001package jmri.jmrix.internal;
002
003import javax.annotation.Nonnull;
004import jmri.NamedBean;
005import jmri.Turnout;
006import jmri.managers.AbstractTurnoutManager;
007import jmri.util.PreferNumericComparator;
008import jmri.implementation.AbstractTurnout;
009
010/**
011 * Implement a turnout manager for "Internal" (virtual) turnouts.
012 *
013 * @author Bob Jacobsen Copyright (C) 2006
014 */
015public class InternalTurnoutManager extends AbstractTurnoutManager {
016
017    public InternalTurnoutManager(InternalSystemConnectionMemo memo) {
018        super(memo);
019    }
020
021    /**
022     * {@inheritDoc}
023     */
024    @Override
025    @Nonnull
026    public InternalSystemConnectionMemo getMemo() {
027        return (InternalSystemConnectionMemo) memo;
028    }
029
030    /**
031     * Create and return an internal (no layout connection) Turnout.
032     * {@inheritDoc}
033     */
034    @Nonnull
035    @Override
036    protected Turnout createNewTurnout(@Nonnull String systemName, String userName) throws IllegalArgumentException {
037        return new AbstractTurnout(systemName, userName) {
038
039            @Override
040            protected void forwardCommandChangeToLayout(int s) {
041                // nothing to do
042            }
043
044            @Override
045            protected void turnoutPushbuttonLockout(boolean b) {
046                // nothing to do
047            }
048
049            @Override
050            public int compareSystemNameSuffix(@Nonnull String suffix1, @Nonnull String suffix2, NamedBean n) {
051                return (new PreferNumericComparator()).compare(suffix1, suffix2);
052            }
053            
054            @Override
055            public boolean isCanFollow() {
056                return true;
057            }
058        };
059    }
060
061    /**
062     * Multiple additions enabled for Internal Turnouts.
063     * {@inheritDoc}
064     */
065    @Override
066    public boolean allowMultipleAdditions(@Nonnull String systemName) {
067        return true;
068    }
069
070    /**
071     * No validation for Internal Turnouts.
072     * {@inheritDoc}
073     */
074    @Override
075    @Nonnull
076    public String createSystemName(@Nonnull String curAddress, @Nonnull String prefix) throws jmri.JmriException {
077        return prefix + typeLetter() + curAddress;
078    }
079
080    /**
081     * {@inheritDoc}
082     */
083    @Override
084    public String getEntryToolTip() {
085        return Bundle.getMessage("AddOutputEntryToolTip");
086    }
087
088    /**
089     * Turnout operation support. Internal turnouts don't need retries.
090     */
091    @Override
092    @Nonnull
093    public String[] getValidOperationTypes() {
094        return new String[]{"NoFeedback"};
095    }
096
097}