Search in sources :

Example 1 with FilterResult

use of net.parostroj.timetable.model.FreightConnectionFilter.FilterResult in project grafikon by jub77.

the class BaseConnectionStrategy method getFreightToNodesImpl.

private void getFreightToNodesImpl(Node start, TimeInterval fromInterval, List<TrainConnection> path, List<FreightConnectionPath> result, Set<FNConnection> used, FreightConnectionFilter filter, FilterContext context) {
    FilterResult filterResult;
    Iterator<TimeInterval> intervals = fromInterval.getTrain().iterator();
    Iterators.find(intervals, interval -> interval == fromInterval);
    intervals = Iterators.filter(intervals, interval -> interval.isNodeOwner() && (interval.isFreightTo() || interval.isFreightConnection()));
    while (intervals.hasNext()) {
        TimeInterval i = intervals.next();
        if (i.isFreight()) {
            FreightConnectionPath newDst = FreightFactory.createFreightNodeConnection(start, i.getOwnerAsNode(), i.isRegionCenterTransfer(), createNewPath(path, fromInterval, i));
            filterResult = filter.accepted(context, newDst, 0);
            if (filterResult == FilterResult.STOP_EXCLUDE) {
                break;
            }
            if (filterResult != FilterResult.IGNORE) {
                result.add(newDst);
            }
            if (filterResult == FilterResult.STOP_INCLUDE) {
                break;
            }
        }
        for (FNConnection conn : freightNet.getTrainsFrom(i)) {
            if (!used.contains(conn)) {
                used.add(conn);
                List<TrainConnection> newPath = createNewPath(path, fromInterval, conn.getFrom());
                this.getFreightToNodesImpl(start, conn.getTo(), newPath, result, used, conn.getFreightDstFilter(filter, false), context);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) FilterResult(net.parostroj.timetable.model.FreightConnectionFilter.FilterResult) Collection(java.util.Collection) Set(java.util.Set) Node(net.parostroj.timetable.model.Node) Iterators(com.google.common.collect.Iterators) FNConnection(net.parostroj.timetable.model.FNConnection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) FilterContext(net.parostroj.timetable.model.FreightConnectionFilter.FilterContext) TimeInterval(net.parostroj.timetable.model.TimeInterval) FreightNet(net.parostroj.timetable.model.FreightNet) Map(java.util.Map) FreightConnectionFilter(net.parostroj.timetable.model.FreightConnectionFilter) LinkedList(java.util.LinkedList) Collections(java.util.Collections) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Train(net.parostroj.timetable.model.Train) TimeInterval(net.parostroj.timetable.model.TimeInterval) FilterResult(net.parostroj.timetable.model.FreightConnectionFilter.FilterResult) FNConnection(net.parostroj.timetable.model.FNConnection)

Aggregations

Iterators (com.google.common.collect.Iterators)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 FNConnection (net.parostroj.timetable.model.FNConnection)1 FreightConnectionFilter (net.parostroj.timetable.model.FreightConnectionFilter)1 FilterContext (net.parostroj.timetable.model.FreightConnectionFilter.FilterContext)1 FilterResult (net.parostroj.timetable.model.FreightConnectionFilter.FilterResult)1 FreightNet (net.parostroj.timetable.model.FreightNet)1 Node (net.parostroj.timetable.model.Node)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 Train (net.parostroj.timetable.model.Train)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1