Returns the value of the mapping with the specified key. @param key the key. @return the value of the mapping with the specified key. @throws ClassCastException if the key cannot be compared with the keys in this map. @throws NullPointerException if the key is {@c
(Object key)
| 4253 | * {@code null}. |
| 4254 | */ |
| 4255 | @SuppressWarnings("unchecked") |
| 4256 | @Override |
| 4257 | public V get(Object key) { |
| 4258 | java.lang.Comparable<K> object = comparator == null ? toComparable((K) key) |
| 4259 | : null; |
| 4260 | K keyK = (K) key; |
| 4261 | Node<K, V> node = root; |
| 4262 | while (node != null) { |
| 4263 | K[] keys = node.keys; |
| 4264 | int left_idx = node.left_idx; |
| 4265 | int result = cmp(object, keyK, keys[left_idx]); |
| 4266 | if (result < 0) { |
| 4267 | node = node.left; |
| 4268 | } else if (result == 0) { |
| 4269 | return node.values[left_idx]; |
| 4270 | } else { |
| 4271 | int right_idx = node.right_idx; |
| 4272 | if (left_idx != right_idx) { |
| 4273 | result = cmp(object, keyK, keys[right_idx]); |
| 4274 | } |
| 4275 | if (result > 0) { |
| 4276 | node = node.right; |
| 4277 | } else if (result == 0) { |
| 4278 | return node.values[right_idx]; |
| 4279 | } else { /* search in node */ |
| 4280 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 4281 | while (low <= high) { |
| 4282 | mid = (low + high) >>> 1; |
| 4283 | result = cmp(object, keyK, keys[mid]); |
| 4284 | if (result > 0) { |
| 4285 | low = mid + 1; |
| 4286 | } else if (result == 0) { |
| 4287 | return node.values[mid]; |
| 4288 | } else { |
| 4289 | high = mid - 1; |
| 4290 | } |
| 4291 | } |
| 4292 | return null; |
| 4293 | } |
| 4294 | } |
| 4295 | } |
| 4296 | return null; |
| 4297 | } |
| 4298 | |
| 4299 | /** |
| 4300 | * Returns a set of the keys contained in this map. The set is backed by |
no test coverage detected