org.statcato.utils
Class CategoryCounter

java.lang.Object
  extended by org.statcato.utils.CategoryCounter

public class CategoryCounter
extends java.lang.Object

Keeps track of a previously unspecified number of categories and the frequency of each category. Maps each category to a unique number.

Since:
1.0
Version:
%I%, %G%
Author:
Margaret Yau

Constructor Summary
CategoryCounter()
          Constructor.
 
Method Summary
 void addCategory(java.lang.String cat)
          Adds the given category to the counter.
 java.util.Vector<java.lang.String> getCategories()
           
 java.lang.String getCategory(int i)
          Returns the category at the given index.
 int getEqualFrequency()
          Checks if all the frequencies are the same.
 int getFrequency(java.lang.String cat)
          Returns the frequency of the given category.
 int getIndex(java.lang.String cat)
          Returns the index corresponding to the given category, or returns -1 if the category is not found.
 int getSize()
          Returns the number of categories found by this counter.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CategoryCounter

public CategoryCounter()
Constructor.

Method Detail

addCategory

public void addCategory(java.lang.String cat)
Adds the given category to the counter.

Parameters:
cat - category string

getCategory

public java.lang.String getCategory(int i)
Returns the category at the given index.

Parameters:
i - index
Returns:
category at the given index

getCategories

public java.util.Vector<java.lang.String> getCategories()

getIndex

public int getIndex(java.lang.String cat)
Returns the index corresponding to the given category, or returns -1 if the category is not found.

Parameters:
cat - category
Returns:
index of the category, or -1 if it does not exist

getSize

public int getSize()
Returns the number of categories found by this counter.

Returns:
number of categories

getEqualFrequency

public int getEqualFrequency()
Checks if all the frequencies are the same. If so, return it; otherwise, return -1.

Returns:
the frequency that all the categories have, or -1 if not all frequencies are equal

getFrequency

public int getFrequency(java.lang.String cat)
Returns the frequency of the given category.

Parameters:
cat - category
Returns:
frequency of the given category

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object