3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-25 07:40:13 +01:00

API: Add Tristate#fromOptionalBoolean (#1125)

Dieser Commit ist enthalten in:
Badbird5907 2023-10-26 03:01:24 -04:00 committet von GitHub
Ursprung 81b183ac39
Commit b30802c1b3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Velocity Contributors
* Copyright (C) 2018-2023 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
@ -7,6 +7,7 @@
package com.velocitypowered.api.permission;
import java.util.Optional;
import net.kyori.adventure.util.TriState;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -66,6 +67,21 @@ public enum Tristate {
return val ? TRUE : FALSE;
}
/**
* Returns a {@link Tristate} from an {@link Optional}.
*
* <p>Unlike {@link #fromBoolean(boolean)}, this method returns {@link #UNDEFINED}
* if the value is empty.</p>
*
* @param val the optional boolean value
* @return {@link #UNDEFINED}, {@link #TRUE} or {@link #FALSE}, if the value is empty,
* <code>true</code> or <code>false</code>, respectively.
*/
public static Tristate fromOptionalBoolean(Optional<Boolean> val) {
return val.map(Tristate::fromBoolean).orElse(UNDEFINED);
}
private final boolean booleanValue;
Tristate(boolean booleanValue) {