652 |
|
* elements that are Comparable but not necessarily Comparable<T> |
653 |
|
* for the same T, so we cannot invoke compareTo among them. To |
654 |
|
* handle this, the tree is ordered primarily by hash value, then |
655 |
< |
* by Comparable.compareTo order if applicable, else by class |
656 |
< |
* names if both comparable but not to each other. On lookup at a |
655 |
> |
* by Comparable.compareTo order if applicable. On lookup at a |
656 |
|
* node, if elements are not comparable or compare as 0 then both |
657 |
|
* left and right children may need to be searched in the case of |
658 |
|
* tied hash values. (This corresponds to the full list search |
751 |
|
} |
752 |
|
|
753 |
|
/** |
755 |
– |
* Compares k and x: if k's comparable class (cc) matches x's, |
756 |
– |
* uses Comparable.compareTo. Otherwise compares on comparable |
757 |
– |
* class name if both exist, else 0. |
758 |
– |
*/ |
759 |
– |
@SuppressWarnings("unchecked") |
760 |
– |
static int cccompare(Class<?> cc, Object k, Object x) { |
761 |
– |
Class<?> cx; |
762 |
– |
return ((cc != null && (cx = comparableClassFor(x)) != null) ? |
763 |
– |
((cx == cc) ? ((Comparable<Object>)k).compareTo(x) : |
764 |
– |
cc.getName().compareTo(cx.getName())) : 0); |
765 |
– |
} |
766 |
– |
|
767 |
– |
/** |
754 |
|
* Returns the TreeNode (or null if not found) for the given |
755 |
|
* key. A front-end for recursive version. |
756 |
|
*/ |
770 |
|
dir = (h < ph) ? -1 : 1; |
771 |
|
else if ((pk = p.key) == k || k.equals(pk)) |
772 |
|
return p; |
773 |
< |
else if ((dir = cccompare(cc, k, pk)) == 0) { |
773 |
> |
else if (cc == null || comparableClassFor(pk) != cc || |
774 |
> |
(dir = ((Comparable<Object>)k).compareTo(pk)) == 0) { |
775 |
|
TreeNode<V> r, pl, pr; // check both sides |
776 |
|
if ((pr = p.right) != null && h >= pr.hash && |
777 |
|
(r = getTreeNode(h, k, pr, cc)) != null) |
829 |
|
dir = (h < ph) ? -1 : 1; |
830 |
|
else if ((pk = p.key) == k || k.equals(pk)) |
831 |
|
return p; |
832 |
< |
else if ((dir = cccompare(cc, k, pk)) == 0) { |
832 |
> |
else if (cc == null || comparableClassFor(pk) != cc || |
833 |
> |
(dir = ((Comparable<Object>)k).compareTo(pk)) == 0) { |
834 |
|
TreeNode<V> r, pr; |
835 |
|
if ((pr = p.right) != null && h >= pr.hash && |
836 |
|
(r = getTreeNode(h, k, pr, cc)) != null) |