Class ZonePrinterParser.SubstringTree

java.lang.Object
javax.time.calendar.format.ZonePrinterParser.SubstringTree
Enclosing class:
ZonePrinterParser

private static final class ZonePrinterParser.SubstringTree extends Object
Model a tree of substrings to make the parsing easier. Due to the nature of time-zone names, it can be faster to parse based in unique substrings rather than just a character by character match.

For example, to parse America/Denver we can look at the first two character "Am". We then notice that the shortest time-zone that starts with Am is America/Nome which is 12 characters long. Checking the first 12 characters of America/Denver giver America/Denv which is a substring of only 1 time-zone: America/Denver. Thus, with just 3 comparisons that match can be found.

This structure maps substrings to substrings of a longer length. Each node of the tree contains a length and a map of valid substrings to sub-nodes. The parser gets the length from the root node. It then extracts a substring of that length from the parseText. If the map contains the substring, it is set as the possible time-zone and the sub-node for that substring is retrieved. The process continues until the substring is no longer found, at which point the matched text is checked against the real time-zones.

  • Field Details

    • length

      final int length
      The length of the substring this node of the tree contains. Subtrees will have a longer length.
    • substringMap

      private final Map<String,ZonePrinterParser.SubstringTree> substringMap
      Map of a substring to a set of substrings that contain the key.
  • Constructor Details

    • SubstringTree

      private SubstringTree(int length)
      Constructor.
      Parameters:
      length - the length of this tree
  • Method Details

    • get

      private ZonePrinterParser.SubstringTree get(String substring2)
    • add

      private void add(String newSubstring)
      Values must be added from shortest to longest.
      Parameters:
      newSubstring - the substring to add, not null