Search in sources :

Example 6 with ObjectWithId

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);
}
Also used : WeightTableRow(net.parostroj.timetable.model.WeightTableRow) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) EngineClass(net.parostroj.timetable.model.EngineClass)

Example 7 with ObjectWithId

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);
}
Also used : ObjectWithId(net.parostroj.timetable.model.ObjectWithId) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) TrainType(net.parostroj.timetable.model.TrainType)

Aggregations

ObjectWithId (net.parostroj.timetable.model.ObjectWithId)7 TrainType (net.parostroj.timetable.model.TrainType)3 LinkedList (java.util.LinkedList)2 EngineClass (net.parostroj.timetable.model.EngineClass)2 LineClass (net.parostroj.timetable.model.LineClass)2 Node (net.parostroj.timetable.model.Node)2 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)2 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)2 ImportComponent (net.parostroj.timetable.model.imports.ImportComponent)2 Iterables (com.google.common.collect.Iterables)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 JOptionPane (javax.swing.JOptionPane)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1