()
| 759 | } |
| 760 | |
| 761 | private void setLastKey() { |
| 762 | if (lastKeyModCount == backingMap.modCount) { |
| 763 | return; |
| 764 | } |
| 765 | java.lang.Comparable<K> object = backingMap.comparator == null ? toComparable((K) endKey) |
| 766 | : null; |
| 767 | K key = (K) endKey; |
| 768 | Node<K, V> node = backingMap.root; |
| 769 | Node<K, V> foundNode = null; |
| 770 | int foundIndex = -1; |
| 771 | TOP_LOOP: while (node != null) { |
| 772 | K[] keys = node.keys; |
| 773 | int left_idx = node.left_idx; |
| 774 | // to be compatible with RI on null-key comparator |
| 775 | int result = object != null ? object.compareTo(keys[left_idx]) : -backingMap.comparator.compare( |
| 776 | keys[left_idx] , key); |
| 777 | //int result = - backingMap.cmp(object, keys[left_idx] , key); |
| 778 | if (result < 0) { |
| 779 | node = node.left; |
| 780 | } else { |
| 781 | int right_idx = node.right_idx; |
| 782 | if (left_idx != right_idx) { |
| 783 | result = backingMap.cmp(object, key, keys[right_idx]); |
| 784 | } |
| 785 | if (result > 0) { |
| 786 | foundNode = node; |
| 787 | foundIndex = right_idx; |
| 788 | node = node.right; |
| 789 | } else if (result == 0) { |
| 790 | if (node.left_idx == node.right_idx) { |
| 791 | foundNode = node.prev; |
| 792 | if (foundNode != null) { |
| 793 | foundIndex = foundNode.right_idx - 1; |
| 794 | } |
| 795 | } else { |
| 796 | foundNode = node; |
| 797 | foundIndex = right_idx; |
| 798 | } |
| 799 | break; |
| 800 | } else { /* search in node */ |
| 801 | foundNode = node; |
| 802 | foundIndex = left_idx; |
| 803 | int low = left_idx + 1, mid = 0, high = right_idx - 1; |
| 804 | while (low <= high) { |
| 805 | mid = (low + high) >>> 1; |
| 806 | result = backingMap.cmp(object, key, keys[mid]); |
| 807 | if (result > 0) { |
| 808 | foundNode = node; |
| 809 | foundIndex = mid; |
| 810 | low = mid + 1; |
| 811 | } else if (result == 0) { |
| 812 | foundNode = node; |
| 813 | foundIndex = mid; |
| 814 | break TOP_LOOP; |
| 815 | } else { |
| 816 | high = mid - 1; |
| 817 | } |
| 818 | } |
no test coverage detected