BitSets { public static int previousClearBit(BitSet bitSet, int fromIndex) { if (fromIndex < -1) { throw new IndexOutOfBoundsException(); } while (fromIndex >= 0) { if (!bitSet.get(fromIndex)) { return fromIndex; } --fromIndex; } return -1; } private  BitSets(); static boolean contains(BitSet set0, BitSet set1); static boolean contains(BitSet set0, ImmutableBitSet set1); static Iterable<Integer> toIter(final BitSet bitSet); static Iterable<Integer> toIter(final ImmutableBitSet bitSet); static IntList toList(final BitSet bitSet); static int[] toArray(final BitSet bitSet); static BitSet of(int... bits); static BitSet of(Integer[] bits); static BitSet of(Iterable<? extends Number> bits); static BitSet of(ImmutableIntList bits); static BitSet range(int fromIndex, int toIndex); static BitSet range(int toIndex); static void setAll(BitSet bitSet, Iterable<? extends Number> list); static BitSet union(BitSet set0, BitSet... sets); static int previousClearBit(BitSet bitSet, int fromIndex); static SortedMap<Integer, BitSet> closure(
      SortedMap<Integer, BitSet> equivalence); static void populate(BitSet bitSet, Iterable<? extends Number> list); static void populate(BitSet bitSet, ImmutableIntList list);  }
@Test public void testPreviousClearBit() { assertThat(BitSets.previousClearBit(BitSets.of(), 10), equalTo(10)); assertThat(BitSets.previousClearBit(BitSets.of(), 0), equalTo(0)); assertThat(BitSets.previousClearBit(BitSets.of(), -1), equalTo(-1)); try { final int actual = BitSets.previousClearBit(BitSets.of(), -2); fail("expected exception, got " + actual); } catch (IndexOutOfBoundsException e) { } assertThat(BitSets.previousClearBit(BitSets.of(0, 1, 3, 4), 4), equalTo(2)); assertThat(BitSets.previousClearBit(BitSets.of(0, 1, 3, 4), 3), equalTo(2)); assertThat(BitSets.previousClearBit(BitSets.of(0, 1, 3, 4), 2), equalTo(2)); assertThat(BitSets.previousClearBit(BitSets.of(0, 1, 3, 4), 1), equalTo(-1)); assertThat(BitSets.previousClearBit(BitSets.of(1, 3, 4), 1), equalTo(0)); }