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)
| 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 |