Class Flag

java.lang.Object
org.apache.juneau.internal.Flag

public final class Flag extends Object
A simple settable boolean value.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Flag
    Creates a boolean value initialized to false.
    boolean
    Sets the boolean value to true and returns the value before it was set.
    boolean
    Sets the boolean value to false and returns the value before it was set.
    ifNotSet(Snippet snippet)
    Runs a snippet of code if the boolean value is false.
    ifSet(Snippet snippet)
    Runs a snippet of code if the boolean value is true.
    boolean
    Returns true if the boolean value is true.
    boolean
    Returns true if the boolean value is false.
    static Flag
    of(boolean value)
    Creates a boolean value with the specified initial state.
    set()
    Sets the boolean value to true.
    setIf(boolean value)
    Sets the boolean value to true if the value is true.
    Sets the boolean value to false.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static Flag create()
      Creates a boolean value initialized to false.
      Returns:
      A new boolean value.
    • of

      public static Flag of(boolean value)
      Creates a boolean value with the specified initial state.
      Parameters:
      value - The initial state of the value.
      Returns:
      A new boolean value.
    • ifSet

      public Flag ifSet(Snippet snippet)
      Runs a snippet of code if the boolean value is true.
      Example:

      BoolValue flag = BoolValue.create(); ... flag.ifSet(()->doSomething());

      Parameters:
      snippet - The snippet of code to run.
      Returns:
      This object.
    • ifNotSet

      public Flag ifNotSet(Snippet snippet)
      Runs a snippet of code if the boolean value is false.
      Example:

      BoolValue flag = BoolValue.create(); ... flag.ifNotSet(()->doSomething());

      Parameters:
      snippet - The snippet of code to run.
      Returns:
      This object.
    • getAndSet

      public boolean getAndSet()
      Sets the boolean value to true and returns the value before it was set.
      Returns:
      The previous value.
    • getAndUnset

      public boolean getAndUnset()
      Sets the boolean value to false and returns the value before it was set.
      Returns:
      The previous value.
    • set

      public Flag set()
      Sets the boolean value to true.
      Returns:
      This object.
    • unset

      public Flag unset()
      Sets the boolean value to false.
      Returns:
      This object.
    • isSet

      public boolean isSet()
      Returns true if the boolean value is true.
      Returns:
      true if the boolean value is true.
    • isUnset

      public boolean isUnset()
      Returns true if the boolean value is false.
      Returns:
      true if the boolean value is false.
    • setIf

      public Flag setIf(boolean value)
      Sets the boolean value to true if the value is true.
      Parameters:
      value - The value to set.
      Returns:
      This object.