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)
| 1272 | * {@code null}. |
| 1273 | */ |
| 1274 | @Override |
| 1275 | public V get(Object key) { |
| 1276 | Comparable<K> object = comparator == null ? toComparable((K) key) : null; |
| 1277 | K keyK = (K) key; |
| 1278 | Node<K, V> node = root; |
| 1279 | while (node != null) { |
| 1280 | K[] keys = node.keys; |
| 1281 | int left_idx = node.left_idx; |
| 1282 | int result = cmp(object, keyK, keys[left_idx]); |
| 1283 | if (result < 0) { |
| 1284 | node = node.left; |
| 1285 | } else if (result == 0) { |
| 1286 | return node.values[left_idx]; |
| 1287 | } else { |
| 1288 | int right_idx = node.right_idx; |
| 1289 | if (left_idx != right_idx) { |
| 1290 | result = cmp(object, keyK, keys[right_idx]); |
| 1291 | } |
| 1292 | if (result > 0) { |
| 1293 | node = node.right; |
| 1294 | } else if (result == 0) { |
| 1295 | return node.values[right_idx]; |
| 1296 | } else { /*search in node*/ |
| 1297 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 1298 | while (low <= high) { |
| 1299 | mid = (low + high) >>> 1; |
| 1300 | result = cmp(object, keyK, keys[mid]); |
| 1301 | if (result > 0) { |
| 1302 | low = mid + 1; |
| 1303 | } else if (result == 0) { |
| 1304 | return node.values[mid]; |
| 1305 | } else { |
| 1306 | high = mid - 1; |
| 1307 | } |
| 1308 | } |
| 1309 | return null; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | return null; |
| 1314 | } |
| 1315 | |
| 1316 | private int cmp(Comparable<K> object, K key1, K key2) { |
| 1317 | return object != null ? |
nothing calls this directly
no test coverage detected