001package jmri.implementation;
002
003/**
004 * Concrete implementation of the Reporter interface for the Internal system.
005 *
006 * @author Bob Jacobsen Copyright (C) 2004
007 */
008public class DefaultMemory extends AbstractMemory {
009
010    public DefaultMemory(String systemName) {
011        super(systemName);
012    }
013
014    public DefaultMemory(String systemName, String userName) {
015        super(systemName, userName);
016    }
017
018    /**
019     * Provide generic access to internal state.
020     * <p>
021     * This generally shouldn't be used by Java code; use the class-specific
022     * form instead. (E.g. getCommandedState in Turnout) This provided to make
023     * Jython script access easier to read.
024     * <p>
025     * If the current value can be reduced to an integer, that is returned,
026     * otherwise a value of -1 is returned.
027     */
028    @Override
029    public int getState() {
030        try {
031            return Integer.parseInt(getValue().toString());
032        } catch (java.lang.NumberFormatException | java.lang.NullPointerException ex1) {
033            return -1;
034        }
035    }
036
037    @Override
038    public void setState(int s) {
039        setValue("" + s);
040    }
041}