So I'm converting some bitfields in our application to use EnumSet instead, and I'm curious if there's a better way to do a comparison for X|Y. Currently we do something like:
if(bitfield & (X | Y) != 0) {
//do stuff
}
The EnumSet equivalent seems to be:
if(enumSet.contains(X) || enumSet.contains(Y)) {
//do stuff
}
Is there a cleaner way to do this? I know you can check for containsAll()
like so:
EnumSet flagsToCheck = EnumSet.of(X, Y);
if(enumSet.containsAll(flagsToCheck)) {
//do stuff
}
But that's for a scenario where you want to know if (X & Y)
is set. Is there an equivalent way to check for (X | Y)
? I would think there would be something like a containsAny()
method, but I don't see anything that seems to have that effect.