Skip to content

Instantly share code, notes, and snippets.

@claudemartin
Created April 24, 2018 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudemartin/7f7da857c4530050be55917e44caafca to your computer and use it in GitHub Desktop.
Save claudemartin/7f7da857c4530050be55917e44caafca to your computer and use it in GitHub Desktop.
Configurable bit position per enum [Example]
package ch.claude_martin.enumbitset;
import static java.util.Arrays.asList;
import java.util.stream.Collectors;
public class Main {
enum Bla implements EnumBitSetHelper<Bla> {
A(-1), B(42), C(108);
final int i;
private Bla(int i) {
this.i = i;
}
public int toInt() {
return this.i;
}
}
public static void main(String[] args) {
var set = GeneralDomainBitSet.of(EnumDomain.of(Bla.class), asList(Bla.A));
set.add(Bla.C);
var list = set.stream().map(Bla::toInt).collect(Collectors.toList());
System.out.println(list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment