public ThreadSafeBitSet andNot(ThreadSafeBitSet other) {
        if(other.log2SegmentSize != log2SegmentSize)
            throw new IllegalArgumentException("Segment sizes must be the same");

        ThreadSafeBitSetSegments thisSegments = this.segments.get();
        ThreadSafeBitSetSegments otherSegments = other.segments.get();
        ThreadSafeBitSetSegments newSegments = new ThreadSafeBitSetSegments(thisSegments.numSegments(), numLongsPerSegment);

        for(int i=0;i<thisSegments.numSegments();i++) {
            AtomicLongArray thisArray = thisSegments.getSegment(i);
            AtomicLongArray otherArray = (i < otherSegments.numSegments()) ? otherSegments.getSegment(i) : null;
            AtomicLongArray newArray = newSegments.getSegment(i);

            for(int j=0;j<thisArray.length();j++) {
                long thisLong = thisArray.get(j);
                long otherLong = (otherArray == null) ? 0 : otherArray.get(j);

                newArray.set(j, thisLong & ~otherLong);
            }
        }

        ThreadSafeBitSet andNot = new ThreadSafeBitSet(log2SegmentSize);
        andNot.segments.set(newSegments);
        return andNot;
    }
@Test
    public void testAndNot() {
        ThreadSafeBitSet tsbSet1 = new ThreadSafeBitSet();
        ThreadSafeBitSet tsbSet2 = new ThreadSafeBitSet();
        for (int i = 0; i < 3; i++) {
            tsbSet1.set(i);
            tsbSet2.set(i * 2);
        }

        // determine andNot
        BitSet andNot_bSet = new BitSet();
        ThreadSafeBitSet andNot_tsbSet = new ThreadSafeBitSet();

        int ordinal = tsbSet1.nextSetBit(0);
        while (ordinal != -1) {
            if (!tsbSet2.get(ordinal)) {
                andNot_bSet.set(ordinal);
                andNot_tsbSet.set(ordinal);
            }
            ordinal = tsbSet1.nextSetBit(ordinal + 1);
        }
        Assert.assertFalse(tsbSet1.equals(tsbSet2));
        Assert.assertNotEquals(tsbSet1, tsbSet2);
        Assert.assertNotEquals(tsbSet1.toBitSet(), tsbSet2.toBitSet());

        // validate content
        ThreadSafeBitSet result = tsbSet1.andNot(tsbSet2);
        Assert.assertEquals(andNot_tsbSet.cardinality(), result.cardinality());
        Assert.assertTrue(andNot_tsbSet.equals(result));
        Assert.assertEquals(andNot_tsbSet, result);
        Assert.assertEquals(andNot_bSet, result.toBitSet());
    }