Search in sources :

Example 1 with WeightTableRow

use of net.parostroj.timetable.model.WeightTableRow 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 2 with WeightTableRow

use of net.parostroj.timetable.model.WeightTableRow in project grafikon by jub77.

the class EngineClassImport method importObjectImpl.

@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
    // check class
    if (!(o instanceof EngineClass))
        return null;
    EngineClass importedEngineClass = (EngineClass) o;
    // check existence
    EngineClass checkedEngineClass = this.getEngineClass(importedEngineClass);
    if (checkedEngineClass != null) {
        if (overwrite) {
            this.getDiagram().getEngineClasses().remove(checkedEngineClass);
        } else {
            String message = "engine class already exists";
            this.addError(importedEngineClass, message);
            log.debug("{}: {}", message, checkedEngineClass);
            return null;
        }
    }
    // create new engine class
    EngineClass engineClass = new EngineClass(this.getId(importedEngineClass), importedEngineClass.getName());
    // process weight rows
    for (WeightTableRow impRow : importedEngineClass.getWeightTable()) {
        WeightTableRow row = engineClass.createWeightTableRow(impRow.getSpeed());
        for (Map.Entry<LineClass, Integer> impEntry : impRow.getWeights().entrySet()) {
            LineClass lineClass = this.getLineClass(impEntry.getKey());
            if (lineClass == null) {
                String message = "line class missing: " + impEntry.getKey().getName();
                this.addError(importedEngineClass, message);
                log.debug(message);
                return null;
            }
            row.setWeightInfo(lineClass, impEntry.getValue());
        }
        engineClass.addWeightTableRow(row);
    }
    // add to diagram
    this.getDiagram().getEngineClasses().add(engineClass);
    this.addImportedObject(engineClass);
    log.trace("Successfully imported engine class: {}", engineClass);
    return engineClass;
}
Also used : WeightTableRow(net.parostroj.timetable.model.WeightTableRow) LineClass(net.parostroj.timetable.model.LineClass) EngineClass(net.parostroj.timetable.model.EngineClass) Map(java.util.Map)

Aggregations

EngineClass (net.parostroj.timetable.model.EngineClass)2 LineClass (net.parostroj.timetable.model.LineClass)2 WeightTableRow (net.parostroj.timetable.model.WeightTableRow)2 Map (java.util.Map)1 ObjectWithId (net.parostroj.timetable.model.ObjectWithId)1