edu.upenn.cis.pdtb.util
Class EnumFeature

java.lang.Object
  extended byedu.upenn.cis.pdtb.util.EnumFeature

public class EnumFeature
extends java.lang.Object

This class is used to store a group of features. It takes an array of the feature strings and sorts this array once. This makes it possible to look up a value, given an index, in constant time, or look up an index, given a value, in log(n) time. For example, the EnumFeature for source would be created by:

 EnumFeature SourceFeature = new EnumFeature("Source", new String[] { "Arb",
 		"Ot", "Wr" }, 2);
 
2 Is the default index, and here it points to "Wr". SourceFeature.getName() will return "Source". To get the index of a given String in an EnumFeature, you would do something like:
 EnumIndex i = SourceFeature.indexOf("Ot");
 
You can then use this index to look up the String using:
 String s = i.toString();
 
s will now be "Ot". EnumIndex also has a built in equals() function for the most efficient comparison of enumFeature Indices

Since:
3.0
Author:
geraud

Nested Class Summary
 class EnumFeature.EnumIndex
          Representation of an EnumFeature index.
 
Constructor Summary
EnumFeature(java.lang.String name, java.lang.String[] values)
           
EnumFeature(java.lang.String name, java.lang.String[] values, int defaultIndex)
          Instantiation
 
Method Summary
 EnumFeature.EnumIndex getDefaultIndex()
          Gets the default value's index
 java.lang.String getDefaultValue()
          Gets the default value
 java.lang.String getName()
          Gets the name of the group of features
 java.lang.String[] getValues()
          Gets the the whole array of features
 EnumFeature.EnumIndex indexOf(java.lang.String value)
          Gets the feature index of the given feature string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumFeature

public EnumFeature(java.lang.String name,
                   java.lang.String[] values,
                   int defaultIndex)
Instantiation

Parameters:
name - A string representation of the feature group name
values - An string array of the feature
defaultIndex - The index of the default value in the values param

EnumFeature

public EnumFeature(java.lang.String name,
                   java.lang.String[] values)
Method Detail

getName

public java.lang.String getName()
Gets the name of the group of features

Returns:
The name of the group of features

indexOf

public EnumFeature.EnumIndex indexOf(java.lang.String value)
Gets the feature index of the given feature string

Parameters:
value - The feature string whose index is requested
Returns:
The index of the requested feature string. Negative if the string not found, default index if the string is null

getValues

public java.lang.String[] getValues()
Gets the the whole array of features

Returns:
The whole String array of features

getDefaultValue

public java.lang.String getDefaultValue()
Gets the default value

Returns:
The default feature string, null if none exists

getDefaultIndex

public EnumFeature.EnumIndex getDefaultIndex()
Gets the default value's index

Returns:
The index of the default value