FoldedTreeSet implements SortedSet<E> { public E get(Object obj, Comparator<?> cmp) { Objects.requireNonNull(obj); Node<E> node = root; while (node != null) { E[] entries = node.entries; int leftIndex = node.leftIndex; int result = compare(obj, entries[leftIndex], cmp); if (result < 0) { node = node.left; } else if (result == 0) { return entries[leftIndex]; } else { int rightIndex = node.rightIndex; if (leftIndex != rightIndex) { result = compare(obj, entries[rightIndex], cmp); } if (result == 0) { return entries[rightIndex]; } else if (result > 0) { node = node.right; } else { int low = leftIndex + 1; int high = rightIndex - 1; while (low <= high) { int mid = (low + high) >>> 1; result = compare(obj, entries[mid], cmp); if (result > 0) { low = mid + 1; } else if (result < 0) { high = mid - 1; } else { return entries[mid]; } } return null; } } } return null; } FoldedTreeSet();  FoldedTreeSet(Comparator<E> comparator); @Override Comparator<? super E> comparator(); @Override SortedSet<E> subSet(E fromElement, E toElement); @Override SortedSet<E> headSet(E toElement); @Override SortedSet<E> tailSet(E fromElement); @Override E first(); @Override E last(); @Override int size(); @Override boolean isEmpty(); E get(Object obj, Comparator<?> cmp); E get(E entry); @Override @SuppressWarnings("unchecked") boolean contains(Object obj); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override @SuppressWarnings("unchecked") T[] toArray(T[] a); E addOrReplace(E entry); @Override boolean add(E entry); boolean addSortedLast(E entry); E removeAndGet(Object obj, Comparator<?> cmp); E removeAndGet(Object obj); boolean remove(Object obj, Comparator<?> cmp); @Override boolean remove(Object obj); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); double fillRatio(); boolean compact(long timeout);  }
@Test public void testGet() { FoldedTreeSet<Holder> set = new FoldedTreeSet<>(); long[] longs = new long[43277]; for (int i = 0; i < longs.length; i++) { Holder val = new Holder(srand.nextLong()); while (set.contains(val)) { val = new Holder(srand.nextLong()); } longs[i] = val.getId(); set.add(val); } assertEquals(longs.length, set.size()); for (long val : longs) { assertEquals(val, set.get(new Holder(val)).getId()); } }