|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jut.ref.Counter
public class Counter
wrapper for a long value that is to be accessed and modified out of more than one context.
Counter
is thread-safe.
Field Summary | |
---|---|
protected ArrayList<ParamCallable<Boolean,Long>> |
difListeners
listeners observing changes to this Counter . |
protected ArrayList<ParamCallable<Boolean,Long>> |
valListeners
listeners observing the value of this Counter . |
protected long |
value
the counter used internally. |
Fields inherited from interface jut.ref.ICount |
---|
DUMMY |
Constructor Summary | |
---|---|
Counter()
|
Method Summary | ||
---|---|---|
Counter |
add(long val)
add a value to the counter. |
|
Counter |
addDifListener(ParamCallable<Boolean,Long> listener)
add a (non-null) change listener to this Counter . since Counter implements
ParamCallable , one counter can be linked to another counter by adding it to the change
listeners of the other counter. note that listeners can be added multiple times. in this case,
they will also be notified multiple times. |
|
Counter |
addValListener(ParamCallable<Boolean,Long> listener)
add a (non- null ) value listener to this Counter . note that listeners can
be added multiple times. in this case, they will also be notified multiple times. |
|
Boolean |
call(Long increment)
implementation of the ParamCallable interface, so a counter can be added to the list of
listeners of another counter. |
|
long |
get()
|
|
boolean |
removeDifListener(ParamCallable<Boolean,Long> listener)
unregister a change listener. note that only one instance of the listener is unregistered, not all instances. |
|
boolean |
removeValListener(ParamCallable<Boolean,Long> listener)
unregister a value listener. note that only one instance of the listener is unregistered, not all instances. |
|
|
sync(ParamCallable<T,Long> task)
run a synchronized task, e.g. compare and set, and return the tasks result. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected long value
protected final ArrayList<ParamCallable<Boolean,Long>> valListeners
Counter
.
protected final ArrayList<ParamCallable<Boolean,Long>> difListeners
Counter
.
Constructor Detail |
---|
public Counter()
Method Detail |
---|
public Counter addValListener(ParamCallable<Boolean,Long> listener)
null
) value listener to this Counter
. note that listeners can
be added multiple times. in this case, they will also be notified multiple times.
if a listener returns false
, all its instances are unregistered after all
listeners have been called.
listener
- - the (non-null) value listener to add to this Counter
.
public Counter addDifListener(ParamCallable<Boolean,Long> listener)
Counter
. since Counter
implements
ParamCallable
, one counter can be linked to another counter by adding it to the change
listeners of the other counter. note that listeners can be added multiple times. in this case,
they will also be notified multiple times.
if a listener returns false
, all its instances are unregistered after all
listeners have been called.
listener
- - the (non-null) change listener to add to this Counter
.
public boolean removeValListener(ParamCallable<Boolean,Long> listener)
listener
- - the listener to remove.
public boolean removeDifListener(ParamCallable<Boolean,Long> listener)
listener
- - the listener to remove.
public Counter add(long val)
Counter
's listeners. even if zero is added, the
listeners are called.
add
in interface ICount
val
- - the value to add to this counter.
public long get()
get
in interface ICount
public <T> T sync(ParamCallable<T,Long> task)
T
- - the type of the task's return value.task
- - the task to run. the ParamCallable.call(Object)
method is provided with
the counter value.
public Boolean call(Long increment)
ParamCallable
interface, so a counter can be added to the list of
listeners of another counter.
call
in interface ParamCallable<Boolean,Long>
increment
- - the value to add to this Counter
.
true
so this Counter
is not removed from the listeners of another
Counter
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |