Package org.apache.sis.util.iso
Class AbstractInternationalString
- Object
-
- AbstractInternationalString
-
- All Implemented Interfaces:
CharSequence,Comparable<InternationalString>,Formattable,InternationalString
- Direct Known Subclasses:
DefaultInternationalString,ResourceInternationalString,SimpleInternationalString
public abstract class AbstractInternationalString extends Object implements InternationalString, Formattable
Base class for character strings that has been internationalized into several locales. TheInternationalStringinterface is used instead of theStringclass whenever an attribute needs to be internationalization capable.The default value (as returned by
toString()and otherCharSequencemethods) is the string in the current system-wide default locale. The natural ordering is defined by the value returned bytoString().Substituting a free text by a code listThe ISO standard allows to substitute some character strings in the "free text" domain by aCodeListvalue. This can be done with:Types.getCodeTitle(CodeList)for getting theInternationalStringinstance to store in a metadata property.Types.forCodeTitle(CharSequence)for retrieving theCodeListpreviously stored as anInternationalString.
- Since:
- 0.3
Defined in the
sis-utilitymodule
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractInternationalString()Constructs an international string.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description charcharAt(int index)Returns the character of the string in the default locale at the specified index.intcompareTo(InternationalString object)Compares this string with the specified object for order.voidformatTo(Formatter formatter, int flags, int width, int precision)Formats this international string using the given formatter.intlength()Returns the length of the string in the default locale.CharSequencesubSequence(int start, int end)Returns a subsequence of the string in the default locale.StringtoString()Returns this string in the default locale.abstract StringtoString(Locale locale)Returns this string in the given locale.-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface CharSequence
chars, codePoints
-
-
-
-
Method Detail
-
length
public int length()
Returns the length of the string in the default locale. This is the length of the string returned bytoString().- Specified by:
lengthin interfaceCharSequence- Returns:
- length of the string in the default locale.
-
charAt
public char charAt(int index) throws IndexOutOfBoundsExceptionReturns the character of the string in the default locale at the specified index. This is a character of the string returned bytoString().- Specified by:
charAtin interfaceCharSequence- Parameters:
index- the index of the character.- Returns:
- the character at the specified index.
- Throws:
IndexOutOfBoundsException- if the specified index is out of bounds.
-
subSequence
public CharSequence subSequence(int start, int end)
Returns a subsequence of the string in the default locale. The subsequence is aStringobject starting with the character value at the specified index and ending with the character value at indexend - 1.- Specified by:
subSequencein interfaceCharSequence- Parameters:
start- the start index, inclusive.end- the end index, exclusive.- Returns:
- the specified subsequence.
- Throws:
IndexOutOfBoundsException- ifstartorendis out of range.
-
toString
public abstract String toString(Locale locale)
Returns this string in the given locale. If no string is available in the given locale, then some fallback locale is used. The fallback locale is implementation-dependent, and is not necessarily the same than the default locale used by thetoString()method.Handling ofLocale.ROOTargument valueLocale.ROOTcan be given to this method for requesting a "unlocalized" string, typically some programmatic values like enumerations or identifiers. While identifiers often look like English words,Locale.ROOTis not considered synonymous toLocale.ENGLISHbecause the values may differ in the way numbers and dates are formatted (e.g. using the ISO 8601 standard for dates instead than English conventions).Handling ofThenullargument valueLocale.ROOTconstant is new in Java 6. Some other libraries designed for Java 5 use thenullvalue for "unlocalized" strings. Apache SIS acceptsnullvalue for inter-operability with those libraries. However the behavior is implementation dependent: some subclasses will takenullas a synonymous of the system default locale, while other subclasses will takenullas a synonymous of the root locale. In order to ensure determinist behavior, client code are encouraged to specify only non-null values.- Specified by:
toStringin interfaceInternationalString- Parameters:
locale- the desired locale for the string to be returned.- Returns:
- the string in the given locale if available, or in an implementation-dependent fallback locale otherwise.
- See Also:
Locale.getDefault(),Locale.ROOT
-
toString
public String toString()
Returns this string in the default locale. Invoking this method is equivalent to invokingtoString(Locale.getDefault()).All methods from
CharSequenceoperate on this string. This string is also used as the criterion for natural ordering.- Specified by:
toStringin interfaceCharSequence- Specified by:
toStringin interfaceInternationalString- Overrides:
toStringin classObject- Returns:
- the string in the default locale.
-
formatTo
public void formatTo(Formatter formatter, int flags, int width, int precision)
Formats this international string using the given formatter. This method appends the string obtained by:toString(formatter.Formatter.locale())- Specified by:
formatToin interfaceFormattable- Parameters:
formatter- the formatter to use for formatting this string.flags- a bitmask ofFormattableFlagsvalues.width- the minimum number of characters, or -1 if none.precision- the maximum number of characters (before expanding to thewidth), or -1 for no restriction.
-
compareTo
public int compareTo(InternationalString object)
Compares this string with the specified object for order. This method compares the string in the default locale, as returned bytoString().- Specified by:
compareToin interfaceComparable<InternationalString>- Parameters:
object- the string to compare with this string.- Returns:
- a negative number if this string is before the given string, a positive number if after, or 0 if equals.
-
-