Improve isSet logic, add utils

This commit is contained in:
Noel Németh 2022-06-19 22:38:20 +02:00
parent 0cfdde04c2
commit 87dda18a24

View File

@ -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() {