It turns out that Java has a mechanism to handle flag values, and I didn't have to roll my own. Here are the various pieces that need to be addressed:
WearLocation and BodyPartCapability are already enums but the places where we're using my Bitfield need to have that replaced with EnumSet.
Storage to the database can be achieved by storing long values (as we already do) and Apache commons EnumUtils in an AttributeConverter. The Apache EnumUtils appear to use the enum's ordinal which is not a great idea, but my current implementation is doing that too. Best case would be to move to a new solution that doesn't use ordinals. Instead, the enums could possibly define their own integer constants between 0 and 63.
It turns out that Java has a mechanism to handle flag values, and I didn't have to roll my own. Here are the various pieces that need to be addressed:
WearLocation
andBodyPartCapability
are already enums but the places where we're using myBitfield
need to have that replaced withEnumSet
.long
values (as we already do) and Apache commonsEnumUtils
in an AttributeConverter. The ApacheEnumUtils
appear to use the enum's ordinal which is not a great idea, but my current implementation is doing that too. Best case would be to move to a new solution that doesn't use ordinals. Instead, the enums could possibly define their own integer constants between 0 and 63.ChRoNoN's answer on this SO question is a pretty interesting approach. See also KeaganFouche's answer here.