> For the complete documentation index, see [llms.txt](https://tanishisherewith.gitbook.io/dynamic-hud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tanishisherewith.gitbook.io/dynamic-hud/contextmenu/option-less-than-t-greater-than-class/boolean-option.md).

# Boolean Option

### Introduction

The `BooleanOption` class inherits from the `Option<Boolean>` class and allows users to switch between two states, typically represented as "on" and "off".

### Details

**Constructor**

The Boolean Option class has two constructors that takes the following parameters:

* One of the constructors uses the `BooleanPool` class to store and manage the Boolean values. This is when you don't want the hassle to create a new Boolean for every BooleanOption you create.
* **Supplier Requirement**: The `Supplier<Boolean>` parameter is necessary to obtain the current state of the Boolean value.
* **Consumer Provision**: The `Consumer<Boolean>` parameter updates the Boolean value when the option is interacted with.
* **Name Parameter**: The `name` parameter labels the option within the HUD, enhancing user experience and clarity.

**BooleanPool**

The `BooleanPool` class is a thread-safe cache that stores and retrieves Boolean values. It provides a fast and efficient way to access and update the Boolean values. This is what the `BooleanPool` class looks like

{% code lineNumbers="true" %}

```java
public class BooleanPool {
    private static final Map<String, Boolean> pool = new ConcurrentHashMap<>();

    public static void put(String key, boolean value) {
        pool.put(key, value);
    }
    public static void remove(String key) {
        pool.remove(key);
    }

    public static boolean get(String key) {
        return pool.getOrDefault(key, false);
    }
}
```

{% endcode %}

### Interactivity

* **Click Response**: Clicking the option toggles its state and triggers the associated setter action.
* **Render Behavior**: The option is visually represented with a label, changing color to indicate its state (green for "on", red for "off").
* **Mouse Interaction**: The class includes methods to handle mouse clicks, ensuring the option responds to user input.

### Example Usage

```java
// Create a BooleanOption for sound settings
BooleanOption soundOption = new BooleanOption(
    "Sound Enabled",
    () -> this.isSoundEnabled(), // Getter: Fetches the current sound setting
    value -> this.setSoundEnabled(value) // Setter: Updates the sound setting
);    
```

{% hint style="danger" %}
Ensure that the getter is synchronized with the setter; otherwise, the option will enter a soft lock, and the value will not update. (Meaning the getter and setter should be updating the same variables or referencing the same variable)
{% endhint %}
