Package adams.core
Class NamedCounter
- java.lang.Object
-
- adams.core.NamedCounter
-
- All Implemented Interfaces:
Serializable
public class NamedCounter extends Object implements Serializable
Provides counters that can be referenced by a name.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NamedCounter.CounterComparator
Comparator for sorting the names based on the counts associated with them.
-
Constructor Summary
Constructors Constructor Description NamedCounter()
Initializes the counter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the counter.void
clear(String name)
Clears only the specific counter.int
current(String name)
Returns the current counter value.boolean
has(String name)
Returns whether the counter has a value stored at the moment.boolean
hasReached(String name, int limit)
Returns whether the counter has reached the limit.Iterator<String>
names()
Returns the currently stored names.Iterator<String>
names(boolean asc)
Returns the currently stored names sorted based on associated.Set<String>
nameSet()
Returns the currently stored names.int
next(String name)
Returns the incremented counter.void
set(String name, int count)
Initializes the counter value for the specified name.int
size()
Returns the number of names currently stored.String
toString()
Returns the current counters as string.
-
-
-
Method Detail
-
clear
public void clear()
Clears the counter.
-
clear
public void clear(String name)
Clears only the specific counter.- Parameters:
name
- the name of the counter
-
set
public void set(String name, int count)
Initializes the counter value for the specified name.- Parameters:
name
- the name of the countercount
- the value to use
-
current
public int current(String name)
Returns the current counter value.- Parameters:
name
- the name of the counter- Returns:
- the current counter value
-
next
public int next(String name)
Returns the incremented counter.- Parameters:
name
- the name of the counter- Returns:
- the incremented counter
-
hasReached
public boolean hasReached(String name, int limit)
Returns whether the counter has reached the limit.- Parameters:
name
- the name of the counterlimit
- the limit to check- Returns:
- true if limit reached (or above)
-
has
public boolean has(String name)
Returns whether the counter has a value stored at the moment.- Parameters:
name
- the name of the counter- Returns:
- true if counter present
-
names
public Iterator<String> names()
Returns the currently stored names.- Returns:
- the name enumeration
-
names
public Iterator<String> names(boolean asc)
Returns the currently stored names sorted based on associated.- Parameters:
asc
- if true then names are sorted in ascending manner, otherwise in descending manner- Returns:
- the name enumeration
-
size
public int size()
Returns the number of names currently stored.- Returns:
- the number of stored names
-
-