Class DateTimeFormatterBuilder.ZoneIdPrinterParser.SubstringTree

java.lang.Object
org.threeten.bp.format.DateTimeFormatterBuilder.ZoneIdPrinterParser.SubstringTree
Enclosing class:
DateTimeFormatterBuilder.ZoneIdPrinterParser

private static final class DateTimeFormatterBuilder.ZoneIdPrinterParser.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 gives 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.