net.sf.sensor.counter
Class Counter

java.lang.Object
  extended bynet.sf.sensor.counter.Counter

public class Counter
extends Object

Implements a simple labeled counter that supports incrementing and decrementing operations. Counters usually keep track of a countable piece of business information, like the number of orders processed, the number of active sessions, the number of logged in users, etc. The minimum value of a counter is zero. It is not possible to decrement a counter past zero. The maximum value of a counter is Long.MAX_VALUE. It is not possible to increment a counter past Long.MAX_VALUE.

todo: should all the value-related methods be synchronized or only the methods with a conditional ?

Author:
Age Mooy

Constructor Summary
Counter(String label)
          Constructor that sets the label that identifies one instance of Counter from another.
 
Method Summary
 void decrement()
          Decrements this counter by one if the current value is greater than zero.
 String getLabel()
          Returns the label.
 long getValue()
          Returns the value.
 void increment()
          Increments this counter by one.
 void reset()
          Resets this counter back to zero.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Counter

public Counter(String label)
Constructor that sets the label that identifies one instance of Counter from another.

Parameters:
label - the label that identifies one instance of Counter from another.
Method Detail

increment

public void increment()
Increments this counter by one.


decrement

public void decrement()
Decrements this counter by one if the current value is greater than zero.


reset

public void reset()
Resets this counter back to zero.


getLabel

public String getLabel()
Returns the label.

Returns:
Returns the label.

getValue

public long getValue()
Returns the value.

Returns:
Returns the value.


Copyright © 2005-2006 SourceForge. All Rights Reserved.