csc313.hw1
Class SetOfCountables
java.lang.Object
|
+--csc313.hw1.SetOfCountables
- public class SetOfCountables
- extends Object
This class is a collection that allows an application to count the
number of occurences of each different object in its collection.
It uses the object's equals method to determine which strings
should be counted together.
Created in April 2002
- Author:
- Craig Miller
Constructor Summary |
SetOfCountables()
This constructs an empty set of countable objects. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SetOfCountables
public SetOfCountables()
- This constructs an empty set of countable objects.
countElement
public void countElement(Object item)
- This method increments the count for the given item. If the
item has not been previously counted (i.e. it is not equal to
any previously counted item), the item is added to the
collection and its count is initialized to 1.
- Parameters:
item
- any object with an appropriately defined equals method
getCount
public int getCount(Object item)
- Returns:
- the number of times the item has been counted or 0 if
it has not been counted
size
public int size()
- This method gets the number of different objects that have been counted.
- Returns:
- number of different items (an item is different from
another item if the equals method returns false)
totalCounts
public int totalCounts()
- This method returns the number of times all objects have been counted.
- Returns:
- total number of times countElement has been called
iterator
public CountablesIterator iterator()
- Returns:
- an iterator that allows the application to step through
all counted items including the count for each item
main
public static void main(String[] args)