MCPcopy Create free account
hub / github.com/GateNLP/gate-core / getClosestMatch

Method getClosestMatch

src/main/java/gate/util/RBTreeMap.java:204–222  ·  view source on GitHub ↗

Returns a pair of values: (glb,lub). If the given key is found in the map then glb=lub=the value associated with the given key. If the key is not in the map: glb=the value associated with the greatest key in the map that is lower than the given key; or null if the given key is smaller than any key i

(K key)

Source from the content-addressed store, hash-verified

202 * If the map is empty it returns (null,null).
203 */
204 @SuppressWarnings("unchecked")
205 public V[] getClosestMatch(K key){
206 if (root==null)return (V[])(new Object[]{null,null});
207
208 Entry<K,V> lub=getCeilEntry(key);
209
210 if(lub==null){//greatest key in set is still smaller then parameter "key"
211 return (V[])new Object[]{lastEntry().value,null};
212 };
213
214 int cmp=compare(key,lub.key);
215
216 if (cmp==0){return (V[])(new Object[]{lub.value,lub.value});}
217 else {
218 Entry<K,V> prec=getPrecedingEntry(lub.key);
219 if (prec == null) return (V[])(new Object[]{null,lub.value});
220 else return (V[])(new Object[]{prec.value,lub.value});
221 }
222 }
223
224 /** Returns the value associated to the next key in the map if an exact match
225 * doesn't exist. If there is an exact match, the method will return the

Callers 1

testClosestMatchMethod · 0.80

Calls 4

getCeilEntryMethod · 0.95
lastEntryMethod · 0.95
compareMethod · 0.95
getPrecedingEntryMethod · 0.95

Tested by 1

testClosestMatchMethod · 0.64