use of net.parostroj.timetable.filters.ModelPredicates in project grafikon by jub77.
the class PositionsExtractor method getItemStarts.
private List<Pair<TrainsCycleItem, TimeInterval>> getItemStarts(Collection<TrainsCycle> cycles, Integer start) {
int startingTime = start == null ? 0 : start;
List<Pair<TrainsCycleItem, TimeInterval>> itemStarts = new ArrayList<>();
for (TrainsCycle cycle : sortTrainsCycleList(cycles)) {
TrainsCycleItem sItem = null;
boolean added = false;
for (TrainsCycleItem item : cycle) {
Interval nInterval = IntervalFactory.createInterval(item.getStartTime(), item.getEndTime()).normalize();
if (nInterval.isOverThreshold(startingTime)) {
// go through intervals ...
int lStartTime = startingTime + (startingTime < item.getStartTime() ? TimeInterval.DAY : 0);
for (TimeInterval interval : Iterables.filter(item.getIntervals(), ModelPredicates::nodeInterval)) {
if (interval.isStop() && !interval.isLast() && interval.getEnd() >= lStartTime) {
itemStarts.add(new Pair<>(item, interval));
added = true;
break;
}
}
}
if (sItem == null && nInterval.getStart() > startingTime) {
sItem = item;
}
}
if (!added) {
if (sItem == null) {
sItem = cycle.getFirstItem();
}
if (sItem != null) {
itemStarts.add(new Pair<>(sItem, sItem.getFromInterval()));
}
}
}
return itemStarts;
}
Aggregations