jmri.implementation
Class DefaultConditional

java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.implementation.DefaultConditional
All Implemented Interfaces:
Serializable, Conditional, NamedBean
Direct Known Subclasses:
SensorGroupConditional

public class DefaultConditional
extends AbstractNamedBean
implements Conditional, Serializable

Class providing the basic logic of the Conditional interface. This file is part of JMRI.

JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.

JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Author:
Dave Duchamp Copyright (C) 2007, Pete Cressman Copyright (C) 2009, 2010, 2011, Matthew Harris copyright (c) 2009
See Also:
Serialized Form

Field Summary
protected  ArrayList<ConditionalAction> _actionList
           
static boolean PARKS_DEBUG
           
 
Fields inherited from class jmri.implementation.AbstractNamedBean
mSystemName, mUserName
 
Fields inherited from interface jmri.Conditional
ACTION_ALLOCATE_BLOCK_PATH, ACTION_ALLOCATE_WARRANT_ROUTE, ACTION_AUTO_RUN_WARRANT, ACTION_CANCEL_SENSOR_TIMERS, ACTION_CANCEL_TURNOUT_TIMERS, ACTION_CLEAR_SIGNAL_HELD, ACTION_CLEAR_SIGNALMAST_HELD, ACTION_CONTROL_AUDIO, ACTION_CONTROL_TRAIN, ACTION_COPY_MEMORY, ACTION_DEALLOCATE_BLOCK, ACTION_DEALLOCATE_WARRANT_ROUTE, ACTION_DELAYED_SENSOR, ACTION_DELAYED_TURNOUT, ACTION_DISABLE_LOGIX, ACTION_ENABLE_LOGIX, ACTION_JYTHON_COMMAND, ACTION_LOCK_TURNOUT, ACTION_MANUAL_RUN_WARRANT, ACTION_NONE, ACTION_OPTION_ON_CHANGE, ACTION_OPTION_ON_CHANGE_TO_FALSE, ACTION_OPTION_ON_CHANGE_TO_TRUE, ACTION_PLAY_SOUND, ACTION_RESET_DELAYED_SENSOR, ACTION_RESET_DELAYED_TURNOUT, ACTION_RUN_SCRIPT, ACTION_SET_BLOCK_IN_SERVICE, ACTION_SET_BLOCK_OUT_OF_SERVICE, ACTION_SET_BLOCK_PATH_TURNOUTS, ACTION_SET_FAST_CLOCK_TIME, ACTION_SET_LIGHT, ACTION_SET_LIGHT_INTENSITY, ACTION_SET_LIGHT_TRANSITION_TIME, ACTION_SET_MEMORY, ACTION_SET_ROUTE_TURNOUTS, ACTION_SET_SENSOR, ACTION_SET_SIGNAL_APPEARANCE, ACTION_SET_SIGNAL_DARK, ACTION_SET_SIGNAL_HELD, ACTION_SET_SIGNAL_LIT, ACTION_SET_SIGNALMAST_ASPECT, ACTION_SET_SIGNALMAST_DARK, ACTION_SET_SIGNALMAST_HELD, ACTION_SET_SIGNALMAST_LIT, ACTION_SET_TRAIN_ID, ACTION_SET_TRAIN_NAME, ACTION_SET_TURNOUT, ACTION_START_FAST_CLOCK, ACTION_STOP_FAST_CLOCK, ACTION_THROTTLE_FACTOR, ACTION_TO_ITEM, ACTION_TRIGGER_ROUTE, ALL_AND, ALL_OR, FALSE, ITEM_TO_AUDIO_ACTION, ITEM_TO_CLOCK_ACTION, ITEM_TO_CONDITIONAL_TEST, ITEM_TO_LIGHT_ACTION, ITEM_TO_LIGHT_TEST, ITEM_TO_LOGIX_ACTION, ITEM_TO_MEMORY_ACTION, ITEM_TO_MEMORY_TEST, ITEM_TO_OBLOCK_ACTION, ITEM_TO_OBLOCK_TEST, ITEM_TO_OTHER_ACTION, ITEM_TO_SCRIPT_ACTION, ITEM_TO_SENSOR_ACTION, ITEM_TO_SENSOR_TEST, ITEM_TO_SIGNAL_HEAD_ACTION, ITEM_TO_SIGNAL_HEAD_TEST, ITEM_TO_SIGNAL_MAST_ACTION, ITEM_TO_SIGNAL_MAST_TEST, ITEM_TO_TURNOUT_ACTION, ITEM_TO_TURNOUT_TEST, ITEM_TO_WARRANT_ACTION, ITEM_TO_WARRANT_TEST, ITEM_TYPE_AUDIO, ITEM_TYPE_CLOCK, ITEM_TYPE_CONDITIONAL, ITEM_TYPE_LAST_ACTION, ITEM_TYPE_LAST_STATE_VAR, ITEM_TYPE_LIGHT, ITEM_TYPE_LOGIX, ITEM_TYPE_MEMORY, ITEM_TYPE_OBLOCK, ITEM_TYPE_OTHER, ITEM_TYPE_SCRIPT, ITEM_TYPE_SENSOR, ITEM_TYPE_SIGNALHEAD, ITEM_TYPE_SIGNALMAST, ITEM_TYPE_TURNOUT, ITEM_TYPE_WARRANT, MIXED, NUM_ACTION_OPTIONS, NUM_ACTION_TYPES, OPERATOR_AND, OPERATOR_AND_NOT, OPERATOR_NONE, OPERATOR_NOT, OPERATOR_OR, OPERATOR_OR_NOT, TEST_TO_ITEM, TRUE, TYPE_BLOCK_STATUS_EQUALS, TYPE_CONDITIONAL_FALSE, TYPE_CONDITIONAL_TRUE, TYPE_FAST_CLOCK_RANGE, TYPE_LIGHT_OFF, TYPE_LIGHT_ON, TYPE_MEMORY_COMPARE, TYPE_MEMORY_COMPARE_INSENSITIVE, TYPE_MEMORY_EQUALS, TYPE_MEMORY_EQUALS_INSENSITIVE, TYPE_NONE, TYPE_ROUTE_ALLOCATED, TYPE_ROUTE_FREE, TYPE_ROUTE_OCCUPIED, TYPE_ROUTE_SET, TYPE_SENSOR_ACTIVE, TYPE_SENSOR_INACTIVE, TYPE_SIGNAL_HEAD_APPEARANCE_EQUALS, TYPE_SIGNAL_HEAD_DARK, TYPE_SIGNAL_HEAD_FLASHGREEN, TYPE_SIGNAL_HEAD_FLASHLUNAR, TYPE_SIGNAL_HEAD_FLASHRED, TYPE_SIGNAL_HEAD_FLASHYELLOW, TYPE_SIGNAL_HEAD_GREEN, TYPE_SIGNAL_HEAD_HELD, TYPE_SIGNAL_HEAD_LIT, TYPE_SIGNAL_HEAD_LUNAR, TYPE_SIGNAL_HEAD_RED, TYPE_SIGNAL_HEAD_YELLOW, TYPE_SIGNAL_MAST_ASPECT_EQUALS, TYPE_SIGNAL_MAST_HELD, TYPE_SIGNAL_MAST_LIT, TYPE_TRAIN_RUNNING, TYPE_TURNOUT_CLOSED, TYPE_TURNOUT_THROWN, UNKNOWN
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT
 
Constructor Summary
DefaultConditional(String systemName)
           
DefaultConditional(String systemName, String userName)
           
 
Method Summary
 int calculate(boolean enabled, PropertyChangeEvent evt)
          Calculate this Conditional.
 void cancelSensorTimer(String sname)
          Stop a sensor timer if one is actively delaying setting of the specified sensor
 void cancelTurnoutTimer(String sname)
          Stop a turnout timer if one is actively delaying setting of the specified turnout
 String getAntecedentExpression()
          Get antecedent (boolean expression) of Conditional
 ArrayList<ConditionalAction> getCopyOfActions()
          Make deep clone of actions
 ArrayList<ConditionalVariable> getCopyOfStateVariables()
          Make deep clone of variables
static int getIndexInTable(int[] table, int entry)
          Inverse map
 int getLogicType()
          Get type of operators in the antecedent statement
 int getState()
          State of the Conditional is returned.
 boolean getTriggerOnChange()
           
 void setAction(ArrayList<ConditionalAction> arrayList)
          Set list of actions
 void setLogicType(int type, String antecedent)
          set the logic type (all AND's all OR's or mixed AND's and OR's set the antecedent expression - should be a well formed boolean statement with parenthesis indicating the order of evaluation
 void setState(int state)
          State of Conditional is set.
 void setStateVariables(ArrayList<ConditionalVariable> arrayList)
          Set State Variables for this Conditional.
 void setTriggerOnChange(boolean trigger)
          Set policy for execution of action list
 String validateAntecedent(String ant, ArrayList<ConditionalVariable> variableList)
          Check that an antecedent is well formed
 
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, dispose, firePropertyChange, getComment, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, removePropertyChangeListener, setComment, setProperty, setUserName, updateListenerRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.Conditional
addPropertyChangeListener, dispose, removePropertyChangeListener
 
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, getComment, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, setComment, setProperty, setUserName, updateListenerRef
 

Field Detail

PARKS_DEBUG

public static final boolean PARKS_DEBUG
See Also:
Constant Field Values

_actionList

protected ArrayList<ConditionalAction> _actionList
Constructor Detail

DefaultConditional

public DefaultConditional(String systemName,
                          String userName)

DefaultConditional

public DefaultConditional(String systemName)
Method Detail

getIndexInTable

public static int getIndexInTable(int[] table,
                                  int entry)
Inverse map


getAntecedentExpression

public String getAntecedentExpression()
Get antecedent (boolean expression) of Conditional

Specified by:
getAntecedentExpression in interface Conditional

getLogicType

public int getLogicType()
Get type of operators in the antecedent statement

Specified by:
getLogicType in interface Conditional

setLogicType

public void setLogicType(int type,
                         String antecedent)
set the logic type (all AND's all OR's or mixed AND's and OR's set the antecedent expression - should be a well formed boolean statement with parenthesis indicating the order of evaluation

Specified by:
setLogicType in interface Conditional

getTriggerOnChange

public boolean getTriggerOnChange()
Specified by:
getTriggerOnChange in interface Conditional
Returns:
true if action list is executed only when state changes, false if action list is executed on every calculation of state

setTriggerOnChange

public void setTriggerOnChange(boolean trigger)
Description copied from interface: Conditional
Set policy for execution of action list

Specified by:
setTriggerOnChange in interface Conditional
Parameters:
trigger - true execute only on change of state

setStateVariables

public void setStateVariables(ArrayList<ConditionalVariable> arrayList)
Set State Variables for this Conditional. Each state variable will evaluate either True or False when this Conditional is calculated.

This method assumes that all information has been validated.

Specified by:
setStateVariables in interface Conditional

getCopyOfStateVariables

public ArrayList<ConditionalVariable> getCopyOfStateVariables()
Make deep clone of variables

Specified by:
getCopyOfStateVariables in interface Conditional

setAction

public void setAction(ArrayList<ConditionalAction> arrayList)
Set list of actions

Specified by:
setAction in interface Conditional

getCopyOfActions

public ArrayList<ConditionalAction> getCopyOfActions()
Make deep clone of actions

Specified by:
getCopyOfActions in interface Conditional

calculate

public int calculate(boolean enabled,
                     PropertyChangeEvent evt)
Calculate this Conditional. When _enabled is false, Conditional.calculate will compute the state of the conditional, but will not trigger its actions. When _enabled is true, the state is computed and if the state has changed, will trigger all its actions.

Specified by:
calculate in interface Conditional

validateAntecedent

public String validateAntecedent(String ant,
                                 ArrayList<ConditionalVariable> variableList)
Check that an antecedent is well formed

Specified by:
validateAntecedent in interface Conditional

cancelSensorTimer

public void cancelSensorTimer(String sname)
Stop a sensor timer if one is actively delaying setting of the specified sensor

Specified by:
cancelSensorTimer in interface Conditional

cancelTurnoutTimer

public void cancelTurnoutTimer(String sname)
Stop a turnout timer if one is actively delaying setting of the specified turnout

Specified by:
cancelTurnoutTimer in interface Conditional

getState

public int getState()
State of the Conditional is returned.

Specified by:
getState in interface Conditional
Specified by:
getState in interface NamedBean
Returns:
state value

setState

public void setState(int state)
State of Conditional is set. Not really public for Conditionals. The state of a Conditional is only changed by its calculate method, so the state is really a read-only bound property.

Specified by:
setState in interface NamedBean


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads