001package jmri.jmrix.loconet.alm;
002
003import jmri.NmraPacket;
004import jmri.jmrix.loconet.ds64.SimpleTurnoutStateEntry;
005
006//import org.slf4j.Logger;
007//import org.slf4j.LoggerFactory;
008
009/**
010 *
011 * @author B. Milhaupt (C) 2024
012 */
013public class LnSimpleRouteEntry {
014    // data members
015    private int turnoutNumber;   // LocoNet Turnout turnoutNumber
016    private RouteSwitchPositionEnum position;
017    public static final int UNUSEDTURNOUTNUMBER = -1;
018    public SimpleTurnoutStateEntry guiEntry;
019
020    /**
021     * C'tor.
022     */
023    public LnSimpleRouteEntry() {
024        this(-1, true, true);
025    }
026
027    /**
028     * C'tor.
029     * @param addr address
030     * @param closed true if closed, else thrown
031     * @param unused determines whether the entry is unused or used
032     */
033    public LnSimpleRouteEntry(int addr, boolean closed, boolean unused) {
034        turnoutNumber = addr;
035        if (unused) {
036            position = RouteSwitchPositionEnum.UNUSED;
037        } else {
038            position = (closed)
039                    ? RouteSwitchPositionEnum.CLOSED
040                    : RouteSwitchPositionEnum.THROWN;
041        }
042        guiEntry = new SimpleTurnoutStateEntry(addr, closed, unused);
043    }
044
045    /**
046     * Getter.
047     *
048     * @return turnout number
049     */
050    public int getNumber() {
051        return turnoutNumber;
052    }
053
054    /**
055     * Setter.
056     * @param turnoutNumber Turnout number
057     * @return the turnout number which was set
058     */
059    public int setNumber(int turnoutNumber) {
060        if (((turnoutNumber < NmraPacket.accIdLowLimit) || (turnoutNumber > NmraPacket.accIdAltHighLimit)) &&
061                ((turnoutNumber != 0) && (turnoutNumber != -1))) {
062            throw new IllegalArgumentException("Turnout value: " + turnoutNumber// NOI18N
063                    + " not in the range " + NmraPacket.accIdLowLimit + " to " // NOI18N
064                    + NmraPacket.accIdAltHighLimit + " and not 'Unused'.");
065        }
066        this.turnoutNumber = turnoutNumber;
067        return this.turnoutNumber;
068    }
069
070    /**
071     * Getter.
072     * @return RouteSwitchPositionEnum
073     */
074    public RouteSwitchPositionEnum getPosition() {
075        return position;
076    }
077
078    /**
079     * Setter.
080     * @param position Turnout position
081     */
082    public void setPosition(RouteSwitchPositionEnum position) {
083        this.position = position;
084    }
085
086//    private final static Logger log = LoggerFactory.getLogger(LnSimpleRouteEntry.class);
087}