Class ZonePrinterParser.SubstringTree
- java.lang.Object
-
- javax.time.calendar.format.ZonePrinterParser.SubstringTree
-
- Enclosing class:
- ZonePrinterParser
private static final class ZonePrinterParser.SubstringTree extends java.lang.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 Summary
Fields Modifier and Type Field Description (package private) int
length
The length of the substring this node of the tree contains.private java.util.Map<java.lang.String,ZonePrinterParser.SubstringTree>
substringMap
Map of a substring to a set of substrings that contain the key.
-
Constructor Summary
Constructors Modifier Constructor Description private
SubstringTree(int length)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
add(java.lang.String newSubstring)
Values must be added from shortest to longest.private ZonePrinterParser.SubstringTree
get(java.lang.String substring2)
-
-
-
Field Detail
-
length
final int length
The length of the substring this node of the tree contains. Subtrees will have a longer length.
-
substringMap
private final java.util.Map<java.lang.String,ZonePrinterParser.SubstringTree> substringMap
Map of a substring to a set of substrings that contain the key.
-
-
Method Detail
-
get
private ZonePrinterParser.SubstringTree get(java.lang.String substring2)
-
add
private void add(java.lang.String newSubstring)
Values must be added from shortest to longest.- Parameters:
newSubstring
- the substring to add, not null
-
-