001package jmri.jmrix.zimo;
002
003import javax.annotation.Nonnull;
004import jmri.Turnout;
005
006/**
007 * Implement turnout manager for Mx1 Turnouts.
008 * <p>
009 * System names are "ZTnnn", where Z is the user configurable system prefix,
010 * nnn is the turnout number without padding.
011 *
012 * @author Kevin Dickerson (C) 2014
013 */
014public class Mx1TurnoutManager extends jmri.managers.AbstractTurnoutManager {
015
016    public Mx1TurnoutManager(Mx1SystemConnectionMemo memo) {
017        super(memo);
018    }
019
020    /**
021     * {@inheritDoc}
022     */
023    @Override
024    @Nonnull
025    public Mx1SystemConnectionMemo getMemo() {
026        return (Mx1SystemConnectionMemo) memo;
027    }
028
029    /**
030     * {@inheritDoc}
031     */
032    @Nonnull
033    @Override
034    protected Turnout createNewTurnout(@Nonnull String systemName, String userName) throws IllegalArgumentException {
035        int addr;
036        try {
037            addr = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
038        } catch (java.lang.NumberFormatException e) {
039            throw new IllegalArgumentException("Failed to convert systemName '"+systemName+"' to a Turnout address");
040        }
041        Turnout t = new Mx1Turnout(addr, getMemo().getMx1TrafficController(), getSystemPrefix());
042        t.setUserName(userName);
043        return t;
044    }
045
046    @Override
047    public boolean allowMultipleAdditions(@Nonnull String systemName) {
048        return true;
049    }
050
051}