-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a18c037
commit 538457e
Showing
6 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/Index.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package gov.nasa.jpl.aerie.constraints.tree; | ||
|
||
import gov.nasa.jpl.aerie.constraints.model.EvaluationEnvironment; | ||
import gov.nasa.jpl.aerie.constraints.model.SimulationResults; | ||
import gov.nasa.jpl.aerie.constraints.time.Interval; | ||
import gov.nasa.jpl.aerie.constraints.time.Windows; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public class Index implements Expression<Windows> { | ||
|
||
public final Expression<Windows> expression; | ||
//can be negative | ||
public final int i; | ||
|
||
//i must not be 0 | ||
public Index(final Expression<Windows> expression, final int i) { | ||
this.expression = expression; | ||
this.i = i; | ||
} | ||
|
||
@Override | ||
public Windows evaluate(final SimulationResults results, final Interval bounds, final EvaluationEnvironment environment) { | ||
final var intervals = this.expression.evaluate(results, bounds, environment); | ||
final var itForward = intervals.iterateEqualTo(true).iterator(); | ||
var count = 0; | ||
while(itForward.hasNext()){ | ||
count++; | ||
final var current = itForward.next(); | ||
if(i == count){ | ||
return new Windows().set(current, true); | ||
} | ||
} | ||
if(i < 0){ | ||
final var realIndex = count + i + 1; | ||
final var itBackward = intervals.iterateEqualTo(true).iterator(); | ||
count = 0; | ||
while(itBackward.hasNext()){ | ||
count++; | ||
final var current = itBackward.next(); | ||
if(realIndex == count){ | ||
return new Windows().set(current, true); | ||
} | ||
} | ||
} | ||
return new Windows(); | ||
} | ||
|
||
@Override | ||
public String prettyPrint(final String prefix) { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public void extractResources(final Set<String> names) { | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof final Index o)) return false; | ||
|
||
return Objects.equals(this.expression, o.expression) && this.i == o.i; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.expression, this.i); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters