org.statcato.utils
Class CategoryCounter
- java.lang.Object
-
- org.statcato.utils.CategoryCounter
-
public class CategoryCounter extends java.lang.ObjectKeeps track of a previously unspecified number of categories and the frequency of each category. Maps each category to a unique number.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor and Description CategoryCounter()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddCategory(java.lang.String cat)Adds the given category to the counter.java.util.Vector<java.lang.String>getCategories()java.lang.StringgetCategory(int i)Returns the category at the given index.intgetEqualFrequency()Checks if all the frequencies are the same.intgetFrequency(java.lang.String cat)Returns the frequency of the given category.intgetIndex(java.lang.String cat)Returns the index corresponding to the given category, or returns -1 if the category is not found.intgetSize()Returns the number of categories found by this counter.java.lang.StringtoString()
-
-
-
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:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG