/** * Gets the value associated with a key * * @param key * Key * @return Value */ public T get(String key) { TrieNode<T> n = this.find(key); if (n == null) return null; return n.getValue(); }
/** * Gets the value associated with a key * * @param key * Key * @return Value */ public T get(String key) { TrieNode<T> n = this.find(key); if (n == null) return null; return n.getValue(); }
/** * Gets the value associated with a key * * @param key * Key * @return Value */ public T get(String key) { TrieNode<T> n = this.find(key); if (n == null) return null; return n.getValue(); }
/** * Removes a value from the trie * <p> * This doesn't actually remove the key per-se rather sets the value * associated with the key to null. * </p> * * @param key * Key */ public void remove(String key) { TrieNode<T> n = this.find(key); if (n != null) { n.setValue(null); } }
/** * Performs a prefix search and returns all values mapped under the given * prefix. The entirety of the prefix must be matches, if you only want part * of the prefix to be matched use the {@link #partialSearch(String)} method * instead. * * @param prefix * Prefix * @return List of values associated with the given key */ public List<T> prefixSearch(String prefix) { TrieNode<T> n = this.find(prefix); if (n == null) return new ArrayList<>(); return Collections.unmodifiableList(n.getValues()); }
/** * Performs a prefix search and returns all values mapped under the given * prefix. The entirety of the prefix must be matches, if you only want part * of the prefix to be matched use the {@link #partialSearch(String)} method * instead. * * @param prefix * Prefix * @return List of values associated with the given key */ public List<T> prefixSearch(String prefix) { TrieNode<T> n = this.find(prefix); if (n == null) return new ArrayList<>(); return Collections.unmodifiableList(n.getValues()); }
/** * Removes a value from the trie * <p> * This doesn't actually remove the key per-se rather sets the value * associated with the key to null. * </p> * * @param key * Key */ public void remove(String key) { TrieNode<T> n = this.find(key); if (n != null) { n.setValue(null); } }
/** * Performs a prefix search and returns all values mapped under the given * prefix. The entirety of the prefix must be matches, if you only want part * of the prefix to be matched use the {@link #partialSearch(String)} method * instead. * * @param prefix * Prefix * @return List of values associated with the given key */ public List<T> prefixSearch(String prefix) { TrieNode<T> n = this.find(prefix); if (n == null) return new ArrayList<T>(); return Collections.unmodifiableList(n.getValues()); }
/** * Removes a value from the trie * <p> * This doesn't actually remove the key per-se rather sets the value * associated with the key to null. * </p> * * @param key * Key */ public void remove(String key) { TrieNode<T> n = this.find(key); if (n != null) { n.setValue(null); } }
/** * Gets whether a key exists in the trie and meets the given value criteria * * @param key * Key * @param requireValue * If true a key must have a non-null value associated with it to * be considered to be contained in the tree, if false then the * key must merely map to a node in the trie * @return True if the key exists and the value criteria is met, false * otherwise */ public boolean contains(String key, boolean requireValue) { TrieNode<T> n = this.find(key); if (n == null) return false; if (requireValue) { return n.hasValue(); } else { return true; } }
/** * Gets whether a key exists in the trie and meets the given value criteria * * @param key * Key * @param requireValue * If true a key must have a non-null value associated with it to * be considered to be contained in the tree, if false then the * key must merely map to a node in the trie * @return True if the key exists and the value criteria is met, false * otherwise */ public boolean contains(String key, boolean requireValue) { TrieNode<T> n = this.find(key); if (n == null) return false; if (requireValue) { return n.hasValue(); } else { return true; } }
/** * Gets whether a key exists in the trie and meets the given value criteria * * @param key * Key * @param requireValue * If true a key must have a non-null value associated with it to * be considered to be contained in the tree, if false then the * key must merely map to a node in the trie * @return True if the key exists and the value criteria is met, false * otherwise */ public boolean contains(String key, boolean requireValue) { TrieNode<T> n = this.find(key); if (n == null) return false; if (requireValue) { return n.hasValue(); } else { return true; } }
/** * Gets whether a key value pair are present in the trie * * @param key * Key * @param value * Value * @return True if the key value pair exists in the trie, false otherwise */ public boolean contains(String key, T value) { TrieNode<T> n = this.find(key); if (n == null) return false; if (value == null && !n.hasValue()) return true; return value.equals(n.getValue()); }
/** * Gets whether a key value pair are present in the trie * * @param key * Key * @param value * Value * @return True if the key value pair exists in the trie, false otherwise */ public boolean contains(String key, T value) { TrieNode<T> n = this.find(key); if (n == null) return false; if (value == null && !n.hasValue()) return true; return value.equals(n.getValue()); }
/** * Gets whether a key value pair are present in the trie * * @param key * Key * @param value * Value * @return True if the key value pair exists in the trie, false otherwise */ public boolean contains(String key, T value) { TrieNode<T> n = this.find(key); if (n == null) return false; if (value == null && !n.hasValue()) return true; return value.equals(n.getValue()); }