Package adams.core

Class 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
    • Constructor Detail

      • NamedCounter

        public NamedCounter()
        Initializes the counter.
    • 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 counter
        count - 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 counter
        limit - 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
      • nameSet

        public Set<String> nameSet()
        Returns the currently stored names.
        Returns:
        the name set
      • size

        public int size()
        Returns the number of names currently stored.
        Returns:
        the number of stored names
      • toString

        public String toString()
        Returns the current counters as string.
        Overrides:
        toString in class Object
        Returns:
        the string representation