private static class NameNode.AbbreviationComparator extends NameNode.ExactMatchComparator
NameNode objects as
equivalent if the second node's name represents an abbreviation for the
first node's name. This is used when looking up a name which may be
abbreviated, when an exact match lookup has already failed.
Note: this comparator imposes orderings that are inconsistent with equals.
| Modifier | Constructor and Description |
|---|---|
private |
AbbreviationComparator() |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(NameNode n1,
NameNode n2)
Resolves a comparison of two
NameNode objects. |
public int compare(NameNode n1, NameNode n2)
NameNode objects. The
criteria for this comparison to determine equivalence is either an
exact lexical match of the nodes' names, or that the name of node
n1 lexically begins with the name of node
n2.
Important Node: this implementation supports the
lookup of an abbreviated name within a sorted list of unabbreviated
names. It relies upon the binary search implementation provided by
java.util.Collections, in that it assumes the search key
will always be n2, and n1 always represents
a node from the list being searched. This assumption is
fundamental to the correct behavior of the Namespace.find(java.lang.String, boolean, java.util.Set<java.lang.String>)
method.
compare in interface java.util.Comparator<NameNode>compare in class NameNode.ExactMatchComparatorn1 - First NameNode for comparison.n2 - Second NameNode for comparison.0 if nodes' names are considered equal
according to the rules described above; -1 if
o1 is considered lexically less than
o2; 1 if o1 is
considered lexically greater than o2.