All Packages Class Hierarchy This Package Previous Next Index
Class rebelsky.util.Counter
java.lang.Object
|
+----rebelsky.util.Counter
- public class Counter
- extends Object
A simple counter that you can set, increment, decrement, and
reset.
Constructor Index
- o
Counter()
- Create a new counter that starts at 0 and increments by 1.
- o
Counter(long)
- Create a new counter that starts at base and increments by one.
- o
Counter(long, long)
- Create a new counter that starts at base and increments by
inc.
Method Index
- o
decrement()
- Decrement the counter.
- o
increment()
- Increment the counter.
- o
reset()
- Reset the value of the counter.
- o
value()
- Get the value of the counter.
Constructors
o
Counter
public Counter()
- Create a new counter that starts at 0 and increments by 1.
o
Counter
public Counter(long base)
- Create a new counter that starts at base and increments by one.
o
Counter
public Counter(long base,
long inc)
- Create a new counter that starts at base and increments by
inc.
Methods
o
increment
public long increment() throws NumberRangeException
- Increment the counter.
pre: The counter is at least increment from the largest
long (if the increment is positive).
pre: The counter is at least (-increment) from the smallest
long (if the increment is negative).
post: The counter is changed by the increment.
- Returns:
- s The value of the counter.
- Throws: NumberRangeException
- when the preconditions are not met. In this case, the counter
does not change.
o
decrement
public long decrement() throws NumberRangeException
- Decrement the counter.
pre: The counter is at least increment from the smallest
long (if the increment is positive).
pre: The counter is at least (-increment) from the largest
long (if the increment is negative).
post: The counter is decremented by the increment.
- Returns:
- s The value of the counter.
- Throws: NumberRangeException
- when the preconditions are not met. In this case, the counter
does not change.
o
value
public long value()
- Get the value of the counter.
pre: (none)
post: (none)
o
reset
public long reset()
- Reset the value of the counter.
pre: (none)
post: the value is now equal to the base value
All Packages Class Hierarchy This Package Previous Next Index