Skip to content

StringHashTrie ​

com.jsmacrosce.StringHashTrie

Stores strings in a prefix trie and provides collection operations and prefix searches.

Constructors ​

new StringHashTrie ​

new StringHashTrie()#
Initializes an empty root trie with no parent.

Methods ​

add ​

add(String s): boolean#
Adds a case-sensitive string if it is not already stored. A null string causes NullPointerException.

Parameters:

  • s: string to add
Returns: true if the string was added; false if it was already present

addAll ​

addAll(Collection<? extends String> c): boolean#
Adds each string in the collection. Processing is not rolled back if an element fails; a null collection or null element causes NullPointerException.

Parameters:

  • c: strings to add
Returns: true if at least one string was added
addAll(String... o): boolean#
Adds each supplied string. Processing is not rolled back if an element fails; a null array or null element causes NullPointerException.

Parameters:

  • o: strings to add
Returns: true if at least one string was added

clear ​

clear(): void#
Removes all strings stored directly or below this trie node.

contains ​

contains(Object o): boolean#
Tests whether this trie contains the supplied string, using case-sensitive matching. Non-string values, including null, are not contained.

Parameters:

  • o: value to test
Returns: true if o is a stored string

containsAll ​

containsAll(Collection<?> c): boolean#
Tests whether every element of the collection is a stored string. Non-strings and null elements are not contained; a null collection causes NullPointerException.

Parameters:

  • c: collection of values to test
Returns: true if every element is contained, including when the collection is empty
containsAll(String... o): boolean#
Tests whether every supplied string is stored; unlike the collection overload, this accepts an array of strings. Null elements are not contained; a null array causes NullPointerException.

Parameters:

  • o: strings to test
Returns: true if every string is contained, including when the array is empty

getAll ​

getAll(): Set<String>#
Returns a snapshot of the strings in this trie; modifying the set does not modify the trie.
Returns: all strings

getAllWithPrefix ​

getAllWithPrefix(String prefix): Set<String>#
Searches for strings beginning with the given case-sensitive prefix. When the prefix ends within a trie key, this returns the first matching leaf if present; otherwise, it returns the first matching child subtree, so other matches may be omitted.

Parameters:

  • prefix: prefix to match
Returns: matching strings, or all strings when prefix is empty

getAllWithPrefixCaseInsensitive ​

getAllWithPrefixCaseInsensitive(String prefix): Set<String>#
Searches for strings beginning with the given prefix, ignoring case. When the prefix is longer than a trie key, matching is performed segment by segment, which may omit matches when case-insensitive comparison changes length.

Parameters:

  • prefix: prefix to match
Returns: matching strings, or all strings when prefix is empty

isEmpty ​

isEmpty(): boolean#
Returns whether this node has no directly stored strings and no children.
Returns: true when this node has neither leaves nor children

iterator ​

iterator(): Iterator<String>#
Returns an iterator over a snapshot of the strings currently stored in this trie. Its order is unspecified; removing through the iterator affects only the snapshot, and later trie changes are not reflected.
Returns: an iterator over the snapshot

remove ​

remove(Object o): boolean#
Removes a string from this trie if present.

Parameters:

  • o: string to remove
Returns: true if the string was present and removed

removeAll ​

removeAll(Collection<?> c): boolean#
Removes each supplied element that is a string in this trie. The collection must not be null; otherwise this method throws NullPointerException.

Parameters:

  • c: non-null collection of elements to remove; non-strings and null elements are ignored
Returns: true if at least one string was removed
removeAll(String... o): boolean#
Removes each supplied string from this trie. The array must not be null; otherwise this method throws NullPointerException.

Parameters:

  • o: non-null array of strings to remove
Returns: true if at least one string was removed

retainAll ​

retainAll(Collection<?> c): boolean#
Removes every stored string not contained in the supplied collection. The collection must not be null; otherwise this method throws NullPointerException.

Parameters:

  • c: non-null collection of strings to retain
Returns: true if at least one string was removed
retainAll(String... o): boolean#
Removes every stored string not present in the supplied strings. The array must not be null; otherwise this method throws NullPointerException.

Parameters:

  • o: non-null array of strings to retain
Returns: true if at least one string was removed

size ​

size(): int#
Returns the number of strings stored in this trie, including strings in descendant nodes.
Returns: the total stored string count

toArray ​

toArray(): String[]#
Returns the strings currently stored in this trie as a new array; its order is unspecified.
Returns: a new array containing the current strings
toArray(T[] a): T[]#
Copies the strings currently stored in this trie into an array, following Set.toArray(T[]) semantics. The result is a snapshot with unspecified element order. If a is too small, a new array of the same runtime type is returned; if it is larger, the first unused element is set to null. A null array causes NullPointerException, and an incompatible component type causes ArrayStoreException.

Parameters:

  • a: destination array

Type Parameters:

  • T: the array element type
Returns: the destination array if large enough, otherwise a new array of the same runtime type
toArray(IntFunction<T[]> arg0): T[]#

Returns: T[]

toString ​

toString(): String#
Returns: a structural representation for debugging; it may not be valid JSON