public abstract class ValueLabel extends java.lang.Object implements Label, java.lang.Comparable<ValueLabel>, java.io.Serializable
ValueLabel
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. However,
it does
stipulate that equals() and compareTo() are defined solely with respect to
value(); this should not be changed by subclasses.
Other fields of a ValueLabel subclass should be regarded
as secondary facets (it is almost impossible to override equals in
a useful way while observing the contract for equality defined for Object,
in particular, that equality must by symmetric).
This class is designed to be extended.Modifier | Constructor and Description |
---|---|
protected |
ValueLabel() |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ValueLabel valueLabel)
Orders by
value() 's lexicographic ordering. |
boolean |
equals(java.lang.Object obj)
Equality for
ValueLabel s 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(java.lang.String labelStr)
Set the contents of this label to this
String
representing the
complete contents of the label. |
void |
setValue(java.lang.String value)
Set the value for the label (if one is stored).
|
java.lang.String |
toString()
Return a string representation of the label.
|
java.lang.String |
value()
Return the value of the label (or null if none).
|
public java.lang.String value()
ValueLabel
is
always null
public void setValue(java.lang.String value)
public java.lang.String toString()
value()
if it is non-null
,
and the empty string otherwise.public void setFromString(java.lang.String labelStr)
Label
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.setFromString
in interface Label
labelStr
- the String that translates into the content of the
labelpublic boolean equals(java.lang.Object obj)
ValueLabel
s 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 ValueLabel
is determined simply by String
equality of its value()
. Subclasses should not redefine
this to include other aspects of the ValueLabel
, or the
contract for equals()
is broken.equals
in class java.lang.Object
obj
- the object against which equality is to be checkedthis
and obj
are equalpublic int hashCode()
null
.hashCode
in class java.lang.Object
public int compareTo(ValueLabel valueLabel)
value()
's lexicographic ordering.compareTo
in interface java.lang.Comparable<ValueLabel>
valueLabel
- object to compare topublic abstract LabelFactory labelFactory()
labelFactory
in interface Label
LabelFactory