ImmutableBitSet implements Iterable<Integer>, Serializable, Comparable<ImmutableBitSet> { public static ImmutableBitSet range(int fromIndex, int toIndex) { if (fromIndex > toIndex) { throw new IllegalArgumentException(); } if (toIndex < 0) { throw new IllegalArgumentException(); } if (fromIndex == toIndex) { return EMPTY; } int startWordIndex = wordIndex(fromIndex); int endWordIndex = wordIndex(toIndex - 1); long[] words = new long[endWordIndex + 1]; long firstWordMask = WORD_MASK << fromIndex; long lastWordMask = WORD_MASK >>> -toIndex; if (startWordIndex == endWordIndex) { words[startWordIndex] |= firstWordMask & lastWordMask; } else { words[startWordIndex] |= firstWordMask; for (int i = startWordIndex + 1; i < endWordIndex; i++) { words[i] = WORD_MASK; } words[endWordIndex] |= lastWordMask; } return new ImmutableBitSet(words); } 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 testRange() { assertEquals(ImmutableBitSet.range(0, 4).toList(), Arrays.asList(0, 1, 2, 3)); assertEquals(ImmutableBitSet.range(1, 4).toList(), Arrays.asList(1, 2, 3)); assertEquals(ImmutableBitSet.range(4).toList(), Arrays.asList(0, 1, 2, 3)); assertEquals(ImmutableBitSet.range(0).toList(), Collections.<Integer>emptyList()); assertEquals(ImmutableBitSet.range(2, 2).toList(), Collections.<Integer>emptyList()); assertThat(ImmutableBitSet.range(63, 66).toString(), equalTo("{63, 64, 65}")); assertThat(ImmutableBitSet.range(65, 68).toString(), equalTo("{65, 66, 67}")); assertThat(ImmutableBitSet.range(65, 65).toString(), equalTo("{}")); assertThat(ImmutableBitSet.range(65, 65).length(), equalTo(0)); assertThat(ImmutableBitSet.range(65, 165).cardinality(), equalTo(100)); assertThat(ImmutableBitSet.builder().set(63, 66).build().toString(), equalTo("{63, 64, 65}")); assertThat(ImmutableBitSet.builder().set(65, 68).build().toString(), equalTo("{65, 66, 67}")); assertThat(ImmutableBitSet.builder().set(65, 65).build().toString(), equalTo("{}")); assertThat(ImmutableBitSet.builder().set(65, 65).build().length(), equalTo(0)); assertThat(ImmutableBitSet.builder().set(65, 165).build().cardinality(), equalTo(100)); final ImmutableBitSet e0 = ImmutableBitSet.range(0, 0); final ImmutableBitSet e1 = ImmutableBitSet.of(); assertTrue(e0.equals(e1)); assertThat(e0.hashCode(), equalTo(e1.hashCode())); assertTrue(ImmutableBitSet.builder().build() == ImmutableBitSet.of()); }