Class 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
    • 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 the char 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 a LocaledText 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 new CharSequence 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 of LocaleTexts.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.CharSequence

        chars, codePoints
    • 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 is null.
      • 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 is null.
      • 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, or null if no language should be indicated.
        Throws:
        java.lang.NullPointerException - if the given text is null.
    • 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 is null.
      • toLocaleTextArray

        public static LocaledText[] toLocaleTextArray​(java.lang.String[] strings,
                                                      java.util.Locale locale)
        Converts an array of strings to an array of LocaleTexts.
        Parameters:
        strings - The array of strings to be converted to an array of LocaleTexts.
        locale - The locale that represents the language of the text, or null if no language should be indicated.
        Returns:
        The array after the conversion from strings to LocaleTexts.
      • equals

        public boolean equals​(java.lang.Object object)
        Determines if the given object is a LocaledText with the same text and locale.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - The object with which to compare this object; should be LocaledText.
        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 is null, the object with the null locale is considered less than the other.
        Specified by:
        compareTo in interface java.lang.Comparable<LocaledText>
        Parameters:
        localeText - The object with which to compare the component. This must be another LocaledText 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 class java.lang.Object
        Returns:
        A hash code value composed from the text and the locale.
      • length

        public int length()
        Specified by:
        length in interface java.lang.CharSequence
        Returns:
        the number of chars in this sequence.
      • charAt

        public char charAt​(int index)
        Returns the char value at the specified index.
        Specified by:
        charAt in interface java.lang.CharSequence
        Parameters:
        index - The index of the char value to be returned.
        Returns:
        The specified char value.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index argument is negative or not less than length().
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Returns a new CharSequence that is a subsequence of this sequence.
        Specified by:
        subSequence in interface java.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 interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this object's text.
        See Also:
        getText()