001package jmri.jmrit.operations.rollingstock.engines;
002
003import java.util.ArrayList;
004import java.util.List;
005import jmri.jmrit.operations.rollingstock.RollingStockGroup;
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * A consist is a group of engines that is managed as one engine.
011 *
012 * @author Daniel Boudreau Copyright (C) 2008, 2010
013 */
014public class Consist extends RollingStockGroup<Engine> {
015
016    protected int _consistNumber = 0;
017
018    public Consist(String name) {
019        super(name);
020        log.debug("New Consist ({})", name);
021    }
022
023    public List<Engine> getEngines() {
024        return new ArrayList<>(getGroup());
025    }
026
027    public int getConsistNumber() {
028        return _consistNumber;
029    }
030
031    /**
032     *
033     * @param number DCC address for this consist
034     */
035    public void setConsistNumber(int number) {
036        _consistNumber = number;
037    }
038
039    @Override
040    public void dispose() {
041        while (getGroup().size() > 0) {
042            Engine engine = getGroup().get(0);
043            if (engine != null) {
044                engine.setConsist(null);
045            }
046        }
047        super.dispose();
048    }
049
050    private final static Logger log = LoggerFactory.getLogger(Consist.class);
051}