mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-10 21:00:36 +01:00
Improve isSet logic, add utils
This commit is contained in:
parent
0cfdde04c2
commit
87dda18a24
@ -2,6 +2,8 @@ package net.minestom.server.utils;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Used to mimic the final keyword
|
||||
*
|
||||
@ -28,7 +30,19 @@ public final class FinalObject<T> {
|
||||
}
|
||||
|
||||
public boolean isSet() {
|
||||
return obj != null;
|
||||
return finalized;
|
||||
}
|
||||
|
||||
public boolean optionalSet(T object) {
|
||||
if (isSet()) return false;
|
||||
set(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean optionalSet(Supplier<T> objectSupplier) {
|
||||
if (isSet()) return false;
|
||||
set(objectSupplier.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
|
Loading…
Reference in New Issue
Block a user