edu.stanford.nlp.trees
Class AbstractLabel

java.lang.Object
  |
  +--edu.stanford.nlp.trees.AbstractLabel
All Implemented Interfaces:
Comparable, Label
Direct Known Subclasses:
NullLabel, StringLabel

public abstract class AbstractLabel
extends Object
implements Label

An AbstractLabel object acts as a Label with linguistic attributes. This is an abstract class, which doesn't actually store or return anything. It returns null to any requests. Designed to be extended.


Constructor Summary
protected AbstractLabel()
           
 
Method Summary
 int compareTo(Object obj)
          Implementation of comparison for Label.
 boolean equals(Object obj)
          Equality for Labels is defined in the first instance as equality of their String value().
 int hashCode()
          Return the hashCode of the String value providing there is one.
abstract  LabelFactory labelFactory()
          Returns a factory that makes Labels of the appropriate sort.
 void setFromString(String labelStr)
          Set the contents of this label to this String representing the complete contents of the label.
 void setValue(String value)
          Set the value for the label (if one is stored).
 String toString()
          Return a string representation of the label.
 String value()
          Return the value of the label (or null if none).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractLabel

protected AbstractLabel()
Method Detail

value

public String value()
Return the value of the label (or null if none). The default value returned by an AbstractLabel is always null

Specified by:
value in interface Label
Returns:
the value for the label

setValue

public void setValue(String value)
Set the value for the label (if one is stored).

Specified by:
setValue in interface Label
Parameters:
value - - the value for the label

toString

public String toString()
Return a string representation of the label. This will just be the value() if it is non-null, and the empty string otherwise.

Specified by:
toString in interface Label
Overrides:
toString in class Object
Returns:
the string representation

setFromString

public void setFromString(String labelStr)
Description copied from interface: Label
Set the contents of this label to this String representing the complete contents of the label. A class implementing label may throw an UnsupportedOperationException for this method (only). Typically, this method would do some appropriate decoding of the string in a way that sets multiple fields in an inverse of the toString() method.

Specified by:
setFromString in interface Label
Parameters:
labelStr - the String that translates into the content of the label

equals

public boolean equals(Object obj)
Equality for Labels is defined in the first instance as equality of their String value(). Now rewritten to correctly enforce the contract of equals in Object. Equality for a Label is determined simply by String equality of its value(). Subclasses should not redefine this to include other aspects of the Label, or the contract for equals() is broken.

Overrides:
equals in class Object
Parameters:
obj - the object against which equality is to be checked
Returns:
true if this and obj are equal

hashCode

public int hashCode()
Return the hashCode of the String value providing there is one. Otherwise, returns an arbitrary constant for the case of null.

Overrides:
hashCode in class Object

compareTo

public int compareTo(Object obj)
Implementation of comparison for Label. Orders by value's lexicographic ordering.

Specified by:
compareTo in interface Label
Parameters:
obj - object to compare to
Returns:
result (positive if this is greater than obj)

labelFactory

public abstract LabelFactory labelFactory()
Returns a factory that makes Labels of the appropriate sort.

Specified by:
labelFactory in interface Label
Returns:
the LabelFactory


Stanford NLP Group