3434/**
3535 * An immutable {@code BitSet} implementation.
3636 *
37+ * @param <T> Component type
3738 * @author Ruslan Sennov
3839 */
3940public interface BitSet <T > extends SortedSet <T > {
4041
42+ /**
43+ * The <a href="https://docs.oracle.com/javase/8/docs/api/index.html">serial version uid</a>.
44+ */
4145 long serialVersionUID = 1L ;
4246
47+ /**
48+ * Builder of the BitSet. Encapsulates the conversion functions for T.
49+ *
50+ * @param <T> Component type
51+ */
4352 class Builder <T > {
4453
4554 final static Builder <Integer > DEFAULT = new Builder <>(i -> i , i -> i );
@@ -52,6 +61,12 @@ class Builder<T> {
5261 this .toInt = toInt ;
5362 }
5463
64+ /**
65+ * Returns a {@link java.util.stream.Collector} which may be used in conjunction with
66+ * {@link java.util.stream.Stream#collect(java.util.stream.Collector)} to obtain an {@link ArrayList}.
67+ *
68+ * @return A {@link ArrayList} Collector.
69+ */
5570 public Collector <T , ArrayList <T >, BitSet <T >> collector () {
5671 final BinaryOperator <ArrayList <T >> combiner = (left , right ) -> {
5772 left .addAll (right );
@@ -60,10 +75,21 @@ public Collector<T, ArrayList<T>, BitSet<T>> collector() {
6075 return Collector .of (ArrayList ::new , ArrayList ::add , combiner , this ::ofAll );
6176 }
6277
78+ /**
79+ * Returns a new empty BitSet
80+ *
81+ * @return new empty BitSet
82+ */
6383 public BitSet <T > empty () {
6484 return new BitSetModule .BitSet1 <>(fromInt , toInt , 0L );
6585 }
6686
87+ /**
88+ * Builds a new BitSet from a specific value t
89+ *
90+ * @param t value to build the BitSet from
91+ * @return new BitSet
92+ */
6793 public BitSet <T > of (T t ) {
6894 final int value = toInt .apply (t );
6995 if (value < BitSetModule .BITS_PER_WORD ) {
@@ -75,27 +101,59 @@ public BitSet<T> of(T t) {
75101 }
76102 }
77103
104+ /**
105+ * Builds a new BitSet from a list of values
106+ *
107+ * @param values values to build the BitSet from
108+ * @return new BitSet
109+ */
78110 @ SuppressWarnings ("varargs" )
79111 @ SafeVarargs
80112 public final BitSet <T > of (T ... values ) {
81113 return empty ().addAll (Array .wrap (values ));
82114 }
83115
116+ /**
117+ * Builds a new BitSet from an {@link Iterable}
118+ *
119+ * @param values iterable to build the BitSet from
120+ * @return new BitSet
121+ */
84122 public BitSet <T > ofAll (Iterable <? extends T > values ) {
85123 Objects .requireNonNull (values , "values is null" );
86124 return empty ().addAll (values );
87125 }
88126
127+ /**
128+ * Builds a new BitSet from a {@link java.util.stream.Stream} of values
129+ *
130+ * @param javaStream stream of values to build the BitSet from
131+ * @return new BitSet
132+ */
89133 public BitSet <T > ofAll (java .util .stream .Stream <? extends T > javaStream ) {
90134 Objects .requireNonNull (javaStream , "javaStream is null" );
91135 return empty ().addAll (Iterator .ofAll (javaStream .iterator ()));
92136 }
93137
138+ /**
139+ * Builds a new BitSet tabulating a value n times
140+ *
141+ * @param n number of times to tabulate
142+ * @param f function to tabulate
143+ * @return new BitSet
144+ */
94145 public BitSet <T > tabulate (int n , Function <? super Integer , ? extends T > f ) {
95146 Objects .requireNonNull (f , "f is null" );
96147 return empty ().addAll (Collections .tabulate (n , f ));
97148 }
98149
150+ /**
151+ * Builds a new BitSet containing n copies of the same value
152+ *
153+ * @param n number of times to copy the value
154+ * @param s value supplier
155+ * @return new BitSet
156+ */
99157 public BitSet <T > fill (int n , Supplier <? extends T > s ) {
100158 Objects .requireNonNull (s , "s is null" );
101159 return empty ().addAll (Collections .fill (n , s ));
@@ -115,14 +173,29 @@ static Builder<Character> withCharacters() {
115173 return new Builder <>(i -> (char ) i .intValue (), c -> (int ) c );
116174 }
117175
176+ /**
177+ * Returns new {@link BitSet} Builder for type {@link Byte}
178+ *
179+ * @return new Builder
180+ */
118181 static Builder <Byte > withBytes () {
119182 return new Builder <>(Integer ::byteValue , Byte ::intValue );
120183 }
121184
185+ /**
186+ * Returns new {@link BitSet} Builder for type {@link Long}
187+ *
188+ * @return new Builder
189+ */
122190 static Builder <Long > withLongs () {
123191 return new Builder <>(Integer ::longValue , Long ::intValue );
124192 }
125193
194+ /**
195+ * Returns new {@link BitSet} Builder for type {@link Short}
196+ *
197+ * @return new Builder
198+ */
126199 static Builder <Short > withShorts () {
127200 return new Builder <>(Integer ::shortValue , Short ::intValue );
128201 }
0 commit comments