use of net.parostroj.timetable.utils.Pair in project grafikon by jub77.
the class DiagramChangeSetImpl method addChange.
List<Pair<DiagramChange, ChangesTrackerEvent.Type>> addChange(DiagramChange change) {
// add change
// look for existing changes
List<DiagramChange> existing = getChangesForId(change.getObjectId());
List<Pair<DiagramChange, ChangesTrackerEvent.Type>> returning = new LinkedList<>();
boolean shouldAdd = true;
DiagramChange addTo = null;
if (existing != null) {
for (DiagramChange ex : existing) {
// logic
boolean add = shouldAdd(change, ex);
if (add && ex.getAction() == Action.MODIFIED && change.getAction() == Action.MODIFIED) {
addTo = ex;
}
shouldAdd &= add;
if (shouldRemove(change, ex)) {
changes.remove(ex);
returning.add(new Pair<>(ex, ChangesTrackerEvent.Type.CHANGE_REMOVED));
}
}
}
if (shouldAdd) {
if (addTo == null) {
changes.add(change);
returning.add(new Pair<>(change, ChangesTrackerEvent.Type.CHANGE_ADDED));
} else {
addTo.setObject(change.getObject());
if (change.getDescriptions() != null) {
for (DiagramChangeDescription d : change.getDescriptions()) {
addTo.addDescriptionUnique(d);
}
returning.add(new Pair<>(addTo, ChangesTrackerEvent.Type.CHANGE_MODIFIED));
}
}
}
return returning;
}
use of net.parostroj.timetable.utils.Pair in project grafikon by jub77.
the class TrainsFilterDialog method setTrainTypes.
public void setTrainTypes(TrainDiagram diagram, Set<TrainType> types) {
if (diagram == null)
return;
typesPanel.removeAll();
typesPanel.setLayout(new GridLayout((diagram.getTrainTypes().size() - 1) / COLUMNS + 1, COLUMNS));
typesList = new LinkedList<Pair<TrainType, JCheckBox>>();
for (TrainType type : diagram.getTrainTypes()) {
JCheckBox checkBox = new JCheckBox(type.getDefaultAbbr() + " (" + type.getDesc() + ")");
typesList.add(new Pair<TrainType, JCheckBox>(type, checkBox));
checkBox.setSelected(types.contains(type));
typesPanel.add(checkBox);
}
this.pack();
}
use of net.parostroj.timetable.utils.Pair 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);
}
}
use of net.parostroj.timetable.utils.Pair in project grafikon by jub77.
the class TrainRegionCollector method getRectangleForItems.
@Override
public Rectangle getRectangleForItems(List<TimeInterval> items) {
Iterable<Train> trains = Iterables.transform(items, SelectorUtils.createToTrainFunction());
Iterable<Train> uniqueTrains = Iterables.filter(trains, SelectorUtils.createUniqueTrainFilter());
Rectangle result = null;
for (Train train : uniqueTrains) {
Collection<Pair<Shape, TimeInterval>> shapes = regions.get(train);
if (shapes != null) {
for (Pair<Shape, TimeInterval> pair : shapes) {
Shape shape = pair.first;
Rectangle bounds = shape.getBounds();
if (result == null) {
result = bounds;
} else {
result = result.union(bounds);
}
}
}
}
return result;
}
use of net.parostroj.timetable.utils.Pair 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