use of net.parostroj.timetable.model.ObjectWithId in project grafikon by jub77.
the class LibraryBuilder method importEngineClass.
public LibraryItem importEngineClass(EngineClass engineClass) {
EngineClass engineClassCopy = copyFactory.copy(engineClass, engineClass.getId());
for (WeightTableRow row : engineClassCopy.getWeightTable()) {
for (LineClass origLineClass : ImmutableList.copyOf(row.getWeights().keySet())) {
Integer weight = row.getWeight(origLineClass);
row.removeWeightInfo(origLineClass);
ObjectWithId currentLineClass = this.getObjectById(origLineClass.getId());
if (currentLineClass == null) {
if (config.isAddMissing()) {
LibraryItem lineClassItem = this.importLineClass(origLineClass);
currentLineClass = lineClassItem.getObject();
} else {
throw new IllegalArgumentException("Line class missing from library: " + origLineClass);
}
} else if (!(currentLineClass instanceof LineClass)) {
throw new IllegalArgumentException("Wrong type of line class: " + origLineClass);
}
row.setWeightInfo((LineClass) currentLineClass, weight);
}
}
return addImpl(engineClassCopy, LibraryItemType.ENGINE_CLASS);
}
use of net.parostroj.timetable.model.ObjectWithId in project grafikon by jub77.
the class LibraryBuilder method importTrainType.
public LibraryItem importTrainType(TrainType trainType) {
TrainType trainTypeCopy = copyFactory.copy(trainType, trainType.getId());
// TODO fix train name template reference
if (trainType.getCategory() != null) {
ObjectWithId category = this.getObjectById(trainType.getCategory().getId());
if (category == null) {
if (config.isAddMissing()) {
LibraryItem categoryItem = this.importTrainTypeCategory(trainType.getCategory());
category = categoryItem.getObject();
} else {
throw new IllegalArgumentException("Train type category missing from library: " + trainType.getCategory());
}
} else if (!(category instanceof TrainTypeCategory)) {
throw new IllegalArgumentException("Wrong type of category: " + category);
}
trainTypeCopy.setCategory((TrainTypeCategory) category);
}
return addImpl(trainTypeCopy, LibraryItemType.TRAIN_TYPE);
}
Aggregations