ImmutableBitSet implements Iterable<Integer>, Serializable, Comparable<ImmutableBitSet> { public static SortedMap<Integer, ImmutableBitSet> closure( SortedMap<Integer, ImmutableBitSet> equivalence) { if (equivalence.isEmpty()) { return ImmutableSortedMap.of(); } int length = equivalence.lastKey(); for (ImmutableBitSet bitSet : equivalence.values()) { length = Math.max(length, bitSet.length()); } if (equivalence.size() < length || equivalence.firstKey() != 0) { SortedMap<Integer, ImmutableBitSet> old = equivalence; equivalence = new TreeMap<>(); for (int i = 0; i < length; i++) { final ImmutableBitSet bitSet = old.get(i); equivalence.put(i, bitSet == null ? ImmutableBitSet.of() : bitSet); } } final Closure closure = new Closure(equivalence); return closure.closure; } 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 testClosure() { final SortedMap<Integer, ImmutableBitSet> empty = Maps.newTreeMap(); assertThat(ImmutableBitSet.closure(empty), equalTo(empty)); final SortedMap<Integer, ImmutableBitSet> map = Maps.newTreeMap(); map.put(0, ImmutableBitSet.of(3)); map.put(1, ImmutableBitSet.of()); map.put(2, ImmutableBitSet.of(7)); map.put(3, ImmutableBitSet.of(4, 12)); map.put(4, ImmutableBitSet.of()); map.put(5, ImmutableBitSet.of()); map.put(6, ImmutableBitSet.of()); map.put(7, ImmutableBitSet.of()); map.put(8, ImmutableBitSet.of()); map.put(9, ImmutableBitSet.of()); map.put(10, ImmutableBitSet.of()); map.put(11, ImmutableBitSet.of()); map.put(12, ImmutableBitSet.of()); final String original = map.toString(); final String expected = "{0={3, 4, 12}, 1={}, 2={7}, 3={3, 4, 12}, 4={4, 12}, 5={}, 6={}, 7={7}, 8={}, 9={}, 10={}, 11={}, 12={4, 12}}"; assertThat(ImmutableBitSet.closure(map).toString(), equalTo(expected)); assertThat("argument modified", map.toString(), equalTo(original)); final SortedMap<Integer, ImmutableBitSet> map2 = Maps.newTreeMap(); map2.put(0, ImmutableBitSet.of(3)); map2.put(2, ImmutableBitSet.of(7)); map2.put(3, ImmutableBitSet.of(4, 12)); map2.put(9, ImmutableBitSet.of()); final String original2 = map2.toString(); assertThat(ImmutableBitSet.closure(map2).toString(), equalTo(expected)); assertThat("argument modified", map2.toString(), equalTo(original2)); }