Search in sources :

Example 1 with ModelPredicates

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;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TimeInterval(net.parostroj.timetable.model.TimeInterval) ArrayList(java.util.ArrayList) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) ModelPredicates(net.parostroj.timetable.filters.ModelPredicates) Pair(net.parostroj.timetable.utils.Pair) Interval(net.parostroj.timetable.model.Interval) TimeInterval(net.parostroj.timetable.model.TimeInterval)

Aggregations

ArrayList (java.util.ArrayList)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1 Interval (net.parostroj.timetable.model.Interval)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)1 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)1 Pair (net.parostroj.timetable.utils.Pair)1