use of net.parostroj.timetable.actions.TrainComparator in project grafikon by jub77.
the class TrainTimetablesExtractor method getConcurrentTrains.
private Pair<Boolean, List<TranslatedString>> getConcurrentTrains(TimeInterval interval) {
TrainComparator comparator = diagram.getTrainsData().getTrainComparator();
Node node = interval.getOwnerAsNode();
TimeInterval toBeChecked = interval;
Train train = interval.getTrain();
if (interval.isFirst() && train.getTimeIntervalBefore() != null)
toBeChecked = train.getTimeIntervalBefore();
else if (interval.isLast() && train.getTimeIntervalAfter() != null)
toBeChecked = train.getTimeIntervalAfter();
Set<TimeInterval> over = node.getOverlappingTimeIntervals(toBeChecked);
boolean first = true;
// check if the train is first in the station (start be marked with trapezoid)
if (!interval.isFirst())
for (Iterator<TimeInterval> i = over.iterator(); i.hasNext(); ) {
TimeInterval checked = i.next();
if (interval.getStart() > checked.getStart() || (interval.getStart() == checked.getStart() && comparator.compare(interval.getTrain(), checked.getTrain()) >= 0)) {
first = false;
break;
}
}
if (over.isEmpty()) {
return null;
} else {
List<Train> tTrains = new ArrayList<>(over.size());
for (TimeInterval ti : over) {
if (!tTrains.contains(ti.getTrain()))
tTrains.add(ti.getTrain());
}
ElementSort<Train> s = new ElementSort<>(new TrainComparator(node.getDiagram().getTrainsData().getTrainSortPattern()));
tTrains = s.sort(tTrains);
List<TranslatedString> result = new LinkedList<>();
for (Train t : tTrains) {
result.add(t.getName());
}
return new Pair<>(first, result);
}
}
Aggregations