Enum Class Tristate

java.lang.Object
java.lang.Enum<Tristate>
dev.polv.taleapi.permission.Tristate
All Implemented Interfaces:
Serializable, Comparable<Tristate>, Constable

public enum Tristate extends Enum<Tristate>
Represents a tri-valued permission state.

Unlike a simple boolean, Tristate provides three distinct states:

  • ALLOW - Permission is explicitly granted
  • DENY - Permission is explicitly denied
  • UNDEFINED - No explicit permission set (inherit from parent/default)

Why Tristate?

A binary true/false system cannot distinguish between "denied" and "not set". This distinction is crucial for permission inheritance:

  • UNDEFINED permissions inherit from parent groups
  • DENY permissions block inheritance even if a parent allows it
  • Enum Constant Details

    • ALLOW

      public static final Tristate ALLOW
      Permission is explicitly granted.
    • DENY

      public static final Tristate DENY
      Permission is explicitly denied.
    • UNDEFINED

      public static final Tristate UNDEFINED
      No explicit permission set - inherit from parent or use default.
  • Method Details

    • values

      public static Tristate[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Tristate valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • asBoolean

      public boolean asBoolean()
      Converts this tristate to a boolean value.
      Returns:
      true if ALLOW, false otherwise
    • asBoolean

      public boolean asBoolean(boolean defaultValue)
      Converts this tristate to a boolean with a default for UNDEFINED.
      Parameters:
      defaultValue - the value to return if this is UNDEFINED
      Returns:
      true if ALLOW, false if DENY, or defaultValue if UNDEFINED
    • fromBoolean

      public static Tristate fromBoolean(boolean value)
      Creates a Tristate from a boolean value.
      Parameters:
      value - the boolean value
      Returns:
      ALLOW if true, DENY if false
    • fromNullableBoolean

      public static Tristate fromNullableBoolean(Boolean value)
      Creates a Tristate from a nullable Boolean.
      Parameters:
      value - the Boolean value, or null
      Returns:
      ALLOW if true, DENY if false, UNDEFINED if null
    • isDefined

      public boolean isDefined()
      Returns whether this state is defined (not UNDEFINED).
      Returns:
      true if this is ALLOW or DENY