Fabric API

Fabric API

106M Downloads

Tristate extensions

liach opened this issue ยท 1 comments

commented

The tristate enum is a good one. To improve its usability, I propose a few changes to its usage:

Addition of methods:

  1. boolean getOr(boolean fallback). This will return the corresponding boolean value if the enum value is not DEFAULT, and fallback for default. We cannot just assume DEFAULT is false.
  2. boolean getOr(BooleanSupplier supplier). Similar to get(boolean) but can be used to save a few potentially expensive calls, like permApi.getPermission(player, permKey).getOr(player::isGeneralPermissionTarget).
  3. @Nullable Boolean asNullableBoolean(): simple enough, returns a nullable boolean representation
  4. static Tristate fromNullableBoolean(@Nullable Boolean value) similar to above
commented

So more of an OptionalBoolean, like this?