java.util.BitSet

Here are the examples of the java api class java.util.BitSet taken from open source projects.

1. BitSetTest#test_clearII()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_clearII() {
    // Regression for HARMONY-98
    BitSet bitset = new BitSet();
    for (int i = 0; i < 20; i++) {
        bitset.set(i);
    }
    bitset.clear(10, 10);
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    int initialSize = bs.size();
    assertEquals(64, initialSize);
    bs.set(0, initialSize);
    bs.clear(5);
    bs.clear(15);
    bs.clear(7, 11);
    assertEquals("{0, 1, 2, 3, 4, 6, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, " + "26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, " + "46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}", bs.toString());
    for (int i = initialSize; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(7, 64);
    assertEquals("Failed to grow BitSet", 64, bs.size());
    for (int i = 0; i < 7; i++) {
        assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = 7; i < 64; i++) {
        assertFalse("Failed to clear bit " + i, bs.get(i));
    }
    for (int i = 64; i < bs.size(); i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    // more boundary testing
    bs = new BitSet(32);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(0, 64);
    for (int i = 0; i < 64; i++) {
        assertFalse("Failed to clear bit " + i, bs.get(i));
    }
    for (int i = 64; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    bs = new BitSet(32);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(0, 65);
    for (int i = 0; i < 65; i++) {
        assertFalse("Failed to clear bit " + i, bs.get(i));
    }
    for (int i = 65; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(7);
    bs.clear(110);
    bs.clear(9, 74);
    for (int i = 0; i < 9; i++) {
        if (i == 7) {
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
        }
    }
    for (int i = 9; i < 74; i++) {
        assertFalse("Failed to clear bit " + i, bs.get(i));
    }
    for (int i = 74; i < initialSize; i++) {
        if (i == 110) {
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
        }
    }
    for (int i = initialSize; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(0, 256);
    bs.clear(7);
    bs.clear(255);
    bs.clear(9, 219);
    for (int i = 0; i < 9; i++) {
        if (i == 7) {
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
        }
    }
    for (int i = 9; i < 219; i++) {
        assertFalse("failed to clear bit " + i, bs.get(i));
    }
    for (int i = 219; i < 255; i++) {
        assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = 255; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // test illegal args
    bs = new BitSet(10);
    try {
        bs.clear(-1, 3);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.clear(2, -1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    bs.set(2, 4);
    bs.clear(2, 2);
    assertTrue("Bit got cleared incorrectly ", bs.get(2));
    try {
        bs.clear(4, 2);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    bs = new BitSet(0);
    assertEquals("Test1: Wrong length,", 0, bs.length());
    assertEquals("Test1: Wrong size,", 0, bs.size());
    bs.clear(0, 2);
    assertEquals("Test2: Wrong length,", 0, bs.length());
    assertEquals("Test2: Wrong size,", 0, bs.size());
    bs.clear(60, 64);
    assertEquals("Test3: Wrong length,", 0, bs.length());
    assertEquals("Test3: Wrong size,", 0, bs.size());
    bs.clear(64, 120);
    assertEquals("Test4: Wrong length,", 0, bs.length());
    assertEquals("Test4: Wrong size,", 0, bs.size());
    bs.set(25);
    assertEquals("Test5: Wrong length,", 26, bs.length());
    assertEquals("Test5: Wrong size,", 64, bs.size());
    bs.clear(60, 64);
    assertEquals("Test6: Wrong length,", 26, bs.length());
    assertEquals("Test6: Wrong size,", 64, bs.size());
    bs.clear(64, 120);
    assertEquals("Test7: Wrong size,", 64, bs.size());
    assertEquals("Test7: Wrong length,", 26, bs.length());
    bs.clear(80);
    assertEquals("Test8: Wrong size,", 64, bs.size());
    assertEquals("Test8: Wrong length,", 26, bs.length());
    bs.clear(25);
    assertEquals("Test9: Wrong size,", 64, bs.size());
    assertEquals("Test9: Wrong length,", 0, bs.length());
}

2. CookieUtil#validCookieNameOctets()

Project: netty
Source File: CookieUtil.java
View license
private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) {
    BitSet bits = new BitSet(8);
    bits.or(validCookieValueOctets);
    bits.set('(', false);
    bits.set(')', false);
    bits.set('<', false);
    bits.set('>', false);
    bits.set('@', false);
    bits.set(':', false);
    bits.set('/', false);
    bits.set('[', false);
    bits.set(']', false);
    bits.set('?', false);
    bits.set('=', false);
    bits.set('{', false);
    bits.set('}', false);
    bits.set(' ', false);
    bits.set('\t', false);
    return bits;
}

3. BitSetTest#clearII()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void clearII() throws IndexOutOfBoundsException {
    // Regression for HARMONY-98
    BitSet bitset = new BitSet();
    for (int i = 0; i < 20; i++) {
        bitset.set(i);
    }
    bitset.clear(10, 10);
    // Test for method void java.util.BitSet.clear(int, int)
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    int initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(5);
    bs.clear(15);
    bs.clear(7, 11);
    for (int i = 0; i < 7; i++) {
        if (i == 5)
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = 7; i < 11; i++) assertFalse("Failed to clear bit " + i, bs.get(i));
    for (int i = 11; i < initialSize; i++) {
        if (i == 15)
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = initialSize; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(7, 64);
    for (int i = 0; i < 7; i++) assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    for (int i = 7; i < 64; i++) assertFalse("Failed to clear bit " + i, bs.get(i));
    for (int i = 64; i < bs.size(); i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    // more boundary testing
    bs = new BitSet(32);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(0, 64);
    for (int i = 0; i < 64; i++) assertFalse("Failed to clear bit " + i, bs.get(i));
    for (int i = 64; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    bs = new BitSet(32);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(0, 65);
    for (int i = 0; i < 65; i++) assertFalse("Failed to clear bit " + i, bs.get(i));
    for (int i = 65; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    initialSize = bs.size();
    bs.set(0, initialSize);
    bs.clear(7);
    bs.clear(110);
    bs.clear(9, 74);
    for (int i = 0; i < 9; i++) {
        if (i == 7)
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = 9; i < 74; i++) assertFalse("Failed to clear bit " + i, bs.get(i));
    for (int i = 74; i < initialSize; i++) {
        if (i == 110)
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = initialSize; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(0, 256);
    bs.clear(7);
    bs.clear(255);
    bs.clear(9, 219);
    for (int i = 0; i < 9; i++) {
        if (i == 7)
            assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    }
    for (int i = 9; i < 219; i++) assertFalse("failed to clear bit " + i, bs.get(i));
    for (int i = 219; i < 255; i++) assertTrue("Shouldn't have cleared bit " + i, bs.get(i));
    for (int i = 255; i < bs.size(); i++) assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    bs.set(2, 4);
    bs.clear(2, 2);
    assertTrue("Bit got cleared incorrectly ", bs.get(2));
    /*try {
            bs.clear(4, 2);
            fail("Test4: Attempt to flip with illegal args failed to generate exception");
        } catch (IndexOutOfBoundsException e) {
            // excepted
        }*/
    bs = new BitSet(0);
    assertEquals("Test1: Wrong length,", 0, bs.length());
    bs.clear(0, 2);
    assertEquals("Test2: Wrong length,", 0, bs.length());
    bs.clear(60, 64);
    assertEquals("Test3: Wrong length,", 0, bs.length());
    bs.clear(64, 120);
    assertEquals("Test4: Wrong length,", 0, bs.length());
    bs.set(25);
    assertEquals("Test5: Wrong length,", 26, bs.length());
    bs.clear(60, 64);
    assertEquals("Test6: Wrong length,", 26, bs.length());
    bs.clear(64, 120);
    assertEquals("Test7: Wrong length,", 26, bs.length());
    bs.clear(80);
    assertEquals("Test8: Wrong length,", 26, bs.length());
    bs.clear(25);
    assertEquals("Test9: Wrong length,", 0, bs.length());
}

4. BitSetTest#test_cardinality()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_cardinality() {
    BitSet bs = new BitSet(500);
    bs.set(5);
    bs.set(32);
    bs.set(63);
    bs.set(64);
    assertEquals(bs.toString(), 4, bs.cardinality());
    bs.set(71, 110);
    bs.set(127, 130);
    bs.set(193);
    bs.set(450);
    assertEquals(bs.toString(), 48, bs.cardinality());
    bs.flip(0, 500);
    assertEquals("cardinality() returned wrong value", 452, bs.cardinality());
    bs.clear();
    assertEquals("cardinality() returned wrong value", 0, bs.cardinality());
    bs.set(0, 500);
    assertEquals("cardinality() returned wrong value", 500, bs.cardinality());
}

5. BitSetTest#cardinality()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void cardinality() {
    // test for method int java.util.BitSet.cardinality()
    BitSet bs = new BitSet(500);
    bs.set(5);
    bs.set(32);
    bs.set(63);
    bs.set(64);
    bs.set(71, 110);
    bs.set(127, 130);
    bs.set(193);
    bs.set(450);
    assertEquals("cardinality() returned wrong value", 48, bs.cardinality());
    bs.flip(0, 500);
    assertEquals("cardinality() returned wrong value", 452, bs.cardinality());
    bs.clear();
    assertEquals("cardinality() returned wrong value", 0, bs.cardinality());
    bs.set(0, 500);
    assertEquals("cardinality() returned wrong value", 500, bs.cardinality());
}

6. HammingDistanceTest#testDistanceBitSet()

Project: smile
Source File: HammingDistanceTest.java
View license
/**
     * Test of distance method, of class HammingDistance.
     */
@Test
public void testDistanceBitSet() {
    System.out.println("distance");
    BitSet x = new BitSet();
    x.set(1);
    x.set(3);
    x.set(4);
    x.set(5);
    x.set(7);
    BitSet y = new BitSet();
    y.set(1);
    y.set(4);
    y.set(7);
    assertEquals(2, HammingDistance.d(x, y), 1E-9);
}

7. BitSetTest#test_flipII()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_flipII() {
    BitSet bitset = new BitSet();
    for (int i = 0; i < 20; i++) {
        bitset.set(i);
    }
    bitset.flip(10, 10);
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    bs.set(7);
    bs.set(10);
    bs.flip(7, 11);
    for (int i = 0; i < 7; i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    assertFalse("Failed to flip bit 7", bs.get(7));
    assertTrue("Failed to flip bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < bs.size(); i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    bs.set(7);
    bs.set(10);
    bs.flip(7, 64);
    assertEquals("Failed to grow BitSet", 64, bs.size());
    for (int i = 0; i < 7; i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    assertFalse("Failed to flip bit 7", bs.get(7));
    assertTrue("Failed to flip bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < 64; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 64", bs.get(64));
    // more boundary testing
    bs = new BitSet(32);
    bs.flip(0, 64);
    for (int i = 0; i < 64; i++) {
        assertTrue("Failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 64", bs.get(64));
    bs = new BitSet(32);
    bs.flip(0, 65);
    for (int i = 0; i < 65; i++) {
        assertTrue("Failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 65", bs.get(65));
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    bs.set(7);
    bs.set(10);
    bs.set(72);
    bs.set(110);
    bs.flip(9, 74);
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 7", bs.get(7));
    assertFalse("Shouldn't have flipped bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < 72; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 72", bs.get(72));
    assertTrue("Failed to flip bit 73", bs.get(73));
    for (int i = 74; i < 110; i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 110", bs.get(110));
    for (int i = 111; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(7);
    bs.set(10);
    bs.set(72);
    bs.set(110);
    bs.set(181);
    bs.set(220);
    bs.flip(9, 219);
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 7", bs.get(7));
    assertFalse("Shouldn't have flipped bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < 72; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 72", bs.get(72));
    for (int i = 73; i < 110; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 110", bs.get(110));
    for (int i = 111; i < 181; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 181", bs.get(181));
    for (int i = 182; i < 219; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 219", bs.get(219));
    assertTrue("Shouldn't have flipped bit 220", bs.get(220));
    for (int i = 221; i < bs.size(); i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    // test illegal args
    bs = new BitSet(10);
    try {
        bs.flip(-1, 3);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.flip(2, -1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.flip(4, 2);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
}

8. Data#hashCode()

Project: TomP2P
Source File: Data.java
View license
@Override
public int hashCode() {
    BitSet bs = new BitSet(8);
    bs.set(0, signed);
    bs.set(1, ttl);
    bs.set(2, basedOnFlag);
    bs.set(3, protectedEntry);
    bs.set(4, publicKeyFlag);
    bs.set(5, flag1);
    bs.set(6, flag2);
    bs.set(7, prepareFlag);
    int hashCode = bs.hashCode() ^ ttlSeconds ^ type.ordinal() ^ length;
    for (Number160 basedOn : basedOnSet) {
        hashCode = hashCode ^ basedOn.hashCode();
    }
    // This is a slow operation, use with care!
    return hashCode ^ buffer.hashCode();
}

9. BitSetTest#test_andNotLjava_util_BitSet()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_andNotLjava_util_BitSet() {
    BitSet bs = (BitSet) eightbs.clone();
    bs.clear(5);
    BitSet bs2 = new BitSet();
    bs2.set(2);
    bs2.set(3);
    bs.andNot(bs2);
    assertEquals("Incorrect bitset after andNot", "{0, 1, 4, 6, 7}", bs.toString());
    bs = new BitSet(0);
    bs.andNot(bs2);
    assertEquals("Incorrect size", 0, bs.size());
}

10. BitSetTest#flipII()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void flipII() {
    BitSet bitset = new BitSet();
    for (int i = 0; i < 20; i++) {
        bitset.set(i);
    }
    bitset.flip(10, 10);
    // Test for method void java.util.BitSet.flip(int, int)
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    bs.set(7);
    bs.set(10);
    bs.flip(7, 11);
    for (int i = 0; i < 7; i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    assertFalse("Failed to flip bit 7", bs.get(7));
    assertTrue("Failed to flip bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < bs.size(); i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    bs.set(7);
    bs.set(10);
    bs.flip(7, 64);
    for (int i = 0; i < 7; i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
    assertFalse("Failed to flip bit 7", bs.get(7));
    assertTrue("Failed to flip bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < 64; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 64", bs.get(64));
    // more boundary testing
    bs = new BitSet(32);
    bs.flip(0, 64);
    for (int i = 0; i < 64; i++) {
        assertTrue("Failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 64", bs.get(64));
    bs = new BitSet(32);
    bs.flip(0, 65);
    for (int i = 0; i < 65; i++) {
        assertTrue("Failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 65", bs.get(65));
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    bs.set(7);
    bs.set(10);
    bs.set(72);
    bs.set(110);
    bs.flip(9, 74);
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 7", bs.get(7));
    assertFalse("Shouldn't have flipped bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < 72; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 72", bs.get(72));
    assertTrue("Failed to flip bit 73", bs.get(73));
    for (int i = 74; i < 110; i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 110", bs.get(110));
    for (int i = 111; i < bs.size(); i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(7);
    bs.set(10);
    bs.set(72);
    bs.set(110);
    bs.set(181);
    bs.set(220);
    bs.flip(9, 219);
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have flipped bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 7", bs.get(7));
    assertFalse("Shouldn't have flipped bit 8", bs.get(8));
    assertTrue("Failed to flip bit 9", bs.get(9));
    assertFalse("Failed to flip bit 10", bs.get(10));
    for (int i = 11; i < 72; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 72", bs.get(72));
    for (int i = 73; i < 110; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 110", bs.get(110));
    for (int i = 111; i < 181; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Failed to flip bit 181", bs.get(181));
    for (int i = 182; i < 219; i++) {
        assertTrue("failed to flip bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have flipped bit 219", bs.get(219));
    assertTrue("Shouldn't have flipped bit 220", bs.get(220));
    for (int i = 221; i < bs.size(); i++) {
        assertTrue("Shouldn't have flipped bit " + i, !bs.get(i));
    }
}

11. BitSetTest#andNot()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void andNot() {
    BitSet bs = (BitSet) eightbs.clone();
    bs.clear(5);
    BitSet bs2 = new BitSet();
    bs2.set(2);
    bs2.set(3);
    bs.andNot(bs2);
    assertEquals("Incorrect bitset after andNot", "{0, 1, 4, 6, 7}", bs.toString());
    bs = new BitSet(0);
    bs.andNot(bs2);
    assertEquals("Incorrect size", 0, bs.size());
}

12. BitSetConverterTest#testConvertsToSingleCommaDelimitedString()

Project: xstream
Source File: BitSetConverterTest.java
View license
public void testConvertsToSingleCommaDelimitedString() {
    BitSet bitSet = new BitSet();
    bitSet.set(0);
    bitSet.set(1);
    bitSet.set(3);
    bitSet.set(5);
    bitSet.set(6);
    bitSet.set(8);
    bitSet.set(10);
    String expected = "<bit-set>0,1,3,5,6,8,10</bit-set>";
    assertBothWays(bitSet, expected);
}

13. BitSetTest#test_getII()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_getII() {
    BitSet bitset = new BitSet(30);
    bitset.get(3, 3);
    BitSet bs, resultbs, correctbs;
    bs = new BitSet(512);
    bs.set(3, 9);
    bs.set(10, 20);
    bs.set(60, 75);
    bs.set(121);
    bs.set(130, 140);
    // pos1 and pos2 are in the same bitset element, at index0
    resultbs = bs.get(3, 6);
    correctbs = new BitSet(3);
    correctbs.set(0, 3);
    assertEquals("Test1: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 and pos2 are in the same bitset element, at index 1
    resultbs = bs.get(100, 125);
    correctbs = new BitSet(25);
    correctbs.set(21);
    assertEquals("Test2: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 0, and pos2 in bitset element at
    // index 1
    resultbs = bs.get(15, 125);
    correctbs = new BitSet(25);
    correctbs.set(0, 5);
    correctbs.set(45, 60);
    correctbs.set(121 - 15);
    assertEquals("Test3: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 1, and pos2 in bitset element at
    // index 2
    resultbs = bs.get(70, 145);
    correctbs = new BitSet(75);
    correctbs.set(0, 5);
    correctbs.set(51);
    correctbs.set(60, 70);
    assertEquals("Test4: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 0, and pos2 in bitset element at
    // index 2
    resultbs = bs.get(5, 145);
    correctbs = new BitSet(140);
    correctbs.set(0, 4);
    correctbs.set(5, 15);
    correctbs.set(55, 70);
    correctbs.set(116);
    correctbs.set(125, 135);
    assertEquals("Test5: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 0, and pos2 in bitset element at
    // index 3
    resultbs = bs.get(5, 250);
    correctbs = new BitSet(200);
    correctbs.set(0, 4);
    correctbs.set(5, 15);
    correctbs.set(55, 70);
    correctbs.set(116);
    correctbs.set(125, 135);
    assertEquals("Test6: Returned incorrect BitSet", correctbs, resultbs);
    assertEquals("equality principle 1 ", bs.get(0, bs.size()), bs);
    // more tests
    BitSet bs2 = new BitSet(129);
    bs2.set(0, 20);
    bs2.set(62, 65);
    bs2.set(121, 123);
    resultbs = bs2.get(1, 124);
    correctbs = new BitSet(129);
    correctbs.set(0, 19);
    correctbs.set(61, 64);
    correctbs.set(120, 122);
    assertEquals("Test7: Returned incorrect BitSet", correctbs, resultbs);
    // equality principle with some boundary conditions
    bs2 = new BitSet(128);
    bs2.set(2, 20);
    bs2.set(62);
    bs2.set(121, 123);
    bs2.set(127);
    resultbs = bs2.get(0, bs2.size());
    assertEquals("equality principle 2 ", resultbs, bs2);
    bs2 = new BitSet(128);
    bs2.set(2, 20);
    bs2.set(62);
    bs2.set(121, 123);
    bs2.set(127);
    bs2.flip(0, 128);
    resultbs = bs2.get(0, bs.size());
    assertEquals("equality principle 3 ", resultbs, bs2);
    bs = new BitSet(0);
    assertEquals("Test1: Wrong length,", 0, bs.length());
    assertEquals("Test1: Wrong size,", 0, bs.size());
    bs.get(0, 2);
    assertEquals("Test2: Wrong length,", 0, bs.length());
    assertEquals("Test2: Wrong size,", 0, bs.size());
    bs.get(60, 64);
    assertEquals("Test3: Wrong length,", 0, bs.length());
    assertEquals("Test3: Wrong size,", 0, bs.size());
    bs.get(64, 120);
    assertEquals("Test4: Wrong length,", 0, bs.length());
    assertEquals("Test4: Wrong size,", 0, bs.size());
    bs.set(25);
    assertEquals("Test5: Wrong length,", 26, bs.length());
    assertEquals("Test5: Wrong size,", 64, bs.size());
    bs.get(60, 64);
    assertEquals("Test6: Wrong length,", 26, bs.length());
    assertEquals("Test6: Wrong size,", 64, bs.size());
    bs.get(64, 120);
    assertEquals("Test7: Wrong size,", 64, bs.size());
    assertEquals("Test7: Wrong length,", 26, bs.length());
    bs.get(80);
    assertEquals("Test8: Wrong size,", 64, bs.size());
    assertEquals("Test8: Wrong length,", 26, bs.length());
    bs.get(25);
    assertEquals("Test9: Wrong size,", 64, bs.size());
    assertEquals("Test9: Wrong length,", 26, bs.length());
    try {
        bs2.get(-1, 0);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs2.get(bs2.size() / 2, 0);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs2.get(bs2.size() / 2, -1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
}

14. BitSetTest#test_xorLjava_util_BitSet()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_xorLjava_util_BitSet() {
    BitSet bs = (BitSet) eightbs.clone();
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR failed to clear bit " + i + bs, !bs.get(i));
    }
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR failed to set bit " + i + bs, bs.get(i));
    }
    bs = new BitSet(0);
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR(0) failed to set bit " + i + bs, bs.get(i));
    }
    bs = new BitSet();
    bs.set(63);
    assertEquals("{63}", bs.toString());
}

15. ISOUtilTest#testBitSetByteHexInteroperability()

Project: jPOS
Source File: ISOUtilTest.java
View license
@Test
public void testBitSetByteHexInteroperability() throws Throwable {
    BitSet bs = new BitSet();
    bs.set(1);
    bs.set(63);
    bs.set(127);
    bs.set(191);
    byte[] b = ISOUtil.bitSet2byte(bs);
    BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192);
    BitSet bs2 = ISOUtil.hex2BitSet(ISOUtil.hexString(b).getBytes(), 0, 192);
    assertEquals("BitSets should be equal", bs1, bs2);
}

16. BitSetTest#getII()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void getII() {
    BitSet bitset = new BitSet(30);
    bitset.get(3, 3);
    // Test for method boolean java.util.BitSet.get(int, int)
    BitSet bs, resultbs, correctbs;
    bs = new BitSet(512);
    bs.set(3, 9);
    bs.set(10, 20);
    bs.set(60, 75);
    bs.set(121);
    bs.set(130, 140);
    // pos1 and pos2 are in the same bitset element, at index0
    resultbs = bs.get(3, 6);
    correctbs = new BitSet(3);
    correctbs.set(0, 3);
    assertEquals("Test1: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 and pos2 are in the same bitset element, at index 1
    resultbs = bs.get(100, 125);
    correctbs = new BitSet(25);
    correctbs.set(21);
    assertEquals("Test2: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 0, and pos2 in bitset element at
    // index 1
    resultbs = bs.get(15, 125);
    correctbs = new BitSet(25);
    correctbs.set(0, 5);
    correctbs.set(45, 60);
    correctbs.set(121 - 15);
    assertEquals("Test3: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 1, and pos2 in bitset element at
    // index 2
    resultbs = bs.get(70, 145);
    correctbs = new BitSet(75);
    correctbs.set(0, 5);
    correctbs.set(51);
    correctbs.set(60, 70);
    assertEquals("Test4: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 0, and pos2 in bitset element at
    // index 2
    resultbs = bs.get(5, 145);
    correctbs = new BitSet(140);
    correctbs.set(0, 4);
    correctbs.set(5, 15);
    correctbs.set(55, 70);
    correctbs.set(116);
    correctbs.set(125, 135);
    assertEquals("Test5: Returned incorrect BitSet", correctbs, resultbs);
    // pos1 in bitset element at index 0, and pos2 in bitset element at
    // index 3
    resultbs = bs.get(5, 250);
    correctbs = new BitSet(200);
    correctbs.set(0, 4);
    correctbs.set(5, 15);
    correctbs.set(55, 70);
    correctbs.set(116);
    correctbs.set(125, 135);
    assertEquals("Test6: Returned incorrect BitSet", correctbs, resultbs);
    assertEquals("equality principle 1 ", bs.get(0, bs.size()), bs);
    // more tests
    BitSet bs2 = new BitSet(129);
    bs2.set(0, 20);
    bs2.set(62, 65);
    bs2.set(121, 123);
    resultbs = bs2.get(1, 124);
    correctbs = new BitSet(129);
    correctbs.set(0, 19);
    correctbs.set(61, 64);
    correctbs.set(120, 122);
    assertEquals("Test7: Returned incorrect BitSet", correctbs, resultbs);
    // equality principle with some boundary conditions
    bs2 = new BitSet(128);
    bs2.set(2, 20);
    bs2.set(62);
    bs2.set(121, 123);
    bs2.set(127);
    resultbs = bs2.get(0, bs2.size());
    assertEquals("equality principle 2 ", resultbs, bs2);
    bs2 = new BitSet(128);
    bs2.set(2, 20);
    bs2.set(62);
    bs2.set(121, 123);
    bs2.set(127);
    bs2.flip(0, 128);
    resultbs = bs2.get(0, bs.size());
    assertEquals("equality principle 3 ", resultbs, bs2);
    bs = new BitSet(0);
    assertEquals("Test1: Wrong length,", 0, bs.length());
    bs.get(0, 2);
    assertEquals("Test2: Wrong length,", 0, bs.length());
    bs.get(60, 64);
    assertEquals("Test3: Wrong length,", 0, bs.length());
    bs.get(64, 120);
    assertEquals("Test4: Wrong length,", 0, bs.length());
    bs.set(25);
    assertEquals("Test5: Wrong length,", 26, bs.length());
    bs.get(60, 64);
    assertEquals("Test6: Wrong length,", 26, bs.length());
    bs.get(64, 120);
    assertEquals("Test7: Wrong length,", 26, bs.length());
    bs.get(80);
    assertEquals("Test8: Wrong length,", 26, bs.length());
    bs.get(25);
    assertEquals("Test9: Wrong length,", 26, bs.length());
}

17. BitSetTest#xor()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void xor() {
    // Test for method void java.util.BitSet.xor(java.util.BitSet)
    BitSet bs = (BitSet) eightbs.clone();
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertFalse("XOR failed to clear bits", bs.get(i));
    }
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR failed to set bits", bs.get(i));
    }
    bs = new BitSet(0);
    bs.xor(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("XOR(0) failed to set bits", bs.get(i));
    }
    bs = new BitSet();
    bs.set(63);
    assertEquals("Test highest bit", "{63}", bs.toString());
}

18. HexUtilTest#testHexToBits()

Project: fred
Source File: HexUtilTest.java
View license
/**
	 * Tests hexToBits(String,BitSet,int) method
	 */
public void testHexToBits() {
    String methodStringToStore = "00";
    BitSet methodBitSet = new BitSet(8);
    HexUtil.hexToBits(methodStringToStore, methodBitSet, methodBitSet.size());
    assertTrue(methodBitSet.cardinality() == 0);
    BitSet expectedBitSet = new BitSet(8);
    expectedBitSet.set(0, 7, true);
    /*0x7f*/
    methodStringToStore = "7f";
    methodBitSet = new BitSet(8);
    HexUtil.hexToBits(methodStringToStore, methodBitSet, methodBitSet.size());
    assertTrue(methodBitSet.intersects(expectedBitSet));
    expectedBitSet.set(0, 9, true);
    /*0xff*/
    methodStringToStore = "ff";
    methodBitSet = new BitSet(8);
    HexUtil.hexToBits(methodStringToStore, methodBitSet, methodBitSet.size());
    assertTrue(methodBitSet.intersects(expectedBitSet));
}

19. BitSetTest#test_orLjava_util_BitSet()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_orLjava_util_BitSet() {
    BitSet bs = new BitSet(128);
    bs.or(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("OR failed to set bits", bs.get(i));
    }
    bs = new BitSet(0);
    bs.or(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("OR(0) failed to set bits", bs.get(i));
    }
    eightbs.clear(5);
    bs = new BitSet(128);
    bs.or(eightbs);
    assertTrue("OR set a bit which should be off", !bs.get(5));
}

20. BitKeyTest#testCreateFromBitSet()

Project: mondrian
Source File: BitKeyTest.java
View license
public void testCreateFromBitSet() {
    final BitSet bitSet = new BitSet(72);
    bitSet.set(2);
    bitSet.set(3);
    bitSet.set(5);
    bitSet.set(11);
    BitKey bitKey = BitKey.Factory.makeBitKey(bitSet);
    assertEquals("0x0000000000000000000000000000000000000000000000000000100000101100", bitKey.toString());
    final BitSet emptyBitSet = new BitSet(77);
    bitKey = BitKey.Factory.makeBitKey(emptyBitSet);
    assertTrue(bitKey.isEmpty());
}

21. BitSetTest#or()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void or() {
    // Test for method void java.util.BitSet.or(java.util.BitSet)
    BitSet bs = new BitSet(128);
    bs.or(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("OR failed to set bits", bs.get(i));
    }
    bs = new BitSet(0);
    bs.or(eightbs);
    for (int i = 0; i < 8; i++) {
        assertTrue("OR(0) failed to set bits", bs.get(i));
    }
    eightbs.clear(5);
    bs = new BitSet(128);
    bs.or(eightbs);
    assertFalse("OR set a bit which should be off", bs.get(5));
}

22. BitSetsTest#testToIterBitSet()

Project: calcite
Source File: BitSetsTest.java
View license
/**
   * Tests the method
   * {@link org.apache.calcite.util.BitSets#toIter(java.util.BitSet)}.
   */
@Test
public void testToIterBitSet() {
    BitSet bitSet = new BitSet();
    assertToIterBitSet("", bitSet);
    bitSet.set(0);
    assertToIterBitSet("0", bitSet);
    bitSet.set(1);
    assertToIterBitSet("0, 1", bitSet);
    bitSet.clear();
    bitSet.set(10);
    assertToIterBitSet("10", bitSet);
}

23. AndFilterExecuterImpl#applyFilter()

View license
@Override
public BitSet applyFilter(BlocksChunkHolder blockChunkHolder) throws FilterUnsupportedException {
    BitSet leftFilters = leftExecuter.applyFilter(blockChunkHolder);
    if (leftFilters.isEmpty()) {
        return leftFilters;
    }
    BitSet rightFilter = rightExecuter.applyFilter(blockChunkHolder);
    if (rightFilter.isEmpty()) {
        return rightFilter;
    }
    leftFilters.and(rightFilter);
    return leftFilters;
}

24. AndFilterExecuterImpl#isScanRequired()

View license
@Override
public BitSet isScanRequired(byte[][] blockMaxValue, byte[][] blockMinValue) {
    BitSet leftFilters = leftExecuter.isScanRequired(blockMaxValue, blockMinValue);
    if (leftFilters.isEmpty()) {
        return leftFilters;
    }
    BitSet rightFilter = rightExecuter.isScanRequired(blockMaxValue, blockMinValue);
    if (rightFilter.isEmpty()) {
        return rightFilter;
    }
    leftFilters.and(rightFilter);
    return leftFilters;
}

25. HierarchyEncoderImpl#singleBitDiff()

Project: drools
Source File: HierarchyEncoderImpl.java
View license
BitSet singleBitDiff(BitSet x, BitSet y) {
    BitSet t = new BitSet(x.length());
    t.or(x);
    t.flip(0, t.size());
    t.and(y);
    switch(t.cardinality()) {
        case 0:
            return t;
        case 1:
            return t;
        default:
            return new BitSet();
    }
}

26. AndFilterExecuterImpl#applyFilter()

View license
@Override
public BitSet applyFilter(BlocksChunkHolder blockChunkHolder) throws FilterUnsupportedException {
    BitSet leftFilters = leftExecuter.applyFilter(blockChunkHolder);
    if (leftFilters.isEmpty()) {
        return leftFilters;
    }
    BitSet rightFilter = rightExecuter.applyFilter(blockChunkHolder);
    if (rightFilter.isEmpty()) {
        return rightFilter;
    }
    leftFilters.and(rightFilter);
    return leftFilters;
}

27. AndFilterExecuterImpl#isScanRequired()

View license
@Override
public BitSet isScanRequired(byte[][] blockMaxValue, byte[][] blockMinValue) {
    BitSet leftFilters = leftExecuter.isScanRequired(blockMaxValue, blockMinValue);
    if (leftFilters.isEmpty()) {
        return leftFilters;
    }
    BitSet rightFilter = rightExecuter.isScanRequired(blockMaxValue, blockMinValue);
    if (rightFilter.isEmpty()) {
        return rightFilter;
    }
    leftFilters.and(rightFilter);
    return leftFilters;
}

28. BitSetTest#test_length()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_length() {
    BitSet bs = new BitSet();
    assertEquals(bs.toString(), 0, bs.length());
    bs.set(5);
    assertEquals(bs.toString(), 6, bs.length());
    bs.set(10);
    assertEquals(bs.toString(), 11, bs.length());
    bs.set(432);
    assertEquals(bs.toString(), 433, bs.length());
    bs.set(300);
    assertEquals(bs.toString(), 433, bs.length());
}

29. BlockUtils#getPathCross()

Project: jadx
Source File: BlockUtils.java
View license
public static BlockNode getPathCross(MethodNode mth, BlockNode b1, BlockNode b2) {
    if (b1 == null || b2 == null) {
        return null;
    }
    BitSet b = new BitSet();
    b.or(b1.getDomFrontier());
    b.and(b2.getDomFrontier());
    b.clear(b1.getId());
    b.clear(b2.getId());
    if (b.cardinality() == 1) {
        BlockNode end = mth.getBasicBlocks().get(b.nextSetBit(0));
        if (isPathExists(b1, end) && isPathExists(b2, end)) {
            return end;
        }
    }
    if (isPathExists(b1, b2)) {
        return b2;
    }
    if (isPathExists(b2, b1)) {
        return b1;
    }
    return null;
}

30. LinuxJNAAffinityTest#LinuxJNA()

View license
@Test
public void LinuxJNA() {
    int nbits = Runtime.getRuntime().availableProcessors();
    BitSet affinity0 = LinuxJNAAffinity.INSTANCE.getAffinity();
    System.out.println(affinity0);
    BitSet affinity = new BitSet(nbits);
    affinity.set(1);
    LinuxJNAAffinity.INSTANCE.setAffinity(affinity);
    BitSet affinity2 = LinuxJNAAffinity.INSTANCE.getAffinity();
    System.out.println(affinity2);
    assertEquals(1, LinuxJNAAffinity.INSTANCE.getCpu());
    assertEquals(affinity, affinity2);
    affinity.set(0, nbits);
    LinuxJNAAffinity.INSTANCE.setAffinity(affinity);
}

31. BitSetIteratorTest#testNonStartInitial()

Project: lenskit
Source File: BitSetIteratorTest.java
View license
@Test
public void testNonStartInitial() {
    BitSet bset = new BitSet();
    bset.set(1);
    bset.set(2);
    bset.set(4);
    bset.set(5);
    BitSetIterator iter = new BitSetIterator(bset, 0, 6, 2);
    // the iterator should have both next and previous bits
    assertTrue(iter.hasNext());
    assertTrue(iter.hasPrevious());
    // The iterator's 'next' bit should be 2
    assertThat(iter.nextInt(), equalTo(2));
    // followed by 4, of course
    assertThat(iter.nextInt(), equalTo(4));
    // reset, and back should get us 1
    iter = new BitSetIterator(bset, 0, 6, 2);
    assertThat(iter.previousInt(), equalTo(1));
    assertFalse(iter.hasPrevious());
}

32. BitSetIteratorTest#testNonStartInitialAtHole()

Project: lenskit
Source File: BitSetIteratorTest.java
View license
@Test
public void testNonStartInitialAtHole() {
    BitSet bset = new BitSet();
    bset.set(1);
    bset.set(2);
    bset.set(4);
    bset.set(5);
    BitSetIterator iter = new BitSetIterator(bset, 0, 6, 3);
    // the iterator should have both next and previous bits
    assertTrue(iter.hasNext());
    assertTrue(iter.hasPrevious());
    // The iterator's 'next' bit should be 4
    assertThat(iter.nextInt(), equalTo(4));
    // followed by 5, of course
    assertThat(iter.nextInt(), equalTo(5));
    assertFalse(iter.hasNext());
    // reset, and back should get us 2
    iter = new BitSetIterator(bset, 0, 6, 3);
    assertThat(iter.previousInt(), equalTo(2));
    assertThat(iter.previousInt(), equalTo(1));
    assertFalse(iter.hasPrevious());
}

33. CookieUtil#validCookieValueOctets()

Project: netty
Source File: CookieUtil.java
View license
// US-ASCII characters excluding CTLs, whitespace, DQUOTE, comma, semicolon, and backslash
private static BitSet validCookieValueOctets() {
    BitSet bits = new BitSet(8);
    for (int i = 35; i < 127; i++) {
        // US-ASCII characters excluding CTLs (%x00-1F / %x7F)
        bits.set(i);
    }
    // exclude DQUOTE = %x22
    bits.set('"', false);
    // exclude comma = %x2C
    bits.set(',', false);
    // exclude semicolon = %x3B
    bits.set(';', false);
    bits.set('\\', false);
    return bits;
}

34. BlockUtils#getPathCross()

Project: show-java
Source File: BlockUtils.java
View license
public static BlockNode getPathCross(MethodNode mth, BlockNode b1, BlockNode b2) {
    if (b1 == null || b2 == null) {
        return null;
    }
    BitSet b = new BitSet();
    b.or(b1.getDomFrontier());
    b.and(b2.getDomFrontier());
    b.clear(b1.getId());
    b.clear(b2.getId());
    if (b.cardinality() == 1) {
        BlockNode end = mth.getBasicBlocks().get(b.nextSetBit(0));
        if (isPathExists(b1, end) && isPathExists(b2, end)) {
            return end;
        }
    }
    if (isPathExists(b1, b2)) {
        return b2;
    }
    if (isPathExists(b2, b1)) {
        return b1;
    }
    return null;
}

35. BitSetTest#length()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void length() {
    BitSet bs = new BitSet();
    assertEquals("BitSet returned wrong length", 0, bs.length());
    bs.set(5);
    assertEquals("BitSet returned wrong length", 6, bs.length());
    bs.set(10);
    assertEquals("BitSet returned wrong length", 11, bs.length());
    bs.set(432);
    assertEquals("BitSet returned wrong length", 433, bs.length());
    bs.set(300);
    assertEquals("BitSet returned wrong length", 433, bs.length());
}

36. BitSetTest#previousSetBitFound()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void previousSetBitFound() {
    BitSet bs = new BitSet();
    bs.set(2, 10);
    bs.set(16, 19);
    bs.set(31, 64);
    bs.set(96, 98);
    assertEquals(97, bs.previousSetBit(100));
    assertEquals(97, bs.previousSetBit(97));
    assertEquals(96, bs.previousSetBit(96));
    assertEquals(63, bs.previousSetBit(95));
    assertEquals(63, bs.previousSetBit(63));
    assertEquals(62, bs.previousSetBit(62));
    assertEquals(32, bs.previousSetBit(32));
    assertEquals(31, bs.previousSetBit(31));
    assertEquals(18, bs.previousSetBit(30));
    assertEquals(18, bs.previousSetBit(18));
    assertEquals(17, bs.previousSetBit(17));
    assertEquals(16, bs.previousSetBit(16));
    assertEquals(9, bs.previousSetBit(15));
    assertEquals(9, bs.previousSetBit(9));
    assertEquals(2, bs.previousSetBit(2));
    assertEquals(-1, bs.previousSetBit(1));
    assertEquals(-1, bs.previousSetBit(0));
}

37. BitSetTest#previousClearBitFound()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void previousClearBitFound() {
    BitSet bs = new BitSet();
    bs.set(0, 10);
    bs.set(16, 19);
    bs.set(31, 64);
    bs.set(96, 98);
    assertEquals(100, bs.previousClearBit(100));
    assertEquals(98, bs.previousClearBit(98));
    assertEquals(95, bs.previousClearBit(97));
    assertEquals(95, bs.previousClearBit(95));
    assertEquals(64, bs.previousClearBit(64));
    assertEquals(30, bs.previousClearBit(63));
    assertEquals(30, bs.previousClearBit(32));
    assertEquals(30, bs.previousClearBit(31));
    assertEquals(30, bs.previousClearBit(30));
    assertEquals(29, bs.previousClearBit(29));
    assertEquals(20, bs.previousClearBit(20));
    assertEquals(19, bs.previousClearBit(19));
    assertEquals(15, bs.previousClearBit(17));
    assertEquals(15, bs.previousClearBit(15));
    assertEquals(-1, bs.previousClearBit(9));
    assertEquals(-1, bs.previousClearBit(1));
    assertEquals(-1, bs.previousClearBit(0));
}

38. MultiByteFont#getGlyphIndices()

Project: fop
Source File: MultiByteFont.java
View license
protected BitSet getGlyphIndices() {
    BitSet bitset = new BitSet();
    bitset.set(0);
    bitset.set(1);
    bitset.set(2);
    for (CMapSegment i : cmap) {
        int start = i.getUnicodeStart();
        int end = i.getUnicodeEnd();
        int glyphIndex = i.getGlyphStartIndex();
        while (start++ < end + 1) {
            bitset.set(glyphIndex++);
        }
    }
    return bitset;
}

39. BitSetTest#test_toLongArray()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_toLongArray() throws Exception {
    assertEquals("[]", Arrays.toString(BitSet.valueOf(new long[0]).toLongArray()));
    assertEquals("[1]", Arrays.toString(BitSet.valueOf(new long[] { 1 }).toLongArray()));
    assertEquals("[1, 2]", Arrays.toString(BitSet.valueOf(new long[] { 1, 2 }).toLongArray()));
    // Check that we're not returning trailing empty space.
    assertEquals("[]", Arrays.toString(new BitSet(128).toLongArray()));
    BitSet bs = new BitSet();
    bs.set(0);
    bs.set(64, 66);
    bs.clear(64, 66);
    assertEquals("[1]", Arrays.toString(bs.toLongArray()));
}

40. BitSetTest#test_equalsLjava_lang_Object()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_equalsLjava_lang_Object() {
    BitSet bs;
    bs = (BitSet) eightbs.clone();
    assertTrue("Same BitSet returned false", eightbs.equals(eightbs));
    assertTrue("Identical BitSets returned false", eightbs.equals(bs));
    bs.clear(6);
    assertTrue("Different BitSets returned true", !eightbs.equals(bs));
    // Grow the BitSet
    bs = (BitSet) eightbs.clone();
    bs.set(128);
    assertFalse(eightbs.equals(bs));
    bs.clear(128);
    assertTrue(eightbs.equals(bs));
}

41. BitSetTest#test_clear()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_clear() {
    eightbs.clear();
    for (int i = 0; i < 8; i++) {
        assertTrue("Clear didn't clear bit " + i, !eightbs.get(i));
    }
    assertEquals("Test1: Wrong length", 0, eightbs.length());
    BitSet bs = new BitSet(3400);
    // ensure all bits are 1's
    bs.set(0, bs.size() - 1);
    bs.set(bs.size() - 1);
    bs.clear();
    assertEquals(0, bs.length());
    assertTrue(bs.isEmpty());
    assertEquals(0, bs.cardinality());
}

42. BitSetTest#test_intersectsLjava_util_BitSet()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_intersectsLjava_util_BitSet() {
    BitSet bs = new BitSet(500);
    bs.set(5);
    bs.set(63);
    bs.set(64);
    bs.set(71, 110);
    bs.set(127, 130);
    bs.set(192);
    bs.set(450);
    BitSet bs2 = new BitSet(8);
    assertFalse("Test1: intersects() returned incorrect value", bs.intersects(bs2));
    assertFalse("Test1: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.set(4);
    assertFalse("Test2: intersects() returned incorrect value", bs.intersects(bs2));
    assertFalse("Test2: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(5);
    assertTrue("Test3: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test3: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(63);
    assertTrue("Test4: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test4: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(80);
    assertTrue("Test5: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test5: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(127);
    assertTrue("Test6: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test6: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(192);
    assertTrue("Test7: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test7: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(450);
    assertTrue("Test8: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test8: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(500);
    assertFalse("Test9: intersects() returned incorrect value", bs.intersects(bs2));
    assertFalse("Test9: intersects() returned incorrect value", bs2.intersects(bs));
}

43. BitSetIteratorTest#testStartEndOffset2()

Project: lenskit
Source File: BitSetIteratorTest.java
View license
@Test
public void testStartEndOffset2() {
    BitSet s = new BitSet();
    s.set(5);
    s.set(7);
    s.set(9);
    BitSetIterator iter = new BitSetIterator(s, 6, 8);
    assertArrayEquals(new Integer[] { 7 }, Iterators.toArray(new BitSetIterator(s, 6, 8), Integer.class));
    iter = new BitSetIterator(s, 6, 8);
    assertFalse(iter.hasPrevious());
    assertTrue(iter.hasNext());
    iter.nextInt();
    assertFalse(iter.hasNext());
    assertTrue(iter.hasPrevious());
}

44. Similarity#jaccardIndex()

Project: S-Space
Source File: Similarity.java
View license
/**
     * Computes the <a href="http://en.wikipedia.org/wiki/Jaccard_index">Jaccard
     * index</a> comparing the similarity both arrays when viewed as sets of
     * samples.
     */
public static double jaccardIndex(int[] a, int[] b) {
    // The BitSets should be faster than a HashMap since it's back by an
    // array and operations are just logical bit operations and require no
    // auto-boxing.  However, if a or b contains large values, then the cost
    // of creating the necessary size for the BitSet may outweigh its
    // performance.  At some point, it would be useful to profile the two
    // methods and their associated worst cases. -jurgens
    BitSet c = new BitSet();
    BitSet d = new BitSet();
    BitSet union = new BitSet();
    for (int i : a) {
        c.set(i);
        union.set(i);
    }
    for (int i : b) {
        d.set(i);
        union.set(i);
    }
    // get the intersection
    c.and(d);
    return ((double) (c.cardinality())) / union.cardinality();
}

45. BitSetTest#equalityComputed()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void equalityComputed() {
    BitSet bs;
    bs = (BitSet) eightbs.clone();
    assertEquals("Same BitSet returned false", eightbs, eightbs);
    assertEquals("Identical BitSet returned false", bs, eightbs);
    bs.clear(6);
    assertFalse("Different BitSets returned true", eightbs.equals(bs));
    bs = (BitSet) eightbs.clone();
    bs.set(128);
    assertFalse("Different sized BitSet with higher bit set returned true", eightbs.equals(bs));
    bs.clear(128);
    assertTrue("Different sized BitSet with higher bits not set returned false", eightbs.equals(bs));
}

46. BitSetTest#clear()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void clear() {
    eightbs.clear();
    for (int i = 0; i < 8; i++) {
        assertFalse("Clear didn't clear bit " + i, eightbs.get(i));
    }
    assertEquals("Test1: Wrong length", 0, eightbs.length());
    BitSet bs = new BitSet(3400);
    // ensure all bits are 1's
    bs.set(0, bs.size() - 1);
    bs.set(bs.size() - 1);
    bs.clear();
    assertEquals("Test2: Wrong length", 0, bs.length());
    assertTrue("Test2: isEmpty() returned incorrect value", bs.isEmpty());
    assertEquals("Test2: cardinality() returned incorrect value", 0, bs.cardinality());
}

47. BitSetTest#intersects()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void intersects() {
    // Test for method boolean java.util.BitSet.intersects(java.util.BitSet)
    BitSet bs = new BitSet(500);
    bs.set(5);
    bs.set(63);
    bs.set(64);
    bs.set(71, 110);
    bs.set(127, 130);
    bs.set(192);
    bs.set(450);
    BitSet bs2 = new BitSet(8);
    assertFalse("Test1: intersects() returned incorrect value", bs.intersects(bs2));
    assertFalse("Test1: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.set(4);
    assertFalse("Test2: intersects() returned incorrect value", bs.intersects(bs2));
    assertFalse("Test2: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(5);
    assertTrue("Test3: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test3: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(63);
    assertTrue("Test4: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test4: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(80);
    assertTrue("Test5: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test5: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(127);
    assertTrue("Test6: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test6: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(192);
    assertTrue("Test7: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test7: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(450);
    assertTrue("Test8: intersects() returned incorrect value", bs.intersects(bs2));
    assertTrue("Test8: intersects() returned incorrect value", bs2.intersects(bs));
    bs2.clear();
    bs2.set(500);
    assertFalse("Test9: intersects() returned incorrect value", bs.intersects(bs2));
    assertFalse("Test9: intersects() returned incorrect value", bs2.intersects(bs));
}

48. FilterSplitTest#twoLevelDir()

Project: drill
Source File: FilterSplitTest.java
View license
@Test
public void twoLevelDir() {
    // (dir0 = 1 and dir1 = 2) OR (dir0 = 3 and dir1 = 4)
    RexNode n = or(and(eq(c(1), lit(1)), eq(c(2), lit(2))), and(eq(c(1), lit(3)), eq(c(2), lit(4))));
    BitSet bs = new BitSet();
    bs.set(1);
    bs.set(2);
    FindPartitionConditions c = new FindPartitionConditions(bs, builder);
    c.analyze(n);
    RexNode partNode = c.getFinalCondition();
    assertEquals("OR(AND(=($1, 1), =($2, 2)), AND(=($1, 3), =($2, 4)))", n.toString());
    assertEquals("OR(AND(=($1, 1), =($2, 2)), AND(=($1, 3), =($2, 4)))", partNode.toString());
}

49. FilterSplitTest#badOr()

Project: drill
Source File: FilterSplitTest.java
View license
@Test
public void badOr() {
    // (dir0 = 1 and dir1 = 2) OR (a < 5)
    RexNode n = or(and(eq(c(1), lit(1)), eq(c(2), lit(2))), lt(c(0), lit(5)));
    BitSet bs = new BitSet();
    bs.set(1);
    bs.set(2);
    FindPartitionConditions c = new FindPartitionConditions(bs, builder);
    c.analyze(n);
    RexNode partNode = c.getFinalCondition();
    assertEquals("OR(AND(=($1, 1), =($2, 2)), <($0, 5))", n.toString());
    assertTrue(partNode == null);
}

50. FilterSplitTest#badFunc()

Project: drill
Source File: FilterSplitTest.java
View license
@Test
public void badFunc() {
    // (dir0 = 1 and dir1 = 2) OR (a < 5)
    RexNode n = fn(cs(0), cs(1));
    BitSet bs = new BitSet();
    bs.set(1);
    bs.set(2);
    FindPartitionConditions c = new FindPartitionConditions(bs, builder);
    c.analyze(n);
    RexNode partNode = c.getFinalCondition();
    assertEquals("||($0, $1)", n.toString());
    assertTrue(partNode == null);
}

51. SingleClassHierarchy#calcCoveredFiles()

View license
@NotNull
private BitSet calcCoveredFiles(ClassSymbol[] classSymbols) {
    BitSet problematicFiles = new BitSet();
    BitSet coveredFiles = new BitSet();
    for (ClassSymbol symbol : classSymbols) {
        int fileId = myClassAnchors.getFileId(symbol.myAnchorId);
        coveredFiles.set(fileId);
        if (symbol.isHierarchyIncomplete()) {
            problematicFiles.set(fileId);
        }
    }
    coveredFiles.andNot(problematicFiles);
    return coveredFiles;
}

52. BitSetTest#test_andLjava_util_BitSet()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_andLjava_util_BitSet() {
    BitSet bs = new BitSet(128);
    // Initialize the bottom half of the BitSet
    for (int i = 64; i < 128; i++) {
        bs.set(i);
    }
    eightbs.and(bs);
    assertTrue("AND failed to clear bits", !eightbs.equals(bs));
    eightbs.set(3);
    bs.set(3);
    eightbs.and(bs);
    assertTrue("AND failed to maintain set bits", bs.get(3));
    bs.and(eightbs);
    for (int i = 64; i < 128; i++) {
        assertTrue("Failed to clear extra bits in the receiver BitSet", !bs.get(i));
    }
}

53. ISOUtilTest#testBitSet2byte()

Project: jPOS
Source File: ISOUtilTest.java
View license
@Test
public void testBitSet2byte() throws Throwable {
    byte[] b = new byte[1];
    BitSet bmap = new BitSet();
    ISOUtil.hex2BitSet(bmap, b, 0);
    byte[] b2 = new byte[0];
    ISOUtil.hex2BitSet(bmap, b2, -1);
    BitSet b3 = new BitSet(100);
    b3.or(bmap);
    byte[] result = ISOUtil.bitSet2byte(b3);
    assertEquals("result.length", 8, result.length);
    assertEquals("result[0]", (byte) -16, result[0]);
}

54. ISOUtilTest#testBitSet2String()

Project: jPOS
Source File: ISOUtilTest.java
View license
@Test
public void testBitSet2String() throws Throwable {
    BitSet bmap = new BitSet(100);
    byte[] b = new byte[1];
    ISOUtil.byte2BitSet(bmap, b, 100);
    bmap.set(100);
    bmap.flip(0, 100);
    String result = ISOUtil.bitSet2String(bmap);
    assertEquals("result", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000", result);
}

55. BitSetIteratorTest#testStartOffset()

Project: lenskit
Source File: BitSetIteratorTest.java
View license
@Test
public void testStartOffset() {
    BitSet s = new BitSet();
    s.set(2);
    s.set(5);
    BitSetIterator iter = new BitSetIterator(s, 2);
    assertArrayEquals(new Integer[] { 2, 5 }, Iterators.toArray(iter, Integer.class));
    iter = new BitSetIterator(s, 3);
    assertArrayEquals(new Integer[] { 5 }, Iterators.toArray(iter, Integer.class));
}

56. RedisBitSetTest#testBitSetStoredCorrectly()

View license
@Test
public void testBitSetStoredCorrectly() {
    final int length = 20;
    final BitSet primes = new BitSet(length);
    primes.flip(2, length);
    for (int i = 0; i < length; i++) {
        if (primes.get(i)) {
            for (int j = i * 2; j < length; j += i) {
                primes.set(j, false);
            }
        }
    }
    RedisPool pool = Helper.getPool();
    RedisBitSet bs = new RedisBitSet(pool, "test", primes.size());
    bs.overwriteBitSet(primes);
    BitSet read = bs.asBitSet();
    assertEquals(primes, read);
    assertEquals(primes, read);
}

57. SearchingContextTest#intersectionDetectsBecomingEmpty()

View license
@Test
public void intersectionDetectsBecomingEmpty() {
    SearchingContext ctx = new SearchingContext();
    ctx.init(4);
    BitSet set = ctx.getWorkingSet();
    set.set(1);
    set.set(2);
    ctx.intersect(set, false);
    assertFalse(ctx.isEmpty());
    set = ctx.getWorkingSet();
    ctx.intersect(set, false);
    assertTrue(ctx.isEmpty());
}

58. terminal_set#is_subset_of()

Project: pluotsorbet
Source File: terminal_set.java
View license
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Determine if this set is an (improper) subset of another.
   * @param other the set we are testing against.
   */
public boolean is_subset_of(terminal_set other) throws internal_error {
    not_null(other);
    /* make a copy of the other set */
    BitSet copy_other = (BitSet) other._elements.clone();
    /* and or in */
    copy_other.or(_elements);
    /* if it hasn't changed, we were a subset */
    return copy_other.equals(other._elements);
}

59. TestOrcFileRewriter#testRewriteAllRowsDeleted()

Project: presto
Source File: TestOrcFileRewriter.java
View license
@Test
public void testRewriteAllRowsDeleted() throws Exception {
    List<Long> columnIds = ImmutableList.of(3L);
    List<Type> columnTypes = ImmutableList.of(BIGINT);
    File file = new File(temporary, randomUUID().toString());
    try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) {
        writer.appendPages(rowPagesBuilder(columnTypes).row(123L).row(456L).build());
    }
    BitSet rowsToDelete = new BitSet();
    rowsToDelete.set(0);
    rowsToDelete.set(1);
    File newFile = new File(temporary, randomUUID().toString());
    OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, rowsToDelete);
    assertEquals(info.getRowCount(), 0);
    assertEquals(info.getUncompressedSize(), 0);
    assertFalse(newFile.exists());
}

60. RedissonBitSetReactiveTest#testSet()

View license
@Test
public void testSet() {
    RBitSetReactive bs = redisson.getBitSet("testbitset");
    sync(bs.set(3));
    sync(bs.set(5));
    Assert.assertEquals("{3, 5}", bs.toString());
    BitSet bs1 = new BitSet();
    bs1.set(1);
    bs1.set(10);
    sync(bs.set(bs1));
    bs = redisson.getBitSet("testbitset");
    Assert.assertEquals("{1, 10}", bs.toString());
}

61. RedissonBitSetTest#testSet()

Project: redisson
Source File: RedissonBitSetTest.java
View license
@Test
public void testSet() {
    RBitSet bs = redisson.getBitSet("testbitset");
    bs.set(3);
    bs.set(5);
    assertThat(bs.toString()).isEqualTo("{3, 5}");
    BitSet bs1 = new BitSet();
    bs1.set(1);
    bs1.set(10);
    bs.set(bs1);
    bs = redisson.getBitSet("testbitset");
    assertThat(bs.toString()).isEqualTo("{1, 10}");
}

62. TestRange#setTestSinglePonits()

Project: RoaringBitmap
Source File: TestRange.java
View license
@Test
public void setTestSinglePonits() {
    final MutableRoaringBitmap rb = new MutableRoaringBitmap();
    rb.add(500L, 501L);
    rb.add(65536L, 65537L);
    final int rbcard = rb.getCardinality();
    assertEquals(2, rbcard);
    BitSet bs = new BitSet();
    bs.set(500);
    bs.set(65536);
    assertTrue(TestRoaringBitmap.equals(bs, rb));
}

63. TestRange#setTestSinglePonitsA()

Project: RoaringBitmap
Source File: TestRange.java
View license
@Test
public void setTestSinglePonitsA() {
    final MutableRoaringBitmap rb = new MutableRoaringBitmap();
    final MutableRoaringBitmap rb1 = MutableRoaringBitmap.add(rb, 500L, 501L);
    final MutableRoaringBitmap rb2 = MutableRoaringBitmap.add(rb1, 65536L, 65537L);
    final int rbcard = rb2.getCardinality();
    assertEquals(2, rbcard);
    BitSet bs = new BitSet();
    bs.set(500);
    bs.set(65536);
    assertTrue(TestRoaringBitmap.equals(bs, rb2));
}

64. TestRange#setTestSinglePonits()

Project: RoaringBitmap
Source File: TestRange.java
View license
@Test
public void setTestSinglePonits() {
    final RoaringBitmap rb = new RoaringBitmap();
    rb.add(500L, 501L);
    rb.add(65536L, 65537L);
    final int rbcard = rb.getCardinality();
    assertEquals(2, rbcard);
    BitSet bs = new BitSet();
    bs.set(500);
    bs.set(65536);
    assertTrue(TestRoaringBitmap.equals(bs, rb));
}

65. TestRange#setTestSinglePonitsA()

Project: RoaringBitmap
Source File: TestRange.java
View license
@Test
public void setTestSinglePonitsA() {
    final RoaringBitmap rb = new RoaringBitmap();
    final RoaringBitmap rb1 = RoaringBitmap.add(rb, 500L, 501L);
    final RoaringBitmap rb2 = RoaringBitmap.add(rb1, 65536L, 65537L);
    final int rbcard = rb2.getCardinality();
    assertEquals(2, rbcard);
    BitSet bs = new BitSet();
    bs.set(500);
    bs.set(65536);
    assertTrue(TestRoaringBitmap.equals(bs, rb2));
}

66. BitSetTest#and()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void and() {
    // Test for method void java.util.BitSet.and(java.util.BitSet)
    BitSet bs = new BitSet(128);
    for (int i = 64; i < 128; i++) bs.set(i);
    eightbs.and(bs);
    assertFalse("AND failed to clear bits", eightbs.equals(bs));
    eightbs.set(3);
    bs.set(3);
    eightbs.and(bs);
    assertTrue("AND failed to maintain set bits", bs.get(3));
    bs.and(eightbs);
    for (int i = 64; i < 128; i++) {
        assertFalse("Failed to clear extra bits in the receiver BitSet", bs.get(i));
    }
}

67. CookieUtil#validCookieValueOctets()

Project: async-http-client
Source File: CookieUtil.java
View license
private static BitSet validCookieValueOctets() {
    BitSet bits = new BitSet();
    bits.set(0x21);
    for (int i = 0x23; i <= 0x2B; i++) {
        bits.set(i);
    }
    for (int i = 0x2D; i <= 0x3A; i++) {
        bits.set(i);
    }
    for (int i = 0x3C; i <= 0x5B; i++) {
        bits.set(i);
    }
    for (int i = 0x5D; i <= 0x7E; i++) {
        bits.set(i);
    }
    return bits;
}

68. ExcludeColGroupFilterExecuterImpl#getFilteredIndexes()

View license
/**
   * It fills BitSet with row index which matches filter key
   */
protected BitSet getFilteredIndexes(DimensionColumnDataChunk dimensionColumnDataChunk, int numerOfRows) {
    BitSet bitSet = new BitSet(numerOfRows);
    bitSet.flip(0, numerOfRows);
    try {
        KeyStructureInfo keyStructureInfo = getKeyStructureInfo();
        byte[][] filterValues = dimColumnExecuterInfo.getFilterKeys();
        for (int i = 0; i < filterValues.length; i++) {
            byte[] filterVal = filterValues[i];
            for (int rowId = 0; rowId < numerOfRows; rowId++) {
                byte[] colData = new byte[keyStructureInfo.getMaskByteRanges().length];
                dimensionColumnDataChunk.fillChunkData(colData, 0, rowId, keyStructureInfo);
                if (ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterVal, colData) == 0) {
                    bitSet.flip(rowId);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error(e);
    }
    return bitSet;
}

69. PropAtLeastNValues_AC#isEntailed()

View license
//***********************************************************************************
// INFO
//***********************************************************************************
@Override
public ESat isEntailed() {
    BitSet values = new BitSet(n2);
    BitSet mandatoryValues = new BitSet(n2);
    IntVar v;
    int ub;
    for (int i = 0; i < n; i++) {
        v = vars[i];
        ub = v.getUB();
        if (v.isInstantiated()) {
            mandatoryValues.set(map.get(ub));
        }
        for (int j = v.getLB(); j <= ub; j++) {
            values.set(map.get(j));
        }
    }
    if (mandatoryValues.cardinality() >= vars[n].getUB()) {
        return ESat.TRUE;
    }
    if (values.cardinality() < vars[n].getLB()) {
        return ESat.FALSE;
    }
    return ESat.UNDEFINED;
}

70. LiveVariablesAnalysis#flowThrough()

View license
@Override
LiveVariableLattice flowThrough(Node node, LiveVariableLattice input) {
    final BitSet gen = new BitSet(input.liveSet.size());
    final BitSet kill = new BitSet(input.liveSet.size());
    // Make kills conditional if the node can end abruptly by an exception.
    boolean conditional = false;
    List<DiGraphEdge<Node, Branch>> edgeList = getCfg().getOutEdges(node);
    for (DiGraphEdge<Node, Branch> edge : edgeList) {
        if (Branch.ON_EX.equals(edge.getValue())) {
            conditional = true;
        }
    }
    computeGenKill(node, gen, kill, conditional);
    LiveVariableLattice result = new LiveVariableLattice(input);
    // L_in = L_out - Kill + Gen
    result.liveSet.andNot(kill);
    result.liveSet.or(gen);
    return result;
}

71. HashSetvBitSetTest#testTimesExtractOrBitset()

View license
@Test
public void testTimesExtractOrBitset() {
    final BitSet toRemove = new BitSet();
    final int[] array = new int[100];
    toRemove.set(10, 20);
    // warmup
    timeBitSetRemoveAll(array, toRemove);
    // warmup
    timeExtractRemoveAll(array, toRemove);
    long timeDiff = printTimes(100, 1);
    timeDiff += printTimes(100, 10);
    timeDiff += printTimes(100, 50);
    timeDiff += printTimes(100, 100);
    timeDiff += printTimes(1000, 10);
    timeDiff += printTimes(1000, 100);
    timeDiff += printTimes(1000, 500);
    timeDiff += printTimes(1000, 1000);
    Assert.assertTrue(timeDiff <= 0);
}

72. FilterSplitTest#simpleCompound()

Project: drill
Source File: FilterSplitTest.java
View license
@Test
public void simpleCompound() {
    // a < 1 AND dir0 in (2,3)
    RexNode n = and(lt(c(0), lit(1)), or(eq(c(1), lit(2)), eq(c(1), lit(3))));
    BitSet bs = new BitSet();
    bs.set(1);
    FindPartitionConditions c = new FindPartitionConditions(bs, builder);
    c.analyze(n);
    RexNode partNode = c.getFinalCondition();
    assertEquals(n.toString(), "AND(<($0, 1), OR(=($1, 2), =($1, 3)))");
    assertEquals(partNode.toString(), "OR(=($1, 2), =($1, 3))");
}

73. AbstractBitwiseHierarchyImpl#joinCode()

View license
public BitSet joinCode(Collection<BitSet> codes) {
    BitSet x = new BitSet(this.size());
    boolean first = true;
    for (BitSet code : codes) {
        if (first) {
            first = false;
            x.or(code);
        } else {
            x.and(code);
        }
    }
    return x;
}

74. AbstractBitwiseHierarchyImpl#prevKey()

View license
BitSet prevKey(BitSet key) {
    BitSet b = new BitSet(key.length());
    b.or(key);
    int x = key.nextSetBit(0);
    if (x == 0) {
        b.clear(0);
    } else {
        b.set(0, x, true);
        b.clear(x);
    }
    return b;
}

75. AbstractBitwiseHierarchyImpl#nextKey()

View license
BitSet nextKey(BitSet key) {
    int l = key.length();
    if (l == 0) {
        BitSet b = new BitSet(1);
        b.set(0);
        return b;
    }
    BitSet b = new BitSet(l + 1);
    b.or(key);
    int x = key.nextSetBit(0);
    if (x == 0) {
        int y = b.nextClearBit(0);
        b.set(x, y, false);
        b.set(y);
    } else {
        b.set(0);
    }
    return b;
}

76. AbstractBitwiseHierarchyImpl#supersetOrEqualset()

View license
public static boolean supersetOrEqualset(BitSet n1, BitSet n2) {
    BitSet x;
    int l1 = n1.length();
    int l2 = n2.length();
    if (l1 > l2) {
        x = new BitSet(l2);
        x.or(n2);
        x.and(n1);
    } else {
        x = new BitSet(l1);
        x.or(n1);
        x.and(n2);
    }
    return x.equals(n2);
}

77. HierarchyEncoderImpl#gcs()

Project: drools
Source File: HierarchyEncoderImpl.java
View license
protected Set<HierNode<T>> gcs(Set<HierNode<T>> set) {
    Set<HierNode<T>> s = new HashSet<HierNode<T>>();
    Iterator<HierNode<T>> iter = set.iterator();
    BitSet a = new BitSet(this.size());
    a.or(iter.next().getBitMask());
    while (iter.hasNext()) {
        a.and(iter.next().getBitMask());
    }
    //System.out.println( "Root mask for ceil " + toBinaryString( a ) );
    for (HierNode<T> node : getNodes()) {
        if (superset(node.getBitMask(), a) >= 0) {
            s.add(node);
        }
    }
    Set<HierNode<T>> cl = ceil(s);
    return cl;
}

78. ArabicJoinersTestCase#testZWJ()

Project: fop
Source File: ArabicJoinersTestCase.java
View license
private void testZWJ(GlyphContextTester gct, String script, String language, String feature, int flags, String[] test) {
    assert test.length == 2;
    String str = test[0];
    BitSet act = new BitSet();
    GlyphSequence gs = makeGlyphSequence(str);
    for (int i = 0, n = str.length(); i < n; ++i) {
        if (gct.test(script, language, feature, gs, i, flags)) {
            act.set(i);
        }
    }
    BitSet exp = parseBitSet(test[1]);
    assertTrue(act.equals(exp));
}

79. ExcludeColGroupFilterExecuterImpl#getFilteredIndexes()

View license
/**
   * It fills BitSet with row index which matches filter key
   */
protected BitSet getFilteredIndexes(DimensionColumnDataChunk dimensionColumnDataChunk, int numerOfRows) {
    BitSet bitSet = new BitSet(numerOfRows);
    bitSet.flip(0, numerOfRows);
    try {
        KeyStructureInfo keyStructureInfo = getKeyStructureInfo();
        byte[][] filterValues = dimColumnExecuterInfo.getFilterKeys();
        for (int i = 0; i < filterValues.length; i++) {
            byte[] filterVal = filterValues[i];
            for (int rowId = 0; rowId < numerOfRows; rowId++) {
                byte[] colData = new byte[keyStructureInfo.getMaskByteRanges().length];
                dimensionColumnDataChunk.fillChunkData(colData, 0, rowId, keyStructureInfo);
                if (ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterVal, colData) == 0) {
                    bitSet.flip(rowId);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error(e);
    }
    return bitSet;
}

80. BitSetTest#test_ConstructorI()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_ConstructorI() {
    BitSet bs = new BitSet(128);
    // Default size for a BitSet should be 64 elements;
    assertEquals("Created BitSet of incorrect size", 128, bs.size());
    assertTrue("New BitSet had invalid string representation: " + bs.toString(), bs.toString().equals("{}"));
    // All BitSets are created with elements of multiples of 64
    bs = new BitSet(89);
    assertEquals("Failed to round BitSet element size", 128, bs.size());
    try {
        bs = new BitSet(-9);
        fail();
    } catch (NegativeArraySizeException expected) {
    }
}

81. BitSetTest#test_setII()

Project: j2objc
Source File: BitSetTest.java
View license
public void test_setII() {
    BitSet bitset = new BitSet(30);
    bitset.set(29, 29);
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    bs.set(5);
    bs.set(15);
    bs.set(7, 11);
    assertEquals("{5, 7, 8, 9, 10, 15}", bs.toString());
    for (int i = 16; i < bs.size(); i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    bs.set(7, 64);
    assertEquals("Failed to grow BitSet", 64, bs.size());
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    for (int i = 7; i < 64; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 64", bs.get(64));
    // more boundary testing
    bs = new BitSet(32);
    bs.set(0, 64);
    for (int i = 0; i < 64; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 64", bs.get(64));
    bs = new BitSet(32);
    bs.set(0, 65);
    for (int i = 0; i < 65; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 65", bs.get(65));
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    bs.set(7);
    bs.set(110);
    bs.set(9, 74);
    for (int i = 0; i < 9; i++) {
        if (i == 7) {
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
        }
    }
    for (int i = 9; i < 74; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    for (int i = 74; i < bs.size(); i++) {
        if (i == 110) {
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        } else {
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
        }
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(7);
    bs.set(255);
    bs.set(9, 219);
    for (int i = 0; i < 9; i++) {
        if (i == 7) {
            assertTrue("Shouldn't have set flipped " + i, bs.get(i));
        } else {
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
        }
    }
    for (int i = 9; i < 219; i++) {
        assertTrue("failed to set bit " + i, bs.get(i));
    }
    for (int i = 219; i < 255; i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 255", bs.get(255));
    // test illegal args
    bs = new BitSet(10);
    try {
        bs.set(-1, 3);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.set(2, -1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    bs.set(2, 2);
    assertFalse("Bit got set incorrectly ", bs.get(2));
    try {
        bs.set(4, 2);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
}

82. Basic8#doGet()

Project: JAADAS
Source File: Basic8.java
View license
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String str = req.getParameter("name");
    BitSet bs = new BitSet(10);
    if (bs.get(0)) {
        if (bs.get(1)) {
            if (bs.get(2)) {
                if (bs.get(3)) {
                    if (bs.get(4)) {
                    }
                } else {
                    PrintWriter writer = resp.getWriter();
                    writer.println(str);
                /* BAD */
                }
            }
        }
    }
}

83. DTD#defElement()

Project: jdk7u-jdk
Source File: DTD.java
View license
/**
     * Creates and returns an <code>Element</code>.
     * @param name the element's name
     * @return the new <code>Element</code>
     */
protected Element defElement(String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, String[] exclusions, String[] inclusions, AttributeList atts) {
    BitSet excl = null;
    if (exclusions != null && exclusions.length > 0) {
        excl = new BitSet();
        for (String str : exclusions) {
            if (str.length() > 0) {
                excl.set(getElement(str).getIndex());
            }
        }
    }
    BitSet incl = null;
    if (inclusions != null && inclusions.length > 0) {
        incl = new BitSet();
        for (String str : inclusions) {
            if (str.length() > 0) {
                incl.set(getElement(str).getIndex());
            }
        }
    }
    return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts);
}

84. B6296240#main()

Project: jdk7u-jdk
Source File: B6296240.java
View license
public static void main(String[] args) {
    String[] malformedIPv4s = { "192.168.1.220..." };
    BitSet expectedExceptions = new BitSet(malformedIPv4s.length);
    expectedExceptions.clear();
    for (int i = 0; i < malformedIPv4s.length; i++) {
        try {
            InetAddress.getAllByName(malformedIPv4s[i]);
        } catch (UnknownHostException e) {
            expectedExceptions.set(i);
        }
    }
    for (int i = 0; i < malformedIPv4s.length; i++) {
        if (!expectedExceptions.get(i)) {
            System.out.println("getAllByName(\"" + malformedIPv4s[i] + "\") should throw exception.");
        }
    }
    if (expectedExceptions.cardinality() != malformedIPv4s.length) {
        throw new RuntimeException("Failed: some expected UnknownHostExceptions are not thrown.");
    }
}

85. Usage#evalLiveIn()

Project: kilim
Source File: Usage.java
View license
/**
     * This is the standard liveness calculation (Dragon Book, section 10.6). At each BB (and its
     * corresponding usage), we evaluate "in" using use and def. in = use U (out \ def) where out =
     * U succ.in, for all successors
     */
public boolean evalLiveIn(ArrayList<Usage> succUsage) {
    BitSet out = new BitSet(nLocals);
    BitSet old_in = (BitSet) in.clone();
    if (succUsage.size() == 0) {
        in = use;
    } else {
        // calculate out = U succ.in
        out = (BitSet) succUsage.get(0).in.clone();
        for (int i = 1; i < succUsage.size(); i++) {
            out.or(succUsage.get(i).in);
        }
        // calc out \ def == out & ~def == ~(out | def)
        BitSet def1 = (BitSet) def.clone();
        def1.flip(0, nLocals);
        out.and(def1);
        out.or(use);
        in = out;
    }
    return !(in.equals(old_in));
}

86. BitSetIteratorTest#testSingle()

Project: lenskit
Source File: BitSetIteratorTest.java
View license
@Test
public void testSingle() {
    BitSet s = new BitSet();
    s.set(0);
    BitSetIterator iter = new BitSetIterator(s);
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertThat(iter.next(), equalTo(0));
    assertFalse(iter.hasNext());
    assertFalse(iter.hasNext());
    assertTrue(iter.hasPrevious());
    assertTrue(iter.hasPrevious());
    assertThat(iter.previous(), equalTo(0));
    assertTrue(iter.hasNext());
    assertFalse(iter.hasPrevious());
}

87. CookieUtil#validCookieValueOctets()

Project: netty
Source File: CookieUtil.java
View license
private static BitSet validCookieValueOctets() {
    BitSet bits = new BitSet();
    bits.set(0x21);
    for (int i = 0x23; i <= 0x2B; i++) {
        bits.set(i);
    }
    for (int i = 0x2D; i <= 0x3A; i++) {
        bits.set(i);
    }
    for (int i = 0x3C; i <= 0x5B; i++) {
        bits.set(i);
    }
    for (int i = 0x5D; i <= 0x7E; i++) {
        bits.set(i);
    }
    return bits;
}

88. DTD#defElement()

Project: openjdk
Source File: DTD.java
View license
/**
     * Creates and returns an <code>Element</code>.
     * @param name        the element's name
     * @param type        the element's type
     * @param omitStart   {@code true} if the element needs no starting tag
     * @param omitEnd     {@code true} if the element needs no closing tag
     * @param content     the element's content
     * @param exclusions  the elements that must be excluded from the content of the element
     * @param inclusions  the elements that can be included as the content of the element
     * @param atts        the attributes of the element
     * @return the new <code>Element</code>
     */
protected Element defElement(String name, int type, boolean omitStart, boolean omitEnd, ContentModel content, String[] exclusions, String[] inclusions, AttributeList atts) {
    BitSet excl = null;
    if (exclusions != null && exclusions.length > 0) {
        excl = new BitSet();
        for (String str : exclusions) {
            if (str.length() > 0) {
                excl.set(getElement(str).getIndex());
            }
        }
    }
    BitSet incl = null;
    if (inclusions != null && inclusions.length > 0) {
        incl = new BitSet();
        for (String str : inclusions) {
            if (str.length() > 0) {
                incl.set(getElement(str).getIndex());
            }
        }
    }
    return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts);
}

89. PrimeTest#createPrimes()

Project: openjdk
Source File: PrimeTest.java
View license
/**
     * Create a {@code BitSet} wherein a set bit indicates the corresponding
     * index plus 2 is prime. That is, if bit N is set, then the integer N + 2
     * is prime. The values 0 and 1 are intentionally excluded. See the
     * <a
     * href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Algorithm_description">
     * Sieve of Eratosthenes</a> algorithm description for more information.
     *
     * @param upperBound The maximum prime to allow
     * @return bits indicating which indexes represent primes
     */
private static BitSet createPrimes(int upperBound) {
    int nbits = upperBound - 1;
    BitSet bs = new BitSet(nbits);
    for (int p = 2; p * p < upperBound; ) {
        for (int i = p * p; i < nbits + 2; i += p) {
            bs.set(i - 2, true);
        }
        do {
            ++p;
        } while (p > 1 && bs.get(p - 2));
    }
    bs.flip(0, nbits);
    return bs;
}

90. B6296240#main()

Project: openjdk
Source File: B6296240.java
View license
public static void main(String[] args) {
    String[] malformedIPv4s = { "192.168.1.220..." };
    BitSet expectedExceptions = new BitSet(malformedIPv4s.length);
    expectedExceptions.clear();
    for (int i = 0; i < malformedIPv4s.length; i++) {
        try {
            InetAddress.getAllByName(malformedIPv4s[i]);
        } catch (UnknownHostException e) {
            expectedExceptions.set(i);
        }
    }
    for (int i = 0; i < malformedIPv4s.length; i++) {
        if (!expectedExceptions.get(i)) {
            System.out.println("getAllByName(\"" + malformedIPv4s[i] + "\") should throw exception.");
        }
    }
    if (expectedExceptions.cardinality() != malformedIPv4s.length) {
        throw new RuntimeException("Failed: some expected UnknownHostExceptions are not thrown.");
    }
}

91. RedisBitSetTest#testEquals()

View license
@Test
public void testEquals() {
    BitSet b1 = new BitSet();
    BitSet b2 = new BitSet();
    IntStream.range(0, 100).forEach( i -> b1.set(i * 10, true));
    IntStream.range(0, 100).forEach( i -> b2.set(i * 99, true));
    RedisPool pool = Helper.getPool();
    RedisBitSet rb1 = new RedisBitSet(pool, "b1", b1.size());
    rb1.overwriteBitSet(b1);
    RedisBitSet rb2 = new RedisBitSet(pool, "b2", b2.size());
    rb2.overwriteBitSet(b2);
    assertEquals(b1, rb1.asBitSet());
    assertEquals(b2, rb2.asBitSet());
    assertThat(rb1, not(equalTo(rb2)));
    assertThat(b1, not(equalTo(b2)));
    assertThat(rb1, not(equalTo(b2)));
}

92. terminal_set#intersects()

Project: pluotsorbet
Source File: terminal_set.java
View license
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/** Determine if this set intersects another.
   * @param other the other set in question.
   */
public boolean intersects(terminal_set other) throws internal_error {
    not_null(other);
    /* make a copy of the other set */
    BitSet copy = (BitSet) other._elements.clone();
    /* xor out our values */
    copy.xor(this._elements);
    /* see if its different */
    return !copy.equals(other._elements);
}

93. SpanningTree#buildSpanningTree()

Project: Prefuse
Source File: SpanningTree.java
View license
/**
     * Build the spanning tree, starting at the given root. Uses an
     * unweighted breadth first traversal to build the spanning tree.
     * @param root the root node of the spanning tree
     */
public void buildSpanningTree(Node root) {
    // re-use a previously allocated tree if possible
    super.clearEdges();
    super.setRoot(root);
    // build unweighted spanning tree by BFS
    LinkedList q = new LinkedList();
    BitSet visit = new BitSet();
    q.add(root);
    visit.set(root.getRow());
    Table edges = getEdgeTable();
    while (!q.isEmpty()) {
        Node p = (Node) q.removeFirst();
        for (Iterator iter = p.edges(); iter.hasNext(); ) {
            Edge e = (Edge) iter.next();
            Node n = e.getAdjacentNode(p);
            if (!visit.get(n.getRow())) {
                q.add(n);
                visit.set(n.getRow());
                int er = super.addChildEdge(p.getRow(), n.getRow());
                edges.setInt(er, SOURCE_EDGE, e.getRow());
            }
        }
    }
}

94. TestRange#setTest2A()

Project: RoaringBitmap
Source File: TestRange.java
View license
@Test
public void setTest2A() {
    final MutableRoaringBitmap rb = new MutableRoaringBitmap();
    final MutableRoaringBitmap rb1 = MutableRoaringBitmap.add(rb, 100000L, 100000L);
    // will not affect rb1 (no shared container)
    rb.add(1);
    final int rbcard = rb1.getCardinality();
    assertEquals(0, rbcard);
    assertEquals(1, rb.getCardinality());
    final BitSet bs = new BitSet();
    assertTrue(TestRoaringBitmap.equals(bs, rb1));
    bs.set(1);
    assertTrue(TestRoaringBitmap.equals(bs, rb));
}

95. TestRange#setTest2A()

Project: RoaringBitmap
Source File: TestRange.java
View license
@Test
public void setTest2A() {
    final RoaringBitmap rb = new RoaringBitmap();
    final RoaringBitmap rb1 = RoaringBitmap.add(rb, 100000L, 100000L);
    // will not affect rb1 (no shared container)
    rb.add(1);
    final int rbcard = rb1.getCardinality();
    assertEquals(0, rbcard);
    assertEquals(1, rb.getCardinality());
    final BitSet bs = new BitSet();
    assertTrue(TestRoaringBitmap.equals(bs, rb1));
    bs.set(1);
    assertTrue(TestRoaringBitmap.equals(bs, rb));
}

96. CompactSparseTypedEdgeSet#remove()

View license
private boolean remove(TIntObjectHashMap<BitSet> edges, int i, T type) {
    BitSet types = edges.get(i);
    if (types == null)
        return false;
    int index = index(type);
    // "connected" set as necessary
    if (types.get(index)) {
        types.set(index, false);
        // If this was the last edge to that vertex, remove this BitMap
        if (types.cardinality() == 0) {
            edges.remove(i);
            size--;
        }
        return true;
    }
    return false;
}

97. SparseDirectedTypedEdgeSet#remove()

View license
private boolean remove(TIntObjectHashMap<BitSet> edges, int i, T type) {
    BitSet types = edges.get(i);
    if (types == null)
        return false;
    int index = index(type);
    // "connected" set as necessary
    if (types.get(index)) {
        types.set(index, false);
        // If this was the last edge to that vertex, remove this BitMap
        if (types.cardinality() == 0) {
            edges.remove(i);
            size--;
            // Check whether the other set has this edge, and if not, remove
            // it from the cache of connected vertices
            TIntObjectHashMap<BitSet> other = (edges == inEdges) ? outEdges : inEdges;
            if (!other.containsKey(i))
                connected.remove(i);
        }
        return true;
    }
    return false;
}

98. BitSetTest#setII()

Project: teavm
Source File: BitSetTest.java
View license
@Test
public void setII() throws IndexOutOfBoundsException {
    BitSet bitset = new BitSet(30);
    bitset.set(29, 29);
    // Test for method void java.util.BitSet.set(int, int)
    // pos1 and pos2 are in the same bitset element
    BitSet bs = new BitSet(16);
    bs.set(5);
    bs.set(15);
    bs.set(7, 11);
    for (int i = 0; i < 7; i++) {
        if (i == 5)
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    for (int i = 7; i < 11; i++) assertTrue("Failed to set bit " + i, bs.get(i));
    for (int i = 11; i < bs.size(); i++) {
        if (i == 15)
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    // pos1 and pos2 is in the same bitset element, boundry testing
    bs = new BitSet(16);
    bs.set(7, 64);
    for (int i = 0; i < 7; i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    for (int i = 7; i < 64; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 64", bs.get(64));
    // more boundary testing
    bs = new BitSet(32);
    bs.set(0, 64);
    for (int i = 0; i < 64; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 64", bs.get(64));
    bs = new BitSet(32);
    bs.set(0, 65);
    for (int i = 0; i < 65; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    assertFalse("Shouldn't have set bit 65", bs.get(65));
    // pos1 and pos2 are in two sequential bitset elements
    bs = new BitSet(128);
    bs.set(7);
    bs.set(110);
    bs.set(9, 74);
    for (int i = 0; i < 9; i++) {
        if (i == 7)
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    for (int i = 9; i < 74; i++) {
        assertTrue("Failed to set bit " + i, bs.get(i));
    }
    for (int i = 74; i < bs.size(); i++) {
        if (i == 110)
            assertTrue("Shouldn't have flipped bit " + i, bs.get(i));
        else
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    // pos1 and pos2 are in two non-sequential bitset elements
    bs = new BitSet(256);
    bs.set(7);
    bs.set(255);
    bs.set(9, 219);
    for (int i = 0; i < 9; i++) {
        if (i == 7)
            assertTrue("Shouldn't have set flipped " + i, bs.get(i));
        else
            assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    for (int i = 9; i < 219; i++) {
        assertTrue("failed to set bit " + i, bs.get(i));
    }
    for (int i = 219; i < 255; i++) {
        assertFalse("Shouldn't have set bit " + i, bs.get(i));
    }
    assertTrue("Shouldn't have flipped bit 255", bs.get(255));
    // test illegal args
    bs = new BitSet(10);
    bs.set(2, 2);
    assertFalse("Bit got set incorrectly ", bs.get(2));
}

99. TestBitField#testNextClearBit()

Project: ThriftyPaxos
Source File: TestBitField.java
View license
private void testNextClearBit() {
    BitSet set = new BitSet();
    BitField field = new BitField();
    set.set(0, 640);
    field.set(0, 640, true);
    assertEquals(set.nextClearBit(0), field.nextClearBit(0));
    Random random = new Random(1);
    field = new BitField();
    field.set(0, 500, true);
    for (int i = 0; i < 100000; i++) {
        int a = random.nextInt(120);
        int b = a + 1 + random.nextInt(200);
        field.clear(a);
        field.clear(b);
        assertEquals(b, field.nextClearBit(a + 1));
        field.set(a);
        field.set(b);
    }
}

100. DependencyInjectionFactoryTest#testWillSelectMatchingConstructor()

View license
public void testWillSelectMatchingConstructor() {
    BitSet used = new BitSet();
    Thing thing = DependencyInjectionFactory.newInstance(used, Thing.class, this, 1);
    assertSame(this, thing.getTestCase());
    assertEquals(1, thing.getFirst());
    assertEquals(4, thing.getSecond());
    assertTrue(used.get(0));
    assertTrue(used.get(1));
    used = new BitSet();
    thing = DependencyInjectionFactory.newInstance(used, Thing.class, this, "a");
    assertSame(this, thing.getTestCase());
    assertEquals(1, thing.getFirst());
    assertEquals(4, thing.getSecond());
    assertTrue(used.get(0));
    assertTrue(used.get(1));
}