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 ex1) {
033            return -1;
034        } catch (java.lang.NullPointerException ex2) {
035            return -1;
036        }
037    }
038
039    @Override
040    public void setState(int s) {
041        setValue("" + s);
042    }
043}