Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
API: Add Tristate#fromOptionalBoolean (#1125)
Dieser Commit ist enthalten in:
Ursprung
81b183ac39
Commit
b30802c1b3
@ -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) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren