public class StringLabel extends ValueLabel implements HasOffset
StringLabel
object acts as a Label by containing a
single String, which it sets or returns in response to requests.
The hashCode() and compareTo() methods for this class assume that this
string value is non-null. equals() is correctly implementedConstructor and Description |
---|
StringLabel()
Create a new
StringLabel with a null content (i.e., str). |
StringLabel(Label label)
Create a new
StringLabel with the
value() of another label as its label. |
StringLabel(java.lang.String str)
Create a new
StringLabel with the given content. |
StringLabel(java.lang.String str,
int beginPosition,
int endPosition)
Create a new
StringLabel with the given content. |
Modifier and Type | Method and Description |
---|---|
int |
beginPosition()
Return the beginning char offset of the label (or -1 if none).
|
int |
endPosition()
Return the ending char offset of the label (or -1 if none).
|
static LabelFactory |
factory()
Return a factory for this kind of label.
|
LabelFactory |
labelFactory()
Return a factory for this kind of label
(i.e.,
StringLabel ). |
void |
setBeginPosition(int beginPosition)
Set the beginning character offset for the label.
|
void |
setEndPosition(int endPosition)
Set the ending character offset of the label (or -1 if none).
|
void |
setFromString(java.lang.String str)
Set the label from a String.
|
void |
setValue(java.lang.String value)
Set the value for the label.
|
java.lang.String |
toString()
Return a string representation of the label.
|
java.lang.String |
value()
Return the word value of the label (or null if none).
|
compareTo, equals, hashCode
public StringLabel()
StringLabel
with a null content (i.e., str).public StringLabel(java.lang.String str)
StringLabel
with the given content.str
- The new label's contentpublic StringLabel(java.lang.String str, int beginPosition, int endPosition)
StringLabel
with the given content.str
- The new label's contentbeginPosition
- Start offset in original textendPosition
- End offset in original textpublic StringLabel(Label label)
StringLabel
with the
value()
of another label as its label.label
- The other labelpublic java.lang.String value()
value
in interface Label
value
in class ValueLabel
public void setValue(java.lang.String value)
setValue
in interface Label
setValue
in class ValueLabel
value
- The value for the labelpublic void setFromString(java.lang.String str)
setFromString
in interface Label
setFromString
in class ValueLabel
str
- The str for the labelpublic java.lang.String toString()
ValueLabel
value()
if it is non-null
,
and the empty string otherwise.toString
in interface Label
toString
in class ValueLabel
public LabelFactory labelFactory()
StringLabel
).
The factory returned is always the same one (a singleton).labelFactory
in interface Label
labelFactory
in class ValueLabel
public static LabelFactory factory()
public int beginPosition()
HasOffset
beginPosition
in interface HasOffset
public int endPosition()
HasOffset
endPosition
in interface HasOffset
public void setBeginPosition(int beginPosition)
HasOffset
setBeginPosition
in interface HasOffset
beginPosition
- The beginning positionpublic void setEndPosition(int endPosition)
HasOffset
setEndPosition
in interface HasOffset
endPosition
- The end character offset for the label