Class DateTimeFieldRule.TextStore

  • Enclosing class:
    DateTimeFieldRule<T>

    public static final class DateTimeFieldRule.TextStore
    extends java.lang.Object
    The mapping between integer values and textual representations.

    Some fields have a textual representation, such as day-of-week or month-of-year. These textual representations can be captured in this class for printing and parsing.

    TextStore is immutable and thread-safe.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.Integer> insensitiveTextValueMap
      Map of case insensitive text to value.
      private int[] lengths
      The lengths of the text items.
      private java.util.Locale locale
      The locale of the text.
      private java.util.Map<java.lang.String,​java.lang.Integer> textValueMap
      Map of case sensitive text to value.
      private java.util.Map<java.lang.Integer,​java.lang.String> valueTextMap
      Map of value to text.
    • Constructor Summary

      Constructors 
      Constructor Description
      TextStore​(java.util.Locale locale, java.util.Map<java.lang.Integer,​java.lang.String> valueTextMap)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Locale getLocale()
      Gets the locale that the text relates to.
      java.util.Map<java.lang.String,​java.lang.Integer> getTextValueMap()
      Gets the derived map expressing the value for each text.
      java.lang.String getValueText​(int value)
      Gets the text for the specified integer value.
      java.util.Map<java.lang.Integer,​java.lang.String> getValueTextMap()
      Gets the map of text for each integer value.
      long matchText​(boolean ignoreCase, java.lang.String parseText)
      Matches the specified text against the text-value map returning the matched length and value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • locale

        private final java.util.Locale locale
        The locale of the text.
      • valueTextMap

        private final java.util.Map<java.lang.Integer,​java.lang.String> valueTextMap
        Map of value to text.
      • textValueMap

        private final java.util.Map<java.lang.String,​java.lang.Integer> textValueMap
        Map of case sensitive text to value.
      • insensitiveTextValueMap

        private final java.util.Map<java.lang.String,​java.lang.Integer> insensitiveTextValueMap
        Map of case insensitive text to value.
      • lengths

        private final int[] lengths
        The lengths of the text items.
    • Constructor Detail

      • TextStore

        public TextStore​(java.util.Locale locale,
                         java.util.Map<java.lang.Integer,​java.lang.String> valueTextMap)
        Constructor.
        Parameters:
        locale - the locale, not null
        valueTextMap - the map of values to text to store, not null
    • Method Detail

      • getLocale

        public java.util.Locale getLocale()
        Gets the locale that the text relates to.
        Returns:
        the locale for the text, never null
      • getValueTextMap

        public java.util.Map<java.lang.Integer,​java.lang.String> getValueTextMap()
        Gets the map of text for each integer value.
        Returns:
        the unmodifiable map of value to text, never null
      • getValueText

        public java.lang.String getValueText​(int value)
        Gets the text for the specified integer value.

        The text associated with the value is returned, or null if none found.

        Parameters:
        value - the value to get text for
        Returns:
        the text for the field value, null if no text found
      • getTextValueMap

        public java.util.Map<java.lang.String,​java.lang.Integer> getTextValueMap()
        Gets the derived map expressing the value for each text.

        If the value-text map contains duplicate text elements then this map will be empty.

        Returns:
        the unmodifiable map of text to value for the field rule and style, never null
      • matchText

        public long matchText​(boolean ignoreCase,
                              java.lang.String parseText)
        Matches the specified text against the text-value map returning the matched length and value.

        This method is intended for use during parsing, and matches the search text against the text-value map, optionally ignoring case.

        Parameters:
        ignoreCase - true to ignore case during the matching
        parseText - the text to match against
        Returns:
        a long packed result of two int values (for performance in parsing). The value is (parseLength << 32 + matchedValue). Zero is returned if there is no match. Minus one is returned if the text store cannot parse. The parse length can be obtained via (result >>> 32). The value can be obtained via ((int) result).