Package com.globalmentor.model
Class LocaledText
- java.lang.Object
-
- com.globalmentor.model.DefaultLocaleable
-
- com.globalmentor.model.LocaledText
-
- All Implemented Interfaces:
Localeable
,java.lang.CharSequence
,java.lang.Comparable<LocaledText>
public class LocaledText extends DefaultLocaleable implements java.lang.CharSequence, java.lang.Comparable<LocaledText>
The encapsulation of text and the locale that indicates the text language.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from interface com.globalmentor.model.Localeable
LOCALE_PROPERTY_NAME
-
-
Constructor Summary
Constructors Constructor Description LocaledText(LocaledText localeText)
Copy constructor.LocaledText(java.lang.String text)
Text constructor with no locale specified.LocaledText(java.lang.String text, java.util.Locale locale)
Full constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description char
charAt(int index)
Returns thechar
value at the specified index.int
compareTo(LocaledText localeText)
Compares this object to another object.boolean
equals(java.lang.Object object)
Determines if the given object is aLocaledText
with the same text and locale.java.lang.String
getText()
int
hashCode()
int
length()
void
setText(java.lang.String text)
Sets the represented text.java.lang.CharSequence
subSequence(int start, int end)
Returns a newCharSequence
that is a subsequence of this sequence.static LocaledText[]
toLocaleTextArray(java.lang.String[] strings, java.util.Locale locale)
Converts an array of strings to an array ofLocaleText
s.java.lang.String
toString()
-
Methods inherited from class com.globalmentor.model.DefaultLocaleable
getLocale, setLocale
-
-
-
-
Constructor Detail
-
LocaledText
public LocaledText(LocaledText localeText) throws java.lang.NullPointerException
Copy constructor.- Parameters:
localeText
- The non-null
object containing the text and optional locale to represent.- Throws:
java.lang.NullPointerException
- if the given locale text isnull
.
-
LocaledText
public LocaledText(java.lang.String text) throws java.lang.NullPointerException
Text constructor with no locale specified.- Parameters:
text
- The non-null
text string to represent.- Throws:
java.lang.NullPointerException
- if the given text isnull
.
-
LocaledText
public LocaledText(java.lang.String text, java.util.Locale locale) throws java.lang.NullPointerException
Full constructor.- Parameters:
text
- The non-null
text string to represent.locale
- The locale that represents the language of the text, ornull
if no language should be indicated.- Throws:
java.lang.NullPointerException
- if the given text isnull
.
-
-
Method Detail
-
getText
public java.lang.String getText()
- Returns:
- The non-
null
text represented.
-
setText
public void setText(java.lang.String text) throws java.lang.NullPointerException
Sets the represented text.- Parameters:
text
- The non-null
text string to represent.- Throws:
java.lang.NullPointerException
- if the given text isnull
.
-
toLocaleTextArray
public static LocaledText[] toLocaleTextArray(java.lang.String[] strings, java.util.Locale locale)
Converts an array of strings to an array ofLocaleText
s.- Parameters:
strings
- The array of strings to be converted to an array ofLocaleText
s.locale
- The locale that represents the language of the text, ornull
if no language should be indicated.- Returns:
- The array after the conversion from strings to
LocaleText
s.
-
equals
public boolean equals(java.lang.Object object)
Determines if the given object is aLocaledText
with the same text and locale.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- The object with which to compare this object; should beLocaledText
.- Returns:
true
if this object equals that specified in object.- See Also:
DefaultLocaleable.getLocale()
,getText()
-
compareTo
public int compareTo(LocaledText localeText) throws java.lang.ClassCastException
Compares this object to another object. This method determines order based upon the text and locale of the object. If both objects have the same text but one locale isnull
, the object with thenull
locale is considered less than the other.- Specified by:
compareTo
in interfacejava.lang.Comparable<LocaledText>
- Parameters:
localeText
- The object with which to compare the component. This must be anotherLocaledText
object.- Returns:
- A negative integer, zero, or a positive integer as this text and locale is less than, equal to, or greater than the text and locale of the specified object, respectively.
- Throws:
java.lang.ClassCastException
- if the specified object's type prevents it from being compared to this object.- See Also:
DefaultLocaleable.getLocale()
,getText()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code value composed from the text and the locale.
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
- Returns:
- the number of
char
s in this sequence.
-
charAt
public char charAt(int index)
Returns thechar
value at the specified index.- Specified by:
charAt
in interfacejava.lang.CharSequence
- Parameters:
index
- The index of thechar
value to be returned.- Returns:
- The specified
char
value. - Throws:
java.lang.IndexOutOfBoundsException
- if the index argument is negative or not less thanlength()
.
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
Returns a newCharSequence
that is a subsequence of this sequence.- Specified by:
subSequence
in interfacejava.lang.CharSequence
- Parameters:
start
- The start index, inclusive.end
- The end index, exclusive.- Returns:
- The specified subsequence.
- Throws:
java.lang.IndexOutOfBoundsException
-- if start or end are negative,
- if end is greater than
length()
, - or if start is greater than end
-
toString
public final java.lang.String toString()
- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of this object's text.
- See Also:
getText()
-
-