Documentation of 'edu.princeton.cs.algs4.Counter' Java class
Counter
edu.princeton.cs.algs4

Class Counter

  • All Implemented Interfaces:
    java.lang.Comparable<Counter>


    public class Counter
    extends java.lang.Object
    implements java.lang.Comparable<Counter>
    The Counter class is a mutable data type to encapsulate a counter.

    For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Constructor Summary

      Constructors 
      Constructor and Description
      Counter(java.lang.String id)
      Initializes a new counter starting at 0, with the given id.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int compareTo(Counter that)
      Compares this counter to the specified counter.
      void increment()
      Increments the counter by 1.
      static void main(java.lang.String[] args)
      Reads two command-line integers n and trials; creates n counters; increments trials counters at random; and prints results.
      int tally()
      Returns the current value of this counter.
      java.lang.String toString()
      Returns a string representation of this counter.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Counter

        public Counter(java.lang.String id)
        Initializes a new counter starting at 0, with the given id.
        Parameters:
        id - the name of the counter
    • Method Detail

      • increment

        public void increment()
        Increments the counter by 1.
      • tally

        public int tally()
        Returns the current value of this counter.
        Returns:
        the current value of this counter
      • toString

        public java.lang.String toString()
        Returns a string representation of this counter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this counter
      • compareTo

        public int compareTo(Counter that)
        Compares this counter to the specified counter.
        Specified by:
        compareTo in interface java.lang.Comparable<Counter>
        Parameters:
        that - the other counter
        Returns:
        0 if the value of this counter equals the value of that counter; a negative integer if the value of this counter is less than the value of that counter; and a positive integer if the value of this counter is greater than the value of that counter
      • main

        public static void main(java.lang.String[] args)
        Reads two command-line integers n and trials; creates n counters; increments trials counters at random; and prints results.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.