001package jmri.jmrix.internal;
002
003import jmri.Consist;
004import jmri.LocoAddress;
005import jmri.DccLocoAddress;
006import jmri.InstanceManager;
007import jmri.implementation.AbstractConsistManager;
008
009/**
010 * Default Consist Manager which uses the NmraConsist class for
011 * the consists it builds.
012 *
013 * @author Paul Bender Copyright (C) 2003
014 * @author Randall Wood Copyright (C) 2013
015 */
016public class InternalConsistManager extends AbstractConsistManager {
017
018    public InternalConsistManager() {
019        super();
020    }
021
022    /**
023     * {@inheritDoc}
024     */
025    @Override
026    public boolean isCommandStationConsistPossible(){
027       return false;
028    }
029
030    /**
031     * {@inheritDoc}
032     */
033    @Override
034    public boolean csConsistNeedsSeperateAddress(){
035      return false;
036    }
037
038    /**
039     * {@inheritDoc}
040     */
041    @Override
042    public Consist addConsist(LocoAddress address) {
043        if (! (address instanceof DccLocoAddress)) {
044            throw new IllegalArgumentException("address is not a DccLocoAddress object");
045        }
046        if (consistTable.containsKey(address)) {
047            return (consistTable.get(address));
048        }
049        Consist consist = null;
050        if (InstanceManager.getNullableDefault(jmri.CommandStation.class) != null ) {
051           consist = new jmri.implementation.NmraConsist((DccLocoAddress) address);
052        }
053        else if (InstanceManager.getNullableDefault(jmri.AddressedProgrammerManager.class) != null){
054           consist = new jmri.implementation.DccConsist((DccLocoAddress) address);
055        }
056        if (consist != null) {
057           consistTable.put(address, consist);
058           notifyConsistListChanged();
059        }
060        return (consist); 
061    }
062
063}