use of net.parostroj.timetable.utils.Triplet in project grafikon by jub77.
the class TrainImport method importObjectImpl.
@Override
protected ObjectWithId importObjectImpl(ObjectWithId importedObject) {
// check class
if (!(importedObject instanceof Train)) {
// skip other objects
return null;
}
Train importedTrain = (Train) importedObject;
// check if the train already exist
Train checkedTrain = this.getTrain(importedTrain);
if (checkedTrain != null) {
String message = "train already exists";
this.addError(importedTrain, message);
log.debug("{}: {}", message, checkedTrain);
return null;
}
// create a new train
TrainType trainType = this.getTrainType(importedTrain.getType());
if (trainType == null) {
String message = "train type missing: " + importedTrain.getType();
this.addError(importedTrain, message);
log.debug(message);
return null;
}
Train train = getDiagram().getPartFactory().createTrain(this.getId(importedTrain));
train.setNumber(importedTrain.getNumber());
train.getAttributes().add(this.importAttributes(importedTrain.getAttributes()));
train.setDescription(importedTrain.getDescription());
train.setType(trainType);
train.setTopSpeed(importedTrain.getTopSpeed());
TrainIntervalsBuilder builder = new TrainIntervalsBuilder(train, importedTrain.getStartTime());
// create route (new)
List<Triplet<RouteSegment<?>, Track, TimeInterval>> route = createNewRoute(importedTrain);
if (route == null) {
String message = "error creating route for train";
this.addError(importedTrain, message);
log.debug("{}: {}", message, importedTrain);
return null;
}
for (Triplet<RouteSegment<?>, Track, TimeInterval> seg : route) {
if (seg.first instanceof Node) {
// node
Node node = (Node) seg.first;
builder.addNode(this.getId(seg.third), node, (NodeTrack) seg.second, seg.third.getLength(), seg.third.getAttributes());
} else {
// line
Line line = (Line) seg.first;
builder.addLine(this.getId(seg.third), line, (LineTrack) seg.second, seg.third.getSpeedLimit(), seg.third.getAddedTime(), seg.third.getAttributes());
}
}
builder.finish();
train.setTimeBefore(importedTrain.getTimeBefore());
train.setTimeAfter(importedTrain.getTimeAfter());
this.getDiagram().getTrains().add(train);
this.addImportedObject(train);
log.trace("Successfully imported train: {}", train);
return train;
}
Aggregations