Class FeatureFlag<T>

java.lang.Object
io.github.projectunified.faststats.featureflag.FeatureFlag<T>
Type Parameters:
T - the type of the flag value (String, Number, or Boolean)

public final class FeatureFlag<T> extends Object
A feature flag representing a setting or configuration fetched from the FastStats server.
  • Method Details

    • getId

      public String getId()
      Get the flag identifier.
      Returns:
      the flag id
    • getType

      public FeatureFlag.Type getType()
      Returns the type representing the value type of this flag.
      Returns:
      the value type
    • getDefaultValue

      public T getDefaultValue()
      Get the default value for this flag.
      Returns:
      the default value
    • getCached

      public Optional<T> getCached()
      Get the current cached flag value.
      Returns:
      the cached value, if present
    • getExpiration

      public Optional<Instant> getExpiration()
      Get the expiration time for the current cached value.
      Returns:
      the expiration time, or empty if not fetched yet
    • isExpired

      public boolean isExpired()
      Returns whether the current cached value is expired or absent.
      Returns:
      true if expired or absent, false otherwise
    • isValid

      public boolean isValid()
      Returns whether the current cached value is still valid.
      Returns:
      true if valid and not expired, false otherwise
    • whenReady

      public CompletableFuture<T> whenReady()
      Return a future that completes with the flag value once it is ready.
      Returns:
      a future completing with the flag value
    • fetch

      public CompletableFuture<T> fetch()
      Force a fresh fetch of the flag value from the server.
      Returns:
      a future completing with the latest server value
    • optIn

      public CompletableFuture<T> optIn()
      Request that the server opt in to this flag, then refresh the cached value.
      Returns:
      a future completing with the updated flag value
    • optOut

      public CompletableFuture<T> optOut()
      Request that the server opt out of this flag, then refresh the cached value.
      Returns:
      a future completing with the updated flag value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object