001package jmri;
002
003import java.beans.PropertyChangeEvent;
004import java.beans.PropertyChangeListener;
005import java.util.List;
006import java.util.ArrayList;
007import java.util.Arrays;
008import java.util.Collections;
009import java.util.Set;
010import java.util.HashSet;
011import java.util.ResourceBundle;
012import javax.annotation.Nonnull;
013
014/**
015 * A Conditional is layout control logic, consisting of a logical expression and
016 * an action.
017 * <p>
018 * A Conditional does not exist on its own, but is part of a Logix. The system
019 * name of each Conditional is set automatically when the conditional is
020 * created. It begins with the system name of its parent Logix. There is no
021 * Conditional Table. Conditionals are created, editted, and deleted via the
022 * Logix Table.
023 * <p>
024 * A Conditional has a "state", which changes depending on whether its logical
025 * expression calculates to TRUE or FALSE. The "state" may not be changed by the
026 * user. It only changes in response to changes in the "state variables" used in
027 * its logical expression.
028 * <p>
029 * Listeners may be set to monitor a change in the state of a conditional.
030 *
031 * <hr>
032 * This file is part of JMRI.
033 * <p>
034 * JMRI is free software; you can redistribute it and/or modify it under the
035 * terms of version 2 of the GNU General Public License as published by the Free
036 * Software Foundation. See the "COPYING" file for a copy of this license.
037 * <p>
038 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
039 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
040 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
041 *
042 * @author Dave Duchamp Copyright (C) 2007, 2008
043 * @author Pete Cressman Copyright (C) 2009, 2010, 2011
044 * @author Matthew Harris copyright (c) 2009
045 */
046public interface Conditional extends NamedBean {
047
048    static final ResourceBundle rbx = ResourceBundle.getBundle("jmri.jmrit.conditional.ConditionalBundle");
049    static final ResourceBundle rbxWarrant = ResourceBundle.getBundle("jmri.jmrit.logix.WarrantBundle");
050
051    // states
052    enum State {
053        UNKNOWN(NamedBean.UNKNOWN, "StateUnknown"),
054        FALSE(Conditional.FALSE, "StateFalse"),
055        TRUE(Conditional.TRUE, "StateTrue");
056
057        private final int _state;
058        private final String _bundleKey;
059
060        private State(int state, String bundleKey) {
061            _state = state;
062            _bundleKey = bundleKey;
063        }
064
065        public int getIntValue() {
066            return _state;
067        }
068
069        public static State getOperatorFromIntValue(int stateInt) {
070            for (State state : State.values()) {
071                if (state.getIntValue() == stateInt) {
072                    return state;
073                }
074            }
075
076            throw new IllegalArgumentException("State is unknown");
077        }
078
079        @Override
080        public String toString() {
081            return Bundle.getMessage(_bundleKey);
082        }
083    }
084
085    public static final int FALSE = 0x02;
086    public static final int TRUE = 0x04;
087
088    public enum AntecedentOperator {
089        ALL_AND(Conditional.ALL_AND, Bundle.getMessage("LogicAND")),
090        ALL_OR(Conditional.ALL_OR, Bundle.getMessage("LogicOR")),
091        MIXED(Conditional.MIXED, Bundle.getMessage("LogicMixed"));
092
093        private final int _value;
094        private final String _string;
095
096        private AntecedentOperator(int value, String string) {
097            _value = value;
098            _string = string;
099        }
100
101        public int getIntValue() {
102            return _value;
103        }
104
105        public static AntecedentOperator getOperatorFromIntValue(int value) {
106            for (AntecedentOperator antecedentOperators : AntecedentOperator.values()) {
107                if (antecedentOperators.getIntValue() == value) {
108                    return antecedentOperators;
109                }
110            }
111
112            throw new IllegalArgumentException("ItemType is unknown");
113        }
114
115        @Override
116        public String toString() {
117            return _string;
118        }
119    }
120
121    // logic operators used in antecedent
122    static final int ALL_AND = 0x01;
123    static final int ALL_OR = 0x02;
124    static final int MIXED = 0x03;
125
126    public enum Operator {
127        NONE,
128        AND,
129        OR;
130
131        // This method is used by DefaultConditionalManagerXml.store() for backward compatibility
132        public int getIntValue() {
133            switch (this) {
134                case NONE: return OPERATOR_NONE;
135                case AND: return OPERATOR_AND;
136                case OR: return OPERATOR_OR;
137                default: throw new IllegalArgumentException(String.format("operator %s is unknown", this.name()));
138            }
139        }
140
141        // This method is used by DefaultConditionalManagerXml.loadConditionals() for backward compatibility
142        public static Operator getOperatorFromIntValue(int opern) {
143            switch (opern) {
144                case OPERATOR_AND: return Operator.AND;
145                case OPERATOR_NONE: return Operator.NONE;
146                case OPERATOR_OR: return Operator.OR;
147                default: throw new IllegalArgumentException(String.format("operator %d is unknown", opern));
148            }
149        }
150    }
151
152    // state variable definitions. Keep these since they are needed
153    // for backward compatibility in DefaultConditionalManagerXml.
154    // But they are not used elsewhere.
155    static final int OPERATOR_AND = 1;
156    static final int OPERATOR_NONE = 4;
157    static final int OPERATOR_OR = 5;
158
159    // state variable and action items used by logix.
160    enum ItemType {
161        NONE(TYPE_NONE, IsStateVar.IS_STATE_VAR, "ItemTypeNone"),        // There is no ITEM_TYPE_NONE so use TYPE_NONE instead
162        SENSOR(ITEM_TYPE_SENSOR, IsStateVar.IS_STATE_VAR, "ItemTypeSensor"),
163        TURNOUT(ITEM_TYPE_TURNOUT, IsStateVar.IS_STATE_VAR, "ItemTypeTurnout"),
164        LIGHT(ITEM_TYPE_LIGHT, IsStateVar.IS_STATE_VAR, "ItemTypeLight"),
165        SIGNALHEAD(ITEM_TYPE_SIGNALHEAD, IsStateVar.IS_STATE_VAR, "ItemTypeSignalHead"),
166        SIGNALMAST(ITEM_TYPE_SIGNALMAST, IsStateVar.IS_STATE_VAR, "ItemTypeSignalMast"),
167        MEMORY(ITEM_TYPE_MEMORY, IsStateVar.IS_STATE_VAR, "ItemTypeMemory"),
168        CONDITIONAL(ITEM_TYPE_CONDITIONAL, IsStateVar.IS_STATE_VAR, "ItemTypeConditional"),  // used only by ConditionalVariable
169        LOGIX(ITEM_TYPE_LOGIX, IsStateVar.IS_STATE_VAR, "ItemTypeLogix"),                    // used only by ConditionalAction
170        WARRANT(ITEM_TYPE_WARRANT, IsStateVar.IS_STATE_VAR, "ItemTypeWarrant"),
171        CLOCK(ITEM_TYPE_CLOCK, IsStateVar.IS_STATE_VAR, "ItemTypeClock"),
172        OBLOCK(ITEM_TYPE_OBLOCK, IsStateVar.IS_STATE_VAR, "ItemTypeOBlock"),
173        ENTRYEXIT(ITEM_TYPE_ENTRYEXIT, IsStateVar.IS_STATE_VAR, "ItemTypeEntryExit"),
174
175        AUDIO(ITEM_TYPE_AUDIO, IsStateVar.IS_NOT_STATE_VAR, "ItemTypeAudio"),
176        SCRIPT(ITEM_TYPE_SCRIPT, IsStateVar.IS_NOT_STATE_VAR, "ItemTypeScript"),
177        OTHER(ITEM_TYPE_OTHER, IsStateVar.IS_NOT_STATE_VAR, "ItemTypeOther");
178
179        private final int _type;
180        private IsStateVar _isStateVar;
181        private final String _bundleKey;
182
183        private static final List<ItemType> stateVarList;
184
185        static
186        {
187            stateVarList = new ArrayList<>();
188
189            for (ItemType itemType : ItemType.values()) {
190                if (itemType._isStateVar == IsStateVar.IS_STATE_VAR) {
191                    stateVarList.add(itemType);
192                }
193            }
194        }
195
196        private ItemType(int type, IsStateVar isStateVar, String bundleKey) {
197            _type = type;
198            _isStateVar = isStateVar;
199            _bundleKey = bundleKey;
200        }
201
202        public static List<ItemType> getStateVarList() {
203            return stateVarList;
204        }
205
206        public int getIntValue() {
207            return _type;
208        }
209
210        public static ItemType getOperatorFromIntValue(int itemTypeInt) {
211            for (ItemType itemType : ItemType.values()) {
212                if (itemType.getIntValue() == itemTypeInt) {
213                    return itemType;
214                }
215            }
216
217            throw new IllegalArgumentException("ItemType is unknown");
218        }
219
220        @Override
221        public String toString() {
222            return Bundle.getMessage(_bundleKey);
223        }
224
225        // This enum is only used within the outer enum ItemType.
226        private enum IsStateVar {
227            IS_STATE_VAR,
228            IS_NOT_STATE_VAR
229        }
230    }
231
232    // items
233    enum Type {
234        ERROR(TYPE_ERROR, ItemType.NONE, "", ""), // NOI18N
235        NONE(TYPE_NONE, ItemType.NONE, "", ""), // NOI18N
236        SENSOR_ACTIVE(TYPE_SENSOR_ACTIVE, ItemType.SENSOR, Bundle.getMessage("SensorStateActive"), rbx.getString("TypeSensorActive")), // NOI18N
237        SENSOR_INACTIVE(TYPE_SENSOR_INACTIVE, ItemType.SENSOR, Bundle.getMessage("SensorStateInactive"), rbx.getString("TypeSensorInactive")), // NOI18N
238        TURNOUT_THROWN(TYPE_TURNOUT_THROWN, ItemType.TURNOUT, Bundle.getMessage("TurnoutStateThrown"), rbx.getString("TypeTurnoutThrown")), // NOI18N
239        TURNOUT_CLOSED(TYPE_TURNOUT_CLOSED, ItemType.TURNOUT, Bundle.getMessage("TurnoutStateClosed"), rbx.getString("TypeTurnoutClosed")), // NOI18N
240        CONDITIONAL_TRUE(TYPE_CONDITIONAL_TRUE, ItemType.CONDITIONAL, Bundle.getMessage("True"), rbx.getString("TypeConditionalTrue")), // NOI18N
241        CONDITIONAL_FALSE(TYPE_CONDITIONAL_FALSE, ItemType.CONDITIONAL, Bundle.getMessage("False"), rbx.getString("TypeConditionalFalse")), // NOI18N
242        LIGHT_ON(TYPE_LIGHT_ON, ItemType.LIGHT, rbx.getString("LightOn"), rbx.getString("TypeLightOn")), // NOI18N
243        LIGHT_OFF(TYPE_LIGHT_OFF, ItemType.LIGHT, rbx.getString("LightOff"), rbx.getString("TypeLightOff")), // NOI18N
244        MEMORY_EQUALS(TYPE_MEMORY_EQUALS, ItemType.MEMORY, rbx.getString("StateMemoryEquals"), rbx.getString("TypeMemoryEquals")), // NOI18N
245        MEMORY_COMPARE(TYPE_MEMORY_COMPARE, ItemType.MEMORY, rbx.getString("StateMemoryCompare"), rbx.getString("TypeMemoryCompare")), // NOI18N
246        MEMORY_EQUALS_INSENSITIVE(TYPE_MEMORY_EQUALS_INSENSITIVE, ItemType.MEMORY, rbx.getString("StateMemoryEqualsInsensitive"), rbx.getString("TypeMemoryEqualsInsensitive")), // NOI18N
247        MEMORY_COMPARE_INSENSITIVE(TYPE_MEMORY_COMPARE_INSENSITIVE, ItemType.MEMORY, rbx.getString("StateMemoryCompareInsensitive"), rbx.getString("TypeMemoryCompareInsensitive")), // NOI18N
248        FAST_CLOCK_RANGE(TYPE_FAST_CLOCK_RANGE, ItemType.CLOCK, rbx.getString("TypeFastClockRange"), rbx.getString("TypeFastClockRange")), // NOI18N
249
250        // Note the set signalHeadAppearanceSet below which holds those SignalHead types that are appearances.
251        SIGNAL_HEAD_RED(TYPE_SIGNAL_HEAD_RED, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateRed"), Bundle.getMessage("SignalHeadStateRed")), // NOI18N
252        SIGNAL_HEAD_YELLOW(TYPE_SIGNAL_HEAD_YELLOW, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateYellow"), Bundle.getMessage("SignalHeadStateYellow")), // NOI18N
253        SIGNAL_HEAD_GREEN(TYPE_SIGNAL_HEAD_GREEN, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateGreen"), Bundle.getMessage("SignalHeadStateGreen")), // NOI18N
254        SIGNAL_HEAD_DARK(TYPE_SIGNAL_HEAD_DARK, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateDark"), Bundle.getMessage("SignalHeadStateDark")), // NOI18N
255        SIGNAL_HEAD_FLASHRED(TYPE_SIGNAL_HEAD_FLASHRED, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateFlashingRed"), Bundle.getMessage("SignalHeadStateFlashingRed")), // NOI18N
256        SIGNAL_HEAD_FLASHYELLOW(TYPE_SIGNAL_HEAD_FLASHYELLOW, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateFlashingYellow"), Bundle.getMessage("SignalHeadStateFlashingYellow")), // NOI18N
257        SIGNAL_HEAD_FLASHGREEN(TYPE_SIGNAL_HEAD_FLASHGREEN, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateFlashingGreen"), Bundle.getMessage("SignalHeadStateFlashingGreen")), // NOI18N
258        SIGNAL_HEAD_LIT(TYPE_SIGNAL_HEAD_LIT, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateLit"), Bundle.getMessage("SignalHeadStateLit")), // NOI18N
259        SIGNAL_HEAD_HELD(TYPE_SIGNAL_HEAD_HELD, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateHeld"), Bundle.getMessage("SignalHeadStateHeld")), // NOI18N
260        SIGNAL_HEAD_LUNAR(TYPE_SIGNAL_HEAD_LUNAR, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateLunar"), Bundle.getMessage("SignalHeadStateLunar")), // NOI18N
261        SIGNAL_HEAD_FLASHLUNAR(TYPE_SIGNAL_HEAD_FLASHLUNAR, ItemType.SIGNALHEAD, Bundle.getMessage("SignalHeadStateFlashingLunar"), Bundle.getMessage("SignalHeadStateFlashingLunar")), // NOI18N
262        // Warrant variables
263        ROUTE_FREE(TYPE_ROUTE_FREE, ItemType.WARRANT, rbx.getString("StateRouteFree"), rbx.getString("TypeWarrantRouteFree")), // NOI18N
264        ROUTE_OCCUPIED(TYPE_ROUTE_OCCUPIED, ItemType.WARRANT, rbx.getString("stateRouteOccupied"), rbx.getString("TypeWarrantRouteOccupied")), // NOI18N
265        ROUTE_ALLOCATED(TYPE_ROUTE_ALLOCATED, ItemType.WARRANT, rbx.getString("StateRouteReserved"), rbx.getString("TypeWarrantRouteAllocated")), // NOI18N
266        ROUTE_SET(TYPE_ROUTE_SET, ItemType.WARRANT, rbx.getString("StateRouteIsSet"), rbx.getString("TypeRouteIsSet")), // NOI18N
267        TRAIN_RUNNING(TYPE_TRAIN_RUNNING, ItemType.WARRANT, rbx.getString("StateTrainRunning"), rbx.getString("TypeTrainRunning")), // NOI18N
268        SIGNAL_MAST_ASPECT_EQUALS(TYPE_SIGNAL_MAST_ASPECT_EQUALS, ItemType.SIGNALMAST, rbx.getString("TypeSignalMastAspectEquals"), rbx.getString("TypeSignalMastAspectEquals")), // NOI18N
269        SIGNAL_MAST_LIT(TYPE_SIGNAL_MAST_LIT, ItemType.SIGNALMAST, Bundle.getMessage("SignalMastStateLit"), Bundle.getMessage("SignalMastStateLit")), // NOI18N
270        SIGNAL_MAST_HELD(TYPE_SIGNAL_MAST_HELD, ItemType.SIGNALMAST, Bundle.getMessage("SignalMastStateHeld"), Bundle.getMessage("SignalMastStateHeld")), // NOI18N
271        SIGNAL_HEAD_APPEARANCE_EQUALS(TYPE_SIGNAL_HEAD_APPEARANCE_EQUALS, ItemType.SIGNALHEAD, rbx.getString("TypeSignalHeadAspectEquals"), rbx.getString("TypeSignalHeadAspectEquals")), // NOI18N
272        BLOCK_STATUS_EQUALS(TYPE_BLOCK_STATUS_EQUALS, ItemType.OBLOCK, "", ""), // NOI18N
273        //Entry Exit Rules
274        ENTRYEXIT_ACTIVE(TYPE_ENTRYEXIT_ACTIVE, ItemType.ENTRYEXIT, rbx.getString("TypeEntryExitActive"), rbx.getString("TypeEntryExitActive")), // NOI18N
275        ENTRYEXIT_INACTIVE(TYPE_ENTRYEXIT_INACTIVE, ItemType.ENTRYEXIT, rbx.getString("TypeEntryExitInactive"), rbx.getString("TypeEntryExitInactive")), // NOI18N
276        // OBlock
277        OBLOCK_UNOCCUPIED(TYPE_OBLOCK_UNOCCUPIED, ItemType.OBLOCK, rbxWarrant.getString("unoccupied"), rbxWarrant.getString("unoccupied")), // NOI18N
278        OBLOCK_OCCUPIED(TYPE_OBLOCK_OCCUPIED, ItemType.OBLOCK, rbxWarrant.getString("occupied"), rbxWarrant.getString("occupied")), // NOI18N
279        OBLOCK_ALLOCATED(TYPE_OBLOCK_ALLOCATED, ItemType.OBLOCK, rbxWarrant.getString("allocated"), rbxWarrant.getString("allocated")), // NOI18N
280        OBLOCK_RUNNING(TYPE_OBLOCK_RUNNING, ItemType.OBLOCK, rbxWarrant.getString("running"), rbxWarrant.getString("running")), // NOI18N
281        OBLOCK_OUT_OF_SERVICE(TYPE_OBLOCK_OUT_OF_SERVICE, ItemType.OBLOCK, rbxWarrant.getString("outOfService"), rbxWarrant.getString("outOfService")), // NOI18N
282        OBLOCK_DARK(TYPE_OBLOCK_DARK, ItemType.OBLOCK, rbxWarrant.getString("dark"), rbxWarrant.getString("dark")), // NOI18N
283        OBLOCK_POWER_ERROR(TYPE_OBLOCK_POWER_ERROR, ItemType.OBLOCK, rbxWarrant.getString("powerError"), rbxWarrant.getString("powerError")), // NOI18N
284        // This is used by ConditionalListEdit and ConditionalTreeEdit
285        XXXXXXX(TYPE_XXXXXXX, ItemType.NONE, "XXXXXXX", "XXXXXXX"); // NOI18N
286
287        private final int _item;
288        private final ItemType _itemType;
289        private final String _string;
290        private final String _testTypeString;
291
292        private static final List<Type> sensorItemsList;
293        private static final List<Type> turnoutItemsList;
294        private static final List<Type> conditionalItemsList;
295        private static final List<Type> lightItemsList;
296        private static final List<Type> warrantItemsList;
297        private static final List<Type> memoryItemsList;
298        private static final List<Type> entryExitItemsList;
299        private static final List<Type> signalHeadStateMachineItemsList;
300        private static final List<Type> signalMastItemsList;
301        private static final List<Type> oblockItemsList;
302
303        private static final Set<Type> signalHeadAppearanceSet;
304
305
306        static
307        {
308            Type[] typeArray1 = {SENSOR_ACTIVE, SENSOR_INACTIVE};
309            sensorItemsList = Collections.unmodifiableList(Arrays.asList(typeArray1));
310
311            Type[] typeArray2 = {TURNOUT_THROWN, TURNOUT_CLOSED};
312            turnoutItemsList = Collections.unmodifiableList(Arrays.asList(typeArray2));
313
314            Type[] typeArray3 = {CONDITIONAL_TRUE, CONDITIONAL_FALSE};
315            conditionalItemsList = Collections.unmodifiableList(Arrays.asList(typeArray3));
316
317            Type[] typeArray4 = {LIGHT_ON, LIGHT_OFF};
318            lightItemsList = Collections.unmodifiableList(Arrays.asList(typeArray4));
319
320            Type[] typeArray5 = {ROUTE_FREE, ROUTE_SET, ROUTE_ALLOCATED, ROUTE_OCCUPIED, TRAIN_RUNNING};
321            warrantItemsList = Collections.unmodifiableList(Arrays.asList(typeArray5));
322
323            Type[] typeArray6 = {MEMORY_EQUALS, MEMORY_EQUALS_INSENSITIVE,
324                MEMORY_COMPARE, MEMORY_COMPARE_INSENSITIVE};
325            memoryItemsList = Collections.unmodifiableList(Arrays.asList(typeArray6));
326
327            Type[] typeArray7 = {ENTRYEXIT_ACTIVE, ENTRYEXIT_INACTIVE};
328            entryExitItemsList = Collections.unmodifiableList(Arrays.asList(typeArray7));
329
330            Type[] typeArray8 = {NONE, SIGNAL_HEAD_APPEARANCE_EQUALS, SIGNAL_HEAD_LIT, SIGNAL_HEAD_HELD};
331            signalHeadStateMachineItemsList = Collections.unmodifiableList(Arrays.asList(typeArray8));
332
333            Type[] typeArray9 = {SIGNAL_HEAD_RED, SIGNAL_HEAD_YELLOW, SIGNAL_HEAD_GREEN,
334                SIGNAL_HEAD_DARK, SIGNAL_HEAD_FLASHRED, SIGNAL_HEAD_FLASHYELLOW,
335                SIGNAL_HEAD_FLASHGREEN, SIGNAL_HEAD_LUNAR, SIGNAL_HEAD_FLASHLUNAR,
336            };
337            signalHeadAppearanceSet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(typeArray9)));
338
339            Type[] typeArray10 = {NONE, SIGNAL_MAST_ASPECT_EQUALS, SIGNAL_MAST_LIT, SIGNAL_MAST_HELD};
340            signalMastItemsList = Collections.unmodifiableList(Arrays.asList(typeArray10));
341
342            Type[] typeArray11 = {OBLOCK_UNOCCUPIED, OBLOCK_OCCUPIED, OBLOCK_ALLOCATED,
343                OBLOCK_RUNNING, OBLOCK_OUT_OF_SERVICE, OBLOCK_DARK, OBLOCK_POWER_ERROR};
344            oblockItemsList = Collections.unmodifiableList(Arrays.asList(typeArray11));
345        }
346
347        private Type(int state, ItemType itemType, String string, String testTypeString) {
348            _item = state;
349            _itemType = itemType;
350            _string = string;
351            _testTypeString = testTypeString;
352        }
353
354        public ItemType getItemType() {
355            return _itemType;
356        }
357
358        public int getIntValue() {
359            return _item;
360        }
361
362        public static List<Type> getSensorItems() {
363            return sensorItemsList;
364        }
365
366        public static List<Type> getTurnoutItems() {
367            return turnoutItemsList;
368        }
369
370        public static List<Type> getConditionalItems() {
371            return conditionalItemsList;
372        }
373
374        public static List<Type> getLightItems() {
375            return lightItemsList;
376        }
377
378        public static List<Type> getWarrantItems() {
379            return warrantItemsList;
380        }
381
382        public static List<Type> getMemoryItems() {
383            return memoryItemsList;
384        }
385
386        public static List<Type> getEntryExitItems() {
387            return entryExitItemsList;
388        }
389
390        public static List<Type> getSignalHeadStateMachineItems() {
391            return signalHeadStateMachineItemsList;
392        }
393
394        public static boolean isSignalHeadApperance(Type type) {
395            return signalHeadAppearanceSet.contains(type);
396        }
397
398        public static List<Type> getSignalMastItems() {
399            return signalMastItemsList;
400        }
401
402        public static List<Type> getOBlockItems() {
403            return oblockItemsList;
404        }
405
406        public static int getIndexInList(List<Type> table, Type entry) {
407            for (int i = 0; i < table.size(); i++) {
408                if (entry == table.get(i)) {
409                    return i;
410                }
411            }
412            return -1;
413        }
414
415        public static Type getOperatorFromIntValue(int typeInt) {
416            for (Type type : Type.values()) {
417                if (type.getIntValue() == typeInt) {
418                    return type;
419                }
420            }
421
422            throw new IllegalArgumentException("Type is unknown");
423        }
424
425        // Some items uses Bundle.getString() and some items uses rbx.getString()
426        // and therefore the items must call getString() in the call to the constructor.
427        @Override
428        public String toString() {
429            return _string;
430        }
431
432        public String getTestTypeString() {
433            return _testTypeString;
434        }
435    }
436
437    // items
438    enum Action {
439        NONE(ACTION_NONE, ItemType.NONE, ""), // NOI18N
440        SET_TURNOUT(ACTION_SET_TURNOUT, ItemType.TURNOUT, rbx.getString("ActionSetTurnout")), // NOI18N
441        // allowed settings for turnout are Thrown and Closed (in data)
442        SET_SIGNAL_APPEARANCE(ACTION_SET_SIGNAL_APPEARANCE, ItemType.SIGNALHEAD, rbx.getString("ActionSetSignal")), // NOI18N
443        // allowed settings for signal head are the seven Appearances (in data)
444        SET_SIGNAL_HELD(ACTION_SET_SIGNAL_HELD, ItemType.SIGNALHEAD, rbx.getString("ActionSetSignalHeld")), // NOI18N
445        CLEAR_SIGNAL_HELD(ACTION_CLEAR_SIGNAL_HELD, ItemType.SIGNALHEAD, rbx.getString("ActionClearSignalHeld")), // NOI18N
446        SET_SIGNAL_DARK(ACTION_SET_SIGNAL_DARK, ItemType.SIGNALHEAD, rbx.getString("ActionSetSignalDark")), // NOI18N
447        SET_SIGNAL_LIT(ACTION_SET_SIGNAL_LIT, ItemType.SIGNALHEAD, rbx.getString("ActionSetSignalLit")), // NOI18N
448        TRIGGER_ROUTE(ACTION_TRIGGER_ROUTE, ItemType.OTHER, rbx.getString("ActionTriggerRoute")), // NOI18N
449        SET_SENSOR(ACTION_SET_SENSOR, ItemType.SENSOR, rbx.getString("ActionSetSensor")), // NOI18N
450        // allowed settings for sensor are active and inactive (in data)
451        DELAYED_SENSOR(ACTION_DELAYED_SENSOR, ItemType.SENSOR, rbx.getString("ActionDelayedSensor")), // NOI18N
452        // allowed settings for timed sensor are active and inactive (in data)
453        //   time in seconds before setting sensor should be in delay
454        SET_LIGHT(ACTION_SET_LIGHT, ItemType.LIGHT, rbx.getString("ActionSetLight")), // NOI18N
455        // allowed settings for light are ON and OFF (in data)
456        SET_MEMORY(ACTION_SET_MEMORY, ItemType.MEMORY, rbx.getString("ActionSetMemory")), // NOI18N
457        // text to set into the memory variable should be in string
458        ENABLE_LOGIX(ACTION_ENABLE_LOGIX, ItemType.LOGIX, rbx.getString("ActionEnableLogix")), // NOI18N
459        DISABLE_LOGIX(ACTION_DISABLE_LOGIX, ItemType.LOGIX, rbx.getString("ActionDisableLogix")), // NOI18N
460        PLAY_SOUND(ACTION_PLAY_SOUND, ItemType.AUDIO, rbx.getString("ActionPlaySound")), // NOI18N
461        // reference to sound should be in string
462        RUN_SCRIPT(ACTION_RUN_SCRIPT, ItemType.SCRIPT, rbx.getString("ActionRunScript")), // NOI18N
463        // reference to script should be in string
464        DELAYED_TURNOUT(ACTION_DELAYED_TURNOUT, ItemType.TURNOUT, rbx.getString("ActionDelayedTurnout")), // NOI18N
465        // allowed settings for timed turnout are Thrown and Closed (in data)
466        //   time in seconds before setting turnout should be in delay
467        LOCK_TURNOUT(ACTION_LOCK_TURNOUT, ItemType.TURNOUT, rbx.getString("ActionTurnoutLock")), // NOI18N
468        RESET_DELAYED_SENSOR(ACTION_RESET_DELAYED_SENSOR, ItemType.SENSOR, rbx.getString("ActionResetDelayedSensor")), // NOI18N
469        // allowed settings for timed sensor are active and inactive (in data)
470        //   time in seconds before setting sensor should be in delay
471        CANCEL_SENSOR_TIMERS(ACTION_CANCEL_SENSOR_TIMERS, ItemType.SENSOR, rbx.getString("ActionCancelSensorTimers")), // NOI18N
472        // cancels all timers delaying setting of specified sensor
473        RESET_DELAYED_TURNOUT(ACTION_RESET_DELAYED_TURNOUT, ItemType.TURNOUT, rbx.getString("ActionResetDelayedTurnout")), // NOI18N
474        // allowed settings for timed sensor are active and inactive (in data)
475        //   time in seconds before setting sensor should be in delay
476        CANCEL_TURNOUT_TIMERS(ACTION_CANCEL_TURNOUT_TIMERS, ItemType.TURNOUT, rbx.getString("ActionCancelTurnoutTimers")), // NOI18N
477        // cancels all timers delaying setting of specified sensor
478        SET_FAST_CLOCK_TIME(ACTION_SET_FAST_CLOCK_TIME, ItemType.CLOCK, rbx.getString("ActionSetFastClockTime")), // NOI18N
479        // sets the fast clock time to the time specified
480        START_FAST_CLOCK(ACTION_START_FAST_CLOCK, ItemType.CLOCK, rbx.getString("ActionStartFastClock")), // NOI18N
481        // starts the fast clock
482        STOP_FAST_CLOCK(ACTION_STOP_FAST_CLOCK, ItemType.CLOCK, rbx.getString("ActionStopFastClock")), // NOI18N
483        // stops the fast clock
484        COPY_MEMORY(ACTION_COPY_MEMORY, ItemType.MEMORY, rbx.getString("ActionCopyMemory")), // NOI18N
485        // copies value from memory variable (in name) to memory variable (in string)
486        SET_LIGHT_INTENSITY(ACTION_SET_LIGHT_INTENSITY, ItemType.LIGHT, rbx.getString("ActionSetLightIntensity")), // NOI18N
487        SET_LIGHT_TRANSITION_TIME(ACTION_SET_LIGHT_TRANSITION_TIME, ItemType.LIGHT, rbx.getString("ActionSetLightTransitionTime")), // NOI18N
488        // control the specified audio object
489        CONTROL_AUDIO(ACTION_CONTROL_AUDIO, ItemType.AUDIO, rbx.getString("ActionControlAudio")), // NOI18N
490        // execute a jython command
491        JYTHON_COMMAND(ACTION_JYTHON_COMMAND, ItemType.SCRIPT, rbx.getString("ActionJythonCommand")), // NOI18N
492        // Warrant actions
493        ALLOCATE_WARRANT_ROUTE(ACTION_ALLOCATE_WARRANT_ROUTE, ItemType.WARRANT, rbx.getString("ActionAllocateWarrant")), // NOI18N
494        DEALLOCATE_WARRANT_ROUTE(ACTION_DEALLOCATE_WARRANT_ROUTE, ItemType.WARRANT, rbx.getString("ActionDeallocateWarrant")), // NOI18N
495        SET_ROUTE_TURNOUTS(ACTION_SET_ROUTE_TURNOUTS, ItemType.WARRANT, rbx.getString("ActionSetWarrantTurnouts")), // NOI18N
496        AUTO_RUN_WARRANT(ACTION_AUTO_RUN_WARRANT, ItemType.WARRANT, rbx.getString("ActionAutoRunWarrant")), // NOI18N
497        MANUAL_RUN_WARRANT(ACTION_MANUAL_RUN_WARRANT, ItemType.WARRANT, rbx.getString("ActionManualRunWarrant")), // NOI18N
498        CONTROL_TRAIN(ACTION_CONTROL_TRAIN, ItemType.WARRANT, rbx.getString("ActionControlTrain")), // NOI18N
499        SET_TRAIN_ID(ACTION_SET_TRAIN_ID, ItemType.WARRANT, rbx.getString("ActionSetTrainId")), // NOI18N
500        SET_TRAIN_NAME(ACTION_SET_TRAIN_NAME, ItemType.WARRANT, rbx.getString("ActionSetTrainName")), // NOI18N
501        SET_SIGNALMAST_ASPECT(ACTION_SET_SIGNALMAST_ASPECT, ItemType.SIGNALMAST, rbx.getString("ActionSetSignalMastAspect")), // NOI18N
502        THROTTLE_FACTOR(ACTION_THROTTLE_FACTOR, ItemType.WARRANT, rbx.getString("ActionSetThrottleFactor")), // NOI18N
503        SET_SIGNALMAST_HELD(ACTION_SET_SIGNALMAST_HELD, ItemType.SIGNALMAST, rbx.getString("ActionSetSignalMastHeld")), // NOI18N
504        CLEAR_SIGNALMAST_HELD(ACTION_CLEAR_SIGNALMAST_HELD, ItemType.SIGNALMAST, rbx.getString("ActionClearSignalMastHeld")), // NOI18N
505        SET_SIGNALMAST_DARK(ACTION_SET_SIGNALMAST_DARK, ItemType.SIGNALMAST, rbx.getString("ActionSetSignalMastDark")), // NOI18N
506        SET_SIGNALMAST_LIT(ACTION_SET_SIGNALMAST_LIT, ItemType.SIGNALMAST, rbx.getString("ActionClearSignalMastDark")), // NOI18N
507        SET_BLOCK_VALUE(ACTION_SET_BLOCK_VALUE, ItemType.OBLOCK, rbx.getString("ActionSetBlockValue")), // NOI18N
508        SET_BLOCK_ERROR(ACTION_SET_BLOCK_ERROR, ItemType.OBLOCK, rbx.getString("ActionSetBlockError")), // NOI18N
509        CLEAR_BLOCK_ERROR(ACTION_CLEAR_BLOCK_ERROR, ItemType.OBLOCK, rbx.getString("ActionClearBlockError")), // NOI18N
510        DEALLOCATE_BLOCK(ACTION_DEALLOCATE_BLOCK, ItemType.OBLOCK, rbx.getString("ActionDeallocateBlock")), // NOI18N
511        SET_BLOCK_OUT_OF_SERVICE(ACTION_SET_BLOCK_OUT_OF_SERVICE, ItemType.OBLOCK, rbx.getString("ActionSetBlockOutOfService")), // NOI18N
512        SET_BLOCK_IN_SERVICE(ACTION_SET_BLOCK_IN_SERVICE, ItemType.OBLOCK, rbx.getString("ActionBlockInService")), // NOI18N
513        // EntryExit Actions
514        SET_NXPAIR_ENABLED(ACTION_SET_NXPAIR_ENABLED, ItemType.ENTRYEXIT, rbx.getString("ActionNXPairEnabled")), // NOI18N
515        SET_NXPAIR_DISABLED(ACTION_SET_NXPAIR_DISABLED, ItemType.ENTRYEXIT, rbx.getString("ActionNXPairDisabled")), // NOI18N
516        SET_NXPAIR_SEGMENT(ACTION_SET_NXPAIR_SEGMENT, ItemType.ENTRYEXIT, rbx.getString("ActionNXPairSegment")); // NOI18N
517
518
519        private final int _item;
520        private final ItemType _itemType;
521        private final String _string;
522
523        private static final List<Action> sensorItemsList;
524        private static final List<Action> turnoutItemsList;
525        private static final List<Action> lightItemsList;
526        private static final List<Action> warrantItemsList;
527        private static final List<Action> memoryItemsList;
528        private static final List<Action> oblockItemsList;
529        private static final List<Action> entryExitItemsList;
530        private static final List<Action> signalHeadItemsList;
531        private static final List<Action> signalMastItemsList;
532        private static final List<Action> clockItemsList;
533        private static final List<Action> logixItemsList;
534        private static final List<Action> audioItemsList;
535        private static final List<Action> scriptItemsList;
536        private static final List<Action> otherItemsList;
537
538
539        static
540        {
541            Action[] typeArray1 = {SET_SENSOR, DELAYED_SENSOR,
542                RESET_DELAYED_SENSOR, CANCEL_SENSOR_TIMERS};
543            sensorItemsList = Collections.unmodifiableList(Arrays.asList(typeArray1));
544
545            Action[] typeArray2 = {SET_TURNOUT, DELAYED_TURNOUT, LOCK_TURNOUT,
546                CANCEL_TURNOUT_TIMERS, RESET_DELAYED_TURNOUT};
547            turnoutItemsList = Collections.unmodifiableList(Arrays.asList(typeArray2));
548
549            Action[] typeArray3 = {SET_LIGHT, SET_LIGHT_INTENSITY,
550                SET_LIGHT_TRANSITION_TIME};
551            lightItemsList = Collections.unmodifiableList(Arrays.asList(typeArray3));
552
553            Action[] typeArray4 = {ALLOCATE_WARRANT_ROUTE, DEALLOCATE_WARRANT_ROUTE,
554                SET_ROUTE_TURNOUTS, AUTO_RUN_WARRANT, MANUAL_RUN_WARRANT, CONTROL_TRAIN,
555                SET_TRAIN_ID, SET_TRAIN_NAME, THROTTLE_FACTOR};
556            warrantItemsList = Collections.unmodifiableList(Arrays.asList(typeArray4));
557
558            Action[] typeArray5 = {SET_MEMORY, COPY_MEMORY};
559            memoryItemsList = Collections.unmodifiableList(Arrays.asList(typeArray5));
560
561            Action[] typeArray6 = {SET_NXPAIR_ENABLED, SET_NXPAIR_DISABLED,
562                SET_NXPAIR_SEGMENT};
563            entryExitItemsList = Collections.unmodifiableList(Arrays.asList(typeArray6));
564
565            Action[] typeArray7 = {SET_SIGNAL_APPEARANCE, SET_SIGNAL_HELD,
566                CLEAR_SIGNAL_HELD, SET_SIGNAL_DARK, SET_SIGNAL_LIT};
567            signalHeadItemsList = Collections.unmodifiableList(Arrays.asList(typeArray7));
568
569            Action[] typeArray8 = {SET_SIGNALMAST_ASPECT, SET_SIGNALMAST_HELD,
570                CLEAR_SIGNALMAST_HELD, SET_SIGNALMAST_DARK, SET_SIGNALMAST_LIT};
571            signalMastItemsList = Collections.unmodifiableList(Arrays.asList(typeArray8));
572
573            Action[] typeArray9 = {SET_FAST_CLOCK_TIME, START_FAST_CLOCK,
574                STOP_FAST_CLOCK};
575            clockItemsList = Collections.unmodifiableList(Arrays.asList(typeArray9));
576
577            Action[] typeArray10 = {ENABLE_LOGIX, DISABLE_LOGIX};
578            logixItemsList = Collections.unmodifiableList(Arrays.asList(typeArray10));
579
580            Action[] typeArray11 = {DEALLOCATE_BLOCK, SET_BLOCK_VALUE,
581                SET_BLOCK_ERROR, CLEAR_BLOCK_ERROR, SET_BLOCK_OUT_OF_SERVICE,
582                SET_BLOCK_IN_SERVICE};
583            oblockItemsList = Collections.unmodifiableList(Arrays.asList(typeArray11));
584
585            Action[] typeArray12 = {PLAY_SOUND, CONTROL_AUDIO};
586            audioItemsList = Collections.unmodifiableList(Arrays.asList(typeArray12));
587
588            Action[] typeArray13 = {RUN_SCRIPT, JYTHON_COMMAND};
589            scriptItemsList = Collections.unmodifiableList(Arrays.asList(typeArray13));
590
591            Action[] typeArray14 = {TRIGGER_ROUTE};
592            otherItemsList = Collections.unmodifiableList(Arrays.asList(typeArray14));
593        }
594
595        private Action(int state, ItemType itemType, String string) {
596            _item = state;
597            _itemType = itemType;
598            _string = string;
599        }
600
601        public ItemType getItemType() {
602            return _itemType;
603        }
604
605        public int getIntValue() {
606            return _item;
607        }
608
609        public static List<Action> getSensorItems() {
610            return sensorItemsList;
611        }
612
613        public static List<Action> getTurnoutItems() {
614            return turnoutItemsList;
615        }
616
617        public static List<Action> getLightItems() {
618            return lightItemsList;
619        }
620
621        public static List<Action> getWarrantItems() {
622            return warrantItemsList;
623        }
624
625        public static List<Action> getMemoryItems() {
626            return memoryItemsList;
627        }
628
629        public static List<Action> getOBlockItems() {
630            return oblockItemsList;
631        }
632
633        public static List<Action> getEntryExitItems() {
634            return entryExitItemsList;
635        }
636
637        public static List<Action> getSignalHeadItems() {
638            return signalHeadItemsList;
639        }
640
641        public static List<Action> getSignalMastItems() {
642            return signalMastItemsList;
643        }
644
645        public static List<Action> getClockItems() {
646            return clockItemsList;
647        }
648
649        public static List<Action> getLogixItems() {
650            return logixItemsList;
651        }
652
653        public static List<Action> getAudioItems() {
654            return audioItemsList;
655        }
656
657        public static List<Action> getScriptItems() {
658            return scriptItemsList;
659        }
660
661        public static List<Action> getOtherItems() {
662            return otherItemsList;
663        }
664
665        public static Action getOperatorFromIntValue(int actionInt) {
666            for (Action action : Action.values()) {
667                if (action.getIntValue() == actionInt) {
668                    return action;
669                }
670            }
671
672            throw new IllegalArgumentException("Action is unknown");
673        }
674
675        // Some items uses Bundle.getString() and some items uses rbx.getString()
676        // and therefore the items must call getString() in the call to the constructor.
677        @Override
678        public String toString() {
679            return _string;
680        }
681
682    }
683
684    // state variable types
685    static final int TYPE_ERROR = -1;
686    static final int TYPE_NONE = 0;
687    static final int TYPE_SENSOR_ACTIVE = 1;
688    static final int TYPE_SENSOR_INACTIVE = 2;
689    static final int TYPE_TURNOUT_THROWN = 3;
690    static final int TYPE_TURNOUT_CLOSED = 4;
691    static final int TYPE_CONDITIONAL_TRUE = 5;
692    static final int TYPE_CONDITIONAL_FALSE = 6;
693    static final int TYPE_LIGHT_ON = 7;
694    static final int TYPE_LIGHT_OFF = 8;
695    static final int TYPE_MEMORY_EQUALS = 9;
696    static final int TYPE_FAST_CLOCK_RANGE = 10;
697    // Note - within the TYPE_SIGNAL_HEAD definitions, all must be together,
698    //  RED must be first, and HELD must be last
699    static final int TYPE_SIGNAL_HEAD_RED = 11;
700    static final int TYPE_SIGNAL_HEAD_YELLOW = 12;
701    static final int TYPE_SIGNAL_HEAD_GREEN = 13;
702    static final int TYPE_SIGNAL_HEAD_DARK = 14;
703    static final int TYPE_SIGNAL_HEAD_FLASHRED = 15;
704    static final int TYPE_SIGNAL_HEAD_FLASHYELLOW = 16;
705    static final int TYPE_SIGNAL_HEAD_FLASHGREEN = 17;
706    static final int TYPE_SIGNAL_HEAD_LIT = 18;
707    static final int TYPE_SIGNAL_HEAD_HELD = 19;
708    static final int TYPE_MEMORY_COMPARE = 20;
709    static final int TYPE_SIGNAL_HEAD_LUNAR = 21;
710    static final int TYPE_SIGNAL_HEAD_FLASHLUNAR = 22;
711    static final int TYPE_MEMORY_EQUALS_INSENSITIVE = 23;
712    static final int TYPE_MEMORY_COMPARE_INSENSITIVE = 24;
713    // Warrant variables
714    static final int TYPE_ROUTE_FREE = 25;
715    static final int TYPE_ROUTE_OCCUPIED = 26;
716    static final int TYPE_ROUTE_ALLOCATED = 27;
717    static final int TYPE_ROUTE_SET = 28;
718    static final int TYPE_TRAIN_RUNNING = 29;
719    static final int TYPE_SIGNAL_MAST_ASPECT_EQUALS = 30;
720    static final int TYPE_SIGNAL_MAST_LIT = 31;
721    static final int TYPE_SIGNAL_MAST_HELD = 32;
722    static final int TYPE_SIGNAL_HEAD_APPEARANCE_EQUALS = 33;
723
724    static final int TYPE_BLOCK_STATUS_EQUALS = 34;
725
726    //Entry Exit Rules
727    static final int TYPE_ENTRYEXIT_ACTIVE = 35;
728    static final int TYPE_ENTRYEXIT_INACTIVE = 36;
729
730    static final int TYPE_OBLOCK_UNOCCUPIED = 37;
731    static final int TYPE_OBLOCK_OCCUPIED = 38;
732    static final int TYPE_OBLOCK_ALLOCATED = 39;
733    static final int TYPE_OBLOCK_RUNNING = 40;
734    static final int TYPE_OBLOCK_OUT_OF_SERVICE = 41;
735    static final int TYPE_OBLOCK_DARK = 42;
736    static final int TYPE_OBLOCK_POWER_ERROR = 43;
737
738    static final int TYPE_XXXXXXX = 9999;
739
740    // action definitions
741    static final int ACTION_OPTION_ON_CHANGE_TO_TRUE = 1;
742    static final int ACTION_OPTION_ON_CHANGE_TO_FALSE = 2;
743    static final int ACTION_OPTION_ON_CHANGE = 3;
744    static final int NUM_ACTION_OPTIONS = 3;
745
746    // action types
747    static final int ACTION_NONE = 1;
748    static final int ACTION_SET_TURNOUT = 2;
749    // allowed settings for turnout are Thrown and Closed (in data)
750    static final int ACTION_SET_SIGNAL_APPEARANCE = 3;
751    // allowed settings for signal head are the seven Appearances (in data)
752    static final int ACTION_SET_SIGNAL_HELD = 4;
753    static final int ACTION_CLEAR_SIGNAL_HELD = 5;
754    static final int ACTION_SET_SIGNAL_DARK = 6;
755    static final int ACTION_SET_SIGNAL_LIT = 7;
756    static final int ACTION_TRIGGER_ROUTE = 8;
757    static final int ACTION_SET_SENSOR = 9;
758    // allowed settings for sensor are active and inactive (in data)
759    static final int ACTION_DELAYED_SENSOR = 10;
760    // allowed settings for timed sensor are active and inactive (in data)
761    //   time in seconds before setting sensor should be in delay
762    static final int ACTION_SET_LIGHT = 11;
763    // allowed settings for light are ON and OFF (in data)
764    static final int ACTION_SET_MEMORY = 12;
765    // text to set into the memory variable should be in string
766    static final int ACTION_ENABLE_LOGIX = 13;
767    static final int ACTION_DISABLE_LOGIX = 14;
768    static final int ACTION_PLAY_SOUND = 15;
769    // reference to sound should be in string
770    static final int ACTION_RUN_SCRIPT = 16;
771    // reference to script should be in string
772    static final int ACTION_DELAYED_TURNOUT = 17;
773    // allowed settings for timed turnout are Thrown and Closed (in data)
774    //   time in seconds before setting turnout should be in delay
775    static final int ACTION_LOCK_TURNOUT = 18;
776    static final int ACTION_RESET_DELAYED_SENSOR = 19;
777    // allowed settings for timed sensor are active and inactive (in data)
778    //   time in seconds before setting sensor should be in delay
779    static final int ACTION_CANCEL_SENSOR_TIMERS = 20;
780    // cancels all timers delaying setting of specified sensor
781    static final int ACTION_RESET_DELAYED_TURNOUT = 21;
782    // allowed settings for timed sensor are active and inactive (in data)
783    //   time in seconds before setting sensor should be in delay
784    static final int ACTION_CANCEL_TURNOUT_TIMERS = 22;
785    // cancels all timers delaying setting of specified sensor
786    static final int ACTION_SET_FAST_CLOCK_TIME = 23;
787    // sets the fast clock time to the time specified
788    static final int ACTION_START_FAST_CLOCK = 24;
789    // starts the fast clock
790    static final int ACTION_STOP_FAST_CLOCK = 25;
791    // stops the fast clock
792    static final int ACTION_COPY_MEMORY = 26;
793    // copies value from memory variable (in name) to memory variable (in string)
794    static final int ACTION_SET_LIGHT_INTENSITY = 27;
795    static final int ACTION_SET_LIGHT_TRANSITION_TIME = 28;
796    // control the specified audio object
797    static final int ACTION_CONTROL_AUDIO = 29;
798    // execute a jython command
799    static final int ACTION_JYTHON_COMMAND = 30;
800    // Warrant actions
801    static final int ACTION_ALLOCATE_WARRANT_ROUTE = 31;
802    static final int ACTION_DEALLOCATE_WARRANT_ROUTE = 32;
803    static final int ACTION_SET_ROUTE_TURNOUTS = 33;
804    static final int ACTION_AUTO_RUN_WARRANT = 34;
805    static final int ACTION_CONTROL_TRAIN = 35;
806    static final int ACTION_SET_TRAIN_ID = 36;
807    static final int ACTION_SET_SIGNALMAST_ASPECT = 37;
808    static final int ACTION_THROTTLE_FACTOR = 38;
809    static final int ACTION_SET_SIGNALMAST_HELD = 39;
810    static final int ACTION_CLEAR_SIGNALMAST_HELD = 40;
811    static final int ACTION_SET_SIGNALMAST_DARK = 41;
812    static final int ACTION_SET_SIGNALMAST_LIT = 42;
813    static final int ACTION_SET_BLOCK_ERROR = 43;
814    static final int ACTION_CLEAR_BLOCK_ERROR = 44;
815    static final int ACTION_DEALLOCATE_BLOCK = 45;
816    static final int ACTION_SET_BLOCK_OUT_OF_SERVICE = 46;
817    static final int ACTION_SET_BLOCK_IN_SERVICE = 47;
818    static final int ACTION_MANUAL_RUN_WARRANT = 48;
819    static final int ACTION_SET_TRAIN_NAME = 49;
820    static final int ACTION_SET_BLOCK_VALUE = 50;
821    // EntryExit Actions
822    static final int ACTION_SET_NXPAIR_ENABLED = 51;
823    static final int ACTION_SET_NXPAIR_DISABLED = 52;
824    static final int ACTION_SET_NXPAIR_SEGMENT = 53;
825
826    /**
827     * ***********************************************************************************
828     */
829    /* New Variable and Action type scheme for Logix UI
830     * State Variables and actions are grouped according to type.  Variable and action
831     * types share the following group categories:
832     */
833    // state variable and action items used by logix.
834    static final int ITEM_TYPE_SENSOR = 1;
835    static final int ITEM_TYPE_TURNOUT = 2;
836    static final int ITEM_TYPE_LIGHT = 3;
837    static final int ITEM_TYPE_SIGNALHEAD = 4;
838    static final int ITEM_TYPE_SIGNALMAST = 5;
839    static final int ITEM_TYPE_MEMORY = 6;
840    static final int ITEM_TYPE_CONDITIONAL = 7;  // used only by ConditionalVariable
841    static final int ITEM_TYPE_LOGIX = 7;        // used only by ConditionalAction
842    static final int ITEM_TYPE_WARRANT = 8;
843    static final int ITEM_TYPE_CLOCK = 9;
844    static final int ITEM_TYPE_OBLOCK = 10;
845    static final int ITEM_TYPE_ENTRYEXIT = 11;
846
847    static final int ITEM_TYPE_AUDIO = 12;
848    static final int ITEM_TYPE_SCRIPT = 13;
849    static final int ITEM_TYPE_OTHER = 14;
850
851    /**
852     * set the logic type (all AND's all OR's or mixed AND's and OR's set the
853     * antecedent expression - should be a well formed boolean statement with
854     * parenthesis indicating the order of evaluation
855     *
856     * @param type       the type
857     * @param antecedent the expression
858     */
859    public void setLogicType(Conditional.AntecedentOperator type, String antecedent);
860
861    /**
862     * Get antecedent (boolean expression) of Conditional
863     *
864     * @return the expression
865     */
866    public String getAntecedentExpression();
867
868    /**
869     * Get type of operators in the antecedent statement
870     *
871     * @return the type
872     */
873    public Conditional.AntecedentOperator getLogicType();
874
875    /**
876     * @return true if action list is executed only when state changes, false if
877     *         action list is executed on every calculation of state
878     */
879    public boolean getTriggerOnChange();
880
881    /**
882     * Set policy for execution of action list
883     *
884     * @param trigger true execute only on change of state
885     */
886    public void setTriggerOnChange(boolean trigger);
887
888    /**
889     * Set list of actions
890     *
891     * @param arrayList the actions
892     */
893    public void setAction(List<ConditionalAction> arrayList);
894
895    /**
896     * Make deep clone of actions.
897     *
898     * @return a list of copies of actions
899     */
900    @Nonnull
901    public List<ConditionalAction> getCopyOfActions();
902
903    /**
904     * Set State Variables for this Conditional. Each state variable will
905     * evaluate either True or False when this Conditional is calculated.
906     * <p>
907     * This method assumes that all information has been validated.
908     *
909     * @param arrayList the list of variables
910     */
911    public void setStateVariables(List<ConditionalVariable> arrayList);
912
913    /**
914     * Make deep clone of variables.
915     *
916     * @return a list containing copies of variables
917     */
918    @Nonnull
919    public List<ConditionalVariable> getCopyOfStateVariables();
920
921    /**
922     * Calculate this Conditional, triggering either or both actions if the user
923     * specified conditions are met, and the Logix is enabled. Sets the state of
924     * the conditional. Returns the calculated state of this Conditional.
925     *
926     * @param enabled true if Logix should be enabled; false otherwise
927     * @param evt     event to trigger if true
928     * @return the new state
929     */
930    public int calculate(boolean enabled, PropertyChangeEvent evt);
931
932    /**
933     * Check that an antecedent is well formed. If not, returns an error
934     * message. Otherwise returns null.
935     *
936     * @param ant          the expression
937     * @param variableList list of variables
938     * @return true if well formed; false otherwise
939     */
940    public String validateAntecedent(String ant, List<ConditionalVariable> variableList);
941
942    /**
943     * Stop a sensor timer if one is actively delaying setting of the specified
944     * sensor
945     *
946     * @param sname the name of the timer
947     */
948    public void cancelSensorTimer(String sname);
949
950    /**
951     * Stop a turnout timer if one is actively delaying setting of the specified
952     * turnout
953     *
954     * @param sname the name of the timer
955     */
956    public void cancelTurnoutTimer(String sname);
957
958    /**
959     * State of the Conditional is returned.
960     *
961     * @return state value
962     */
963    @Override
964    public int getState();
965
966    /**
967     * Request a call-back when the bound KnownState property changes.
968     *
969     * @param l the listener
970     */
971    @Override
972    public void addPropertyChangeListener(PropertyChangeListener l);
973
974    /**
975     * Remove a request for a call-back when a bound property changes.
976     *
977     * @param l the listener
978     */
979    @Override
980    public void removePropertyChangeListener(PropertyChangeListener l);
981
982    /**
983     * Remove references to and from this object, so that it can eventually be
984     * garbage-collected.
985     */
986    @Override
987    public void dispose();  // remove _all_ connections!
988
989}