Package jmri
Class ConditionalVariable
- java.lang.Object
-
- jmri.ConditionalVariable
-
public class ConditionalVariable extends java.lang.Object
The variable used in the antecedent (the 'if' part) of the Conditional. proposition. The states of ConditionalVariables and logic expression of the antecedent determine the state of the Conditional.ConditionalVariable objects are fully mutable, so use the default equals() operator that checks for identical objects, not identical contents. 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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
EQUAL
static int
GREATER_THAN
static int
GREATER_THAN_OR_EQUAL
static int
LESS_THAN
static int
LESS_THAN_OR_EQUAL
protected NamedBeanHandleManager
nbhm
static int
NUM_COMPARE_OPERATIONS
(package private) static java.util.ResourceBundle
rbx
-
Constructor Summary
Constructors Constructor Description ConditionalVariable()
Create a blank ConditionalVariable, to be filled in later.ConditionalVariable(boolean not, Conditional.Operator opern, Conditional.Type type, java.lang.String name, boolean trigger)
Create a ConditionalVariable with a set of given properties.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) boolean
compare(java.lang.String value1, java.lang.String value2, boolean caseInsensitive)
Compare two values using the comparator set using the comparison instructions insetNum1(int)
.boolean
doTriggerActions()
If change of state of this object causes a change of state of the Conditional, should any actions be executed.boolean
evaluate()
Evaluates this State Variable.static int
fixMidnight(int time)
NamedBean
getBean()
static java.lang.String
getCompareOperationString(int index)
static java.lang.String
getCompareSymbols(int index)
java.lang.String
getDataString()
java.lang.String
getGuiName()
static java.lang.String
getItemTypeString(Conditional.ItemType t)
Convert Variable Type to Text Stringjava.lang.String
getName()
NamedBeanHandle<?>
getNamedBean()
NamedBean
getNamedBeanData()
int
getNum1()
int
getNum2()
Conditional.Operator
getOpern()
java.lang.String
getOpernString()
Provide a localized text for screen display of the logic operator.int
getState()
java.lang.String
getTestTypeString()
Conditional.Type
getType()
boolean
isNegated()
void
setDataString(java.lang.String data)
void
setGuiName(java.lang.String guiName)
Set the GUI name for the conditional state variable.void
setName(java.lang.String name)
void
setNegation(boolean not)
void
setNum1(int num)
void
setNum2(int num)
void
setOpern(Conditional.Operator opern)
void
setState(boolean state)
void
setState(int state)
void
setTriggerActions(boolean trigger)
void
setType(Conditional.Type type)
static Conditional.Type
stringToVariableTest(java.lang.String str)
Identify action Data from Text String.java.lang.String
toString()
-
-
-
Field Detail
-
rbx
static final java.util.ResourceBundle rbx
-
NUM_COMPARE_OPERATIONS
public static final int NUM_COMPARE_OPERATIONS
- See Also:
- Constant Field Values
-
LESS_THAN
public static final int LESS_THAN
- See Also:
- Constant Field Values
-
LESS_THAN_OR_EQUAL
public static final int LESS_THAN_OR_EQUAL
- See Also:
- Constant Field Values
-
EQUAL
public static final int EQUAL
- See Also:
- Constant Field Values
-
GREATER_THAN_OR_EQUAL
public static final int GREATER_THAN_OR_EQUAL
- See Also:
- Constant Field Values
-
GREATER_THAN
public static final int GREATER_THAN
- See Also:
- Constant Field Values
-
nbhm
protected NamedBeanHandleManager nbhm
-
-
Constructor Detail
-
ConditionalVariable
public ConditionalVariable()
Create a blank ConditionalVariable, to be filled in later.
-
ConditionalVariable
public ConditionalVariable(boolean not, Conditional.Operator opern, Conditional.Type type, java.lang.String name, boolean trigger)
Create a ConditionalVariable with a set of given properties.- Parameters:
not
- true if the ConditionalVariable should be negatedopern
- the boolean operator for this ConditionalVariabletype
- the type this ConditionalVariable operates on (Turnout, Sensor, ...)name
- the device nametrigger
- true if actions should be performed if triggered
-
-
Method Detail
-
isNegated
public boolean isNegated()
-
setNegation
public void setNegation(boolean not)
-
getOpern
public Conditional.Operator getOpern()
-
setOpern
public final void setOpern(Conditional.Operator opern)
-
getType
public Conditional.Type getType()
-
setType
public void setType(Conditional.Type type)
-
getName
public java.lang.String getName()
-
setName
public void setName(java.lang.String name)
-
getNamedBean
public NamedBeanHandle<?> getNamedBean()
-
getDataString
public java.lang.String getDataString()
-
setDataString
public void setDataString(java.lang.String data)
-
getNamedBeanData
public NamedBean getNamedBeanData()
-
getNum1
public int getNum1()
-
setNum1
public void setNum1(int num)
-
getNum2
public int getNum2()
-
setNum2
public void setNum2(int num)
-
getGuiName
public java.lang.String getGuiName()
- Returns:
- the GUI name for the referenced conditional.
- Since:
- 4.7.4
-
setGuiName
public void setGuiName(java.lang.String guiName)
Set the GUI name for the conditional state variable.- Parameters:
guiName
- The referenced Conditional user name.- Since:
- 4.7.4
-
doTriggerActions
public boolean doTriggerActions()
If change of state of this object causes a change of state of the Conditional, should any actions be executed.- Returns:
- true if actions should be performed if triggered
-
setTriggerActions
public void setTriggerActions(boolean trigger)
-
getState
public int getState()
-
setState
public void setState(int state)
-
setState
public void setState(boolean state)
-
getTestTypeString
public java.lang.String getTestTypeString()
-
getOpernString
public java.lang.String getOpernString()
Provide a localized text for screen display of the logic operator.- Returns:
- translated string (from jmri.NamedBeanBundle.properties)
-
evaluate
public boolean evaluate()
Evaluates this State Variable.- Returns:
- true if variable evaluates true, otherwise false.
-
compare
boolean compare(java.lang.String value1, java.lang.String value2, boolean caseInsensitive)
Compare two values using the comparator set using the comparison instructions insetNum1(int)
. Note:getNum1()
must be one ofLESS_THAN
,LESS_THAN_OR_EQUAL
,EQUAL
,GREATER_THAN_OR_EQUAL
, orGREATER_THAN
.- Parameters:
value1
- left side of the comparisonvalue2
- right side of the comparisoncaseInsensitive
- true if comparison should be case insensitive; false otherwise- Returns:
- true if values compare per getNum1(); false otherwise
-
fixMidnight
public static int fixMidnight(int time)
-
getItemTypeString
public static java.lang.String getItemTypeString(Conditional.ItemType t)
Convert Variable Type to Text String- Parameters:
t
- the type- Returns:
- the localized description
-
getCompareOperationString
public static java.lang.String getCompareOperationString(int index)
-
getCompareSymbols
public static java.lang.String getCompareSymbols(int index)
-
stringToVariableTest
public static Conditional.Type stringToVariableTest(java.lang.String str)
Identify action Data from Text String.- Parameters:
str
- the text to check- Returns:
- the conditional action type or -1 if if string does not correspond to an action Data as defined in ConditionalAction
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-