public class CountingMeasure extends SimplePushMeasure<Long> implements PullMeasure<Long>, PushMeasure<Long>
CountingMeasure provides a simple way to evaluate a number of
occurrences. For instance, it can be used to count how many solutions have
been generated within an algorithm, how many evaluations have been computed,
how many rounds have been run, etc. If these occurrences are provided by some
PushMeasures, you can use link(PushMeasure) to register the
CountingMeasure to these PushMeasures. Otherwise, use
increment() when the CountingMeasure need to count one more
occurrence. In order to get the count, one can access it immediately through
get() or when it is updated by registering a listener with
SimplePushMeasure.register(MeasureListener).| Constructor and Description |
|---|
CountingMeasure()
Create a
CountingMeasure starting from zero. |
CountingMeasure(long initialCount)
Create a
CountingMeasure which starts at a given value. |
CountingMeasure(String name,
String description)
Create a
CountingMeasure starting from zero. |
CountingMeasure(String name,
String description,
long initialCount)
Create a
CountingMeasure which starts at a given value. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
finalize() |
Long |
get() |
void |
increment()
Add 1 to the current count and push its value to all the registered
observers.
|
void |
increment(long amount)
Increment the current count in a given amount.
|
<T> void |
link(PushMeasure<T> measure)
If this
CountingMeasure is used to count the number of time a
PushMeasure notifies its observers, you can use this method to
link them. |
void |
reset()
Restart the counter to zero.
|
void |
reset(long value)
Restart the counter to a given value.
|
<T> void |
unlink(PushMeasure<T> measure)
If you have linked a
PushMeasure through
link(PushMeasure), you can discard the link by using this
method. |
push, register, unregistergetDescription, getName, setDescription, setName, toStringclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitregister, unregistergetDescription, getNamepublic CountingMeasure(String name, String description, long initialCount)
CountingMeasure which starts at a given value. The next
value to be pushed to the registered observers will be this value + 1.name - the name of the measuredescription - the description of the measureinitialCount - the value to start frompublic CountingMeasure(String name, String description)
CountingMeasure starting from zero. The registered
observers will receive their first notification when it will increment to
1.name - the name of the measuredescription - the description of the measurepublic CountingMeasure(long initialCount)
CountingMeasure which starts at a given value. The next
value to be pushed to the registered observers will be this value + 1. A
default name and description are used.initialCount - the value to start frompublic CountingMeasure()
CountingMeasure starting from zero. The registered
observers will receive their first notification when it will increment to
1. A default name and description are used.public void increment()
public void increment(long amount)
amount - the amount to addpublic Long get()
get in interface PullMeasure<Long>public <T> void link(PushMeasure<T> measure)
CountingMeasure is used to count the number of time a
PushMeasure notifies its observers, you can use this method to
link them. The CountingMeasure will automatically register a
MeasureListener on the PushMeasure such that, every time
the PushMeasure send a notification,
increment() is called. You can link several
PushMeasures at the same time, but each of their notifications
will increment the counter, leading to summing their notifications. When
a PushMeasure should not be considered anymore, use
unlink(PushMeasure) to remove the link.measure - the PushMeasure to linkpublic <T> void unlink(PushMeasure<T> measure)
PushMeasure through
link(PushMeasure), you can discard the link by using this
method.measure - the PushMeasure to unlinkprotected void finalize()
throws Throwable
public void reset()
public void reset(long value)
value - the value to restart fromCopyright © 2015. All rights reserved.