An int only allows 32 values (0 to 31), but it would be easy to switch to long. That would be mostly search/replace. The elements in the set would still be bytes. But don't forget to replace 1 by 1L.
Newer versions of Java might support value types (cf [http://cr.openjdk.java.net/~jrose/values/values-0.html]) . Then this can be changed to such a value type and the methods would not need to be static.
import static ch.claude_martin.smallset.SmallSet.*;
import ch.claude_martin.smallset.SmallSet;
// ...
void static process(byte b) { // ...
// ...
int set = of(1,3,4,7); // [1,3,4,7]
set = add(set, (byte) 9); // [1,3,4,7,9]
set = union(set, ofRange(12, 32)); // [1,3,4,7,9,12,...,31]
containsAll(set, Arrays.asList(3,7));// true
set = complement(set); // [0,2,5,6,8,10,11]
System.out.println(SmallSet.toString(set)); // "(0,2,5,6,8,10,11)"
for(byte b : iterate(set)) process(b);
forEach(set, b -> process(b));
int sum;
sum = reduce(set, 0, Integer::sum); // 42
sum = reduce(set, Integer::sum).orElse(0); // 42
sum = sum(set); // 42Check out the javadoc for more methods: http://claude-martin.ch/smallset/doc/
Or browse the code. There are only 3 classes (plus a JUnit test class).
There's a branch for a version in which SmallSet in an inline class. It only works with a JDK that supports this. It's available as a preview but it's not officially released with any JDK yet. I expet that they will release a preview after the next LTS release (Java 17?) and will add it to a later LTS as an official feature of the Java language.