ImmutableBitSet implements Iterable<Integer>, Serializable, Comparable<ImmutableBitSet> { public int nth(int n) { int start = 0; for (long word : words) { final int bitCount = Long.bitCount(word); if (n < bitCount) { while (word != 0) { if ((word & 1) == 1) { if (n == 0) { return start; } --n; } word >>= 1; ++start; } } start += 64; n -= bitCount; } throw new IndexOutOfBoundsException("index out of range: " + n); } private  ImmutableBitSet(long[] words); static ImmutableBitSet of(); static ImmutableBitSet of(int... bits); static ImmutableBitSet of(Iterable<Integer>  bits); static ImmutableBitSet of(ImmutableIntList bits); static ImmutableBitSet valueOf(long... longs); static ImmutableBitSet valueOf(LongBuffer longs); static ImmutableBitSet range(int fromIndex, int toIndex); static ImmutableBitSet range(int toIndex); Iterable<ImmutableBitSet> powerSet(); boolean get(int bitIndex); ImmutableBitSet get(int fromIndex, int toIndex); String toString(); boolean intersects(ImmutableBitSet set); int cardinality(); int hashCode(); int size(); boolean equals(Object obj); int compareTo(ImmutableBitSet o); int nextSetBit(int fromIndex); int nextClearBit(int fromIndex); int previousClearBit(int fromIndex); Iterator<Integer> iterator(); IntList toList(); List<Integer> asList(); int[] toArray(); long[] toLongArray(); ImmutableBitSet union(BitSet other); ImmutableBitSet union(ImmutableBitSet other); static ImmutableBitSet union(
      Iterable<? extends ImmutableBitSet> sets); ImmutableBitSet except(ImmutableBitSet that); ImmutableBitSet intersect(ImmutableBitSet that); boolean contains(ImmutableBitSet set1); int indexOf(int bit); static SortedMap<Integer, ImmutableBitSet> closure(
      SortedMap<Integer, ImmutableBitSet> equivalence); int length(); boolean isEmpty(); static Builder builder(); static Builder builder(ImmutableBitSet bitSet); int nth(int n); ImmutableBitSet set(int i); ImmutableBitSet setIf(int bit, boolean condition); ImmutableBitSet clear(int i); ImmutableBitSet clearIf(int i, boolean condition); BitSet toBitSet(); ImmutableBitSet permute(Map<Integer, Integer> map); static Iterable<ImmutableBitSet> permute(
      Iterable<ImmutableBitSet> bitSets,
      final Map<Integer, Integer> map); ImmutableBitSet shift(int offset); static final Comparator<ImmutableBitSet> COMPARATOR; static final Ordering<ImmutableBitSet> ORDERING; static final Function<? super BitSet, ImmutableBitSet> FROM_BIT_SET; }
@Test public void testNth() { assertThat(ImmutableBitSet.of(0, 2, 4).nth(0), equalTo(0)); assertThat(ImmutableBitSet.of(0, 2, 4).nth(1), equalTo(2)); assertThat(ImmutableBitSet.of(0, 2, 4).nth(2), equalTo(4)); assertThat(ImmutableBitSet.of(0, 2, 63).nth(2), equalTo(63)); assertThat(ImmutableBitSet.of(0, 2, 64).nth(2), equalTo(64)); assertThat(ImmutableBitSet.of(64).nth(0), equalTo(64)); assertThat(ImmutableBitSet.of(64, 65).nth(0), equalTo(64)); assertThat(ImmutableBitSet.of(64, 65).nth(1), equalTo(65)); assertThat(ImmutableBitSet.of(64, 128).nth(1), equalTo(128)); try { ImmutableBitSet.of().nth(0); fail("expected throw"); } catch (IndexOutOfBoundsException e) { } try { ImmutableBitSet.of().nth(1); fail("expected throw"); } catch (IndexOutOfBoundsException e) { } try { ImmutableBitSet.of(64).nth(1); fail("expected throw"); } catch (IndexOutOfBoundsException e) { } try { ImmutableBitSet.of(64).nth(-1); fail("expected throw"); } catch (IndexOutOfBoundsException e) { } }