001package jmri.jmrix.mrc;
002
003import javax.annotation.Nonnull;
004import jmri.Turnout;
005
006/**
007 * New MRC TurnoutManager
008 * <p>
009 * System names are "PTnnn", where P is the user configurable system prefix,
010 * nnn is the turnout number without padding.
011 *
012 * @author Paul Bender Copyright (C) 2004
013 * @author Martin Wade Copyright (C) 2014
014 */
015public class MrcTurnoutManager extends jmri.managers.AbstractTurnoutManager {
016
017    public MrcTurnoutManager(MrcSystemConnectionMemo memo) {
018        super(memo);
019        this.tc = memo.getMrcTrafficController();
020    }
021
022    MrcTrafficController tc = null;
023
024    @Override
025    @Nonnull
026    public MrcSystemConnectionMemo getMemo() {
027        return (MrcSystemConnectionMemo) memo;
028    }
029
030    /**
031     * {@inheritDoc}
032     */
033    @Nonnull
034    @Override
035    protected Turnout createNewTurnout(@Nonnull String systemName, String userName) throws IllegalArgumentException {
036        int addr;
037        try {
038            addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
039        } catch (NumberFormatException e) {
040            throw new IllegalArgumentException("Failed to convert systemName '"+systemName+"' to a Turnout address");
041        }
042        Turnout t = new MrcTurnout(addr, tc, getSystemPrefix());
043        t.setUserName(userName);
044        return t;
045    }
046
047    @Override
048    public boolean allowMultipleAdditions(@Nonnull String systemName) {
049        return true;
050    }
051
052}