LongBitVector implements BitVector, Cloneable { @Override public int compareTo(BitVector o) { checkSize(o); final int cmp; if (o.size() <= 64) { long x = data + Long.MIN_VALUE; long y = o.toExactLong() + Long.MIN_VALUE; cmp = Long.compare(x, y); assert Integer.signum(cmp) == Integer.signum( BitSetComparator.INSTANCE.compare(toBitSet(), o.toBitSet())); } else { cmp = BitSetComparator.INSTANCE.compare(toBitSet(), o.toBitSet()); } return cmp; } LongBitVector(int size); private  LongBitVector(int size, long data); @Override void and(BitVector o); @Override void andNot(BitVector o); @Override int cardinality(); @Override void clear(); @Override void clear(int bitIndex); @Override void clear(int fromIndex, int toIndex); @Override void copyFrom(BitVector from); @Override void flip(int bitIndex); @Override void flip(int fromIndex, int toIndex); @Override boolean get(int bitIndex); @Override void grayCode(); @Override void grayCodeInverse(); @Override boolean increment(); @Override boolean intersects(BitVector o); @Override int length(); @Override int size(); @Override int nextClearBit(int fromIndex); @Override int nextSetBit(int fromIndex); @Override void or(BitVector o); @Override void rotate(int count); @Override void set(int bitIndex); void set(int bitIndex, boolean value); @Override void set(int fromIndex, int toIndex); @Override void set(int fromIndex, int toIndex, boolean value); @Override void xor(BitVector o); @Override boolean isEmpty(); @Override LongBitVector clone(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); @Override BitSet toBitSet(); @Override long toLong(); @Override BigInteger toBigInteger(); void copyFrom(long value); @Override int compareTo(BitVector o); @Override void copyFrom(BitSet from); @Override void copyFromSection(BitVector src, int fromIndex); @Override long toExactLong(); @Override void smallerEvenAndGrayCode(); @Override void grayCodeRank(BitVector mu, BitVector w); @Override int lowestDifferentBit(); @Override void grayCodeRankInverse(BitVector mu, BitVector known, BitVector r); @Override void copySectionFrom(int offset, BitVector src); @Override long[] toLongArray(); @Override byte[] toBigEndianByteArray(); @Override void copyFrom(long[] array); @Override void copyFromBigEndian(byte[] array); @Override boolean areAllLowestBitsClear(int bitCount); @Override void copyFrom(BigInteger s);  }
@Test public void compareTo() { int n = 10; LongBitVector x = new LongBitVector(64); LongBitVector negativeX = new LongBitVector(64); LongBitVector y = new LongBitVector(64); LongBitVector negativeY = new LongBitVector(64); for (long i = 1 << n; (i -= 17) >= 0; ) { x.copyFrom(i); negativeX.copyFrom(-i); for (long j = 1 << n; (j -= 17) >= 0; ) { y.copyFrom(j); negativeY.copyFrom(-j); Assert.assertEquals(Long.compare(i, j), Integer.signum(x.compareTo(y))); Assert.assertEquals(j == 0 ? Long.signum(i) : (i == 0 ? -1 : Long.compare(-i, -j)), Integer.signum(negativeX.compareTo(negativeY))); Assert.assertEquals(j == 0 ? Long.signum(i) : -1, Integer.signum(x.compareTo(negativeY))); Assert.assertEquals(j == 0 ? -Long.signum(i) : +1, Integer.signum(negativeY.compareTo(x))); } } }