com.sdm.quasar.client.core.states
Class ThresholdCounterBooleanState

java.lang.Object
  extended bycom.sdm.quasar.client.core.states.AbstractState
      extended bycom.sdm.quasar.client.core.states.ThresholdCounterBooleanState
All Implemented Interfaces:
BooleanState, Disposable, State

public class ThresholdCounterBooleanState
extends AbstractState
implements BooleanState

A BooleanState implementation that is true, as long as the managed counter is at least as big as the treshold set.

Version:
1.$Revision$
Author:
Thomas Wolf

Constructor Summary
ThresholdCounterBooleanState()
          Creates a new ThresholdCounterBooleanState.
ThresholdCounterBooleanState(java.lang.String name)
          Creates a new ThresholdCounterBooleanState.
ThresholdCounterBooleanState(java.lang.String name, int threshold)
          Creates a new ThresholdCounterBooleanState.
ThresholdCounterBooleanState(java.lang.String name, int initialCounter, int threshold)
          Creates a new ThresholdCounterBooleanState.
 
Method Summary
 void addCounter(int diff)
          Adds the given diff value to the current counter.
 void decreaseCounter()
          Decreases the counter.
 int getCounter()
          Returns the counter value of this ThresholdCounterBooleanState.
 int getThreshold()
          Returns the threshold of this ThresholdCounterBooleanState.
 java.lang.Object getValue()
           
 void increaseCounter()
          Increases the counter.
 boolean isValueTrue()
          Returns true, if this State is enabled, false otherwise.
 void setThreshold(int threshold)
          Sets the treshold to the given value.
 
Methods inherited from class com.sdm.quasar.client.core.states.AbstractState
addStateListener, appendParametersToString, dispose, fireStateChanged, getName, removeStateListener, setName, stateValueToString, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sdm.quasar.client.core.states.State
addStateListener, getName, removeStateListener, setName
 
Methods inherited from interface com.sdm.quasar.client.core.common.Disposable
dispose
 

Constructor Detail

ThresholdCounterBooleanState

public ThresholdCounterBooleanState()
Creates a new ThresholdCounterBooleanState.

Note: The counter will be initialized with 0 and the threshold is 1.


ThresholdCounterBooleanState

public ThresholdCounterBooleanState(java.lang.String name)
Creates a new ThresholdCounterBooleanState.

Note: The counter will be initialized with 0 and the threshold is 1.

Parameters:
name - the name of this BooleanState (not null)

ThresholdCounterBooleanState

public ThresholdCounterBooleanState(java.lang.String name,
                                    int threshold)
Creates a new ThresholdCounterBooleanState.

Note: The counter will be initialized with 0.

Parameters:
name - the name of this BooleanState (not null)
threshold - the threshold value (non-negative)

ThresholdCounterBooleanState

public ThresholdCounterBooleanState(java.lang.String name,
                                    int initialCounter,
                                    int threshold)
Creates a new ThresholdCounterBooleanState.

Parameters:
name - the name of this BooleanState (not null)
initialCounter - the initial counter value (non-negative)
threshold - the threshold value (non-negative)
Method Detail

getValue

public java.lang.Object getValue()
Specified by:
getValue in interface State
Returns:
the current state value.
See Also:
State.getValue()

isValueTrue

public boolean isValueTrue()
Description copied from interface: BooleanState
Returns true, if this State is enabled, false otherwise.

Specified by:
isValueTrue in interface BooleanState
Returns:
true, if this State is enabled, false otherwise.
See Also:
BooleanState.isValueTrue()

getThreshold

public int getThreshold()
Returns the threshold of this ThresholdCounterBooleanState.


setThreshold

public void setThreshold(int threshold)
Sets the treshold to the given value.

Parameters:
threshold - the int to set.

getCounter

public int getCounter()
Returns the counter value of this ThresholdCounterBooleanState. The counter is always non-negative and starts with an initial value of 0.


increaseCounter

public void increaseCounter()
Increases the counter. This leads to enable this state, if it is currently enabled.


decreaseCounter

public void decreaseCounter()
Decreases the counter. If the counter is less than getThreshold(), the state is disabled again.


addCounter

public void addCounter(int diff)
Adds the given diff value to the current counter.

Note: this method assures, that the counter does not become negative.

Parameters:
diff - the difference to add to the counter (may be negative)