Package trclib.dataprocessor
Class TrcDiscreteValue
java.lang.Object
trclib.dataprocessor.TrcDiscreteValue
This class implements a discrete value where the value can only be set in the interval of specified increment.
It provides methods to set the value up or down by increment. It also provides methods to change the increment
by an order of 10, in essence making the increment to specify the significant digit of the value to be changed.
This is especially useful for using the buttons of a game controller to change a value without using a keyboard
to type in a value.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcDiscreteValue
(String instanceName, double valueMin, double valueMax, double incMin, double incMax, double defValue, double defInc) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptiondouble
This method decreases the increment by an order of 10 only if the resulting increment does not go below incMin.double
This method decreases the value by the increment amount only if the resulting value does not go below valueMin.double
This method returns the current increment.double
getValue()
This method returns the current value.toString()
This method returns the instance name.double
This method increases the increment by an order of 10 only if the resulting increment does not go above incMax.double
upValue()
This method increases the value by the increment amount only if the resulting value does not go above valueMax.
-
Field Details
-
instanceName
-
valueMin
private final double valueMin -
valueMax
private final double valueMax -
incMin
private final double incMin -
incMax
private final double incMax -
value
private double value -
inc
private double inc
-
-
Constructor Details
-
TrcDiscreteValue
public TrcDiscreteValue(String instanceName, double valueMin, double valueMax, double incMin, double incMax, double defValue, double defInc) Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.valueMin
- specifies the value's minimum.valueMax
- specifies the value's maximum.incMin
- specifies the increment's minimum.incMax
- specifies the increment's maximum.defValue
- specifies the initial value.defInc
- specifies the initial increment.
-
-
Method Details
-
toString
This method returns the instance name. -
getValue
public double getValue()This method returns the current value.- Returns:
- current value.
-
getIncrement
public double getIncrement()This method returns the current increment.- Returns:
- current increment.
-
upValue
public double upValue()This method increases the value by the increment amount only if the resulting value does not go above valueMax.- Returns:
- the resulting value.
-
downValue
public double downValue()This method decreases the value by the increment amount only if the resulting value does not go below valueMin.- Returns:
- the resulting value.
-
upIncrement
public double upIncrement()This method increases the increment by an order of 10 only if the resulting increment does not go above incMax.- Returns:
- the resulting increment.
-
downIncrement
public double downIncrement()This method decreases the increment by an order of 10 only if the resulting increment does not go below incMin.- Returns:
- the resulting increment.
-