@Test public void toBigInteger() { int n = 10; LongBitVector x = new LongBitVector(64); LongBitVector negativeX = new LongBitVector(64); for (long i = 1 << n; --i >= 0; ) { x.copyFrom(i); Assert.assertEquals(BigInteger.valueOf(i), x.toBigInteger()); long j = -i; negativeX.copyFrom(j); BigInteger expected = BigInteger.ZERO; for (int k = 0; k < 64; ++k) { if (((j >> k) & 1) == 1) { expected = expected.setBit(k); } } Assert.assertEquals(expected, negativeX.toBigInteger()); } }
@Override public BigInteger toBigInteger() { final BigInteger result; if (data >= 0) { result = BigInteger.valueOf(data); } else { BigInteger missingLowestBit = BigInteger.valueOf(data >>> 1).shiftLeft(1); if ((data & 1) == 1) { result = missingLowestBit.setBit(0); } else { result = missingLowestBit; } } return result; }
LongBitVector implements BitVector, Cloneable { @Override public BigInteger toBigInteger() { final BigInteger result; if (data >= 0) { result = BigInteger.valueOf(data); } else { BigInteger missingLowestBit = BigInteger.valueOf(data >>> 1).shiftLeft(1); if ((data & 1) == 1) { result = missingLowestBit.setBit(0); } else { result = missingLowestBit; } } return result; } }
LongBitVector implements BitVector, Cloneable { @Override public BigInteger toBigInteger() { final BigInteger result; if (data >= 0) { result = BigInteger.valueOf(data); } else { BigInteger missingLowestBit = BigInteger.valueOf(data >>> 1).shiftLeft(1); if ((data & 1) == 1) { result = missingLowestBit.setBit(0); } else { result = missingLowestBit; } } return result; } LongBitVector(int size); private  LongBitVector(int size, long data); }
LongBitVector implements BitVector, Cloneable { @Override public BigInteger toBigInteger() { final BigInteger result; if (data >= 0) { result = BigInteger.valueOf(data); } else { BigInteger missingLowestBit = BigInteger.valueOf(data >>> 1).shiftLeft(1); if ((data & 1) == 1) { result = missingLowestBit.setBit(0); } else { result = missingLowestBit; } } return result; } 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); }
LongBitVector implements BitVector, Cloneable { @Override public BigInteger toBigInteger() { final BigInteger result; if (data >= 0) { result = BigInteger.valueOf(data); } else { BigInteger missingLowestBit = BigInteger.valueOf(data >>> 1).shiftLeft(1); if ((data & 1) == 1) { result = missingLowestBit.setBit(0); } else { result = missingLowestBit; } } return result; } 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);  }