aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java6
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java15
2 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java
index 49dbf9f..eb92387 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableProperty.java
@@ -45,12 +45,6 @@ public final class ObservableProperty<T> implements ObservableView<T> {
return hasValue;
}
- /**
- * {@return the value of this property}
- * @throws IllegalStateException if not initialized
- * @throws NullPointerException if the value is null and null values aren't allowed
- * @see #hasValue()
- */
@Override
public T get() {
if (!hasValue) {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java
index 164f51b..8bad55c 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/ObservableView.java
@@ -3,6 +3,7 @@ package io.github.cottonmc.cotton.gui.widget.data;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
+import java.util.Optional;
import java.util.function.Supplier;
/**
@@ -28,6 +29,20 @@ public interface ObservableView<T> extends Supplier<T> {
T get();
/**
+ * {@return the value of this property, or null if not initialized}
+ */
+ default @Nullable T getOrNull() {
+ return hasValue() ? get() : null;
+ }
+
+ /**
+ * {@return the nonnull value of this property, or {@link Optional#empty()} if null or not initialized}
+ */
+ default Optional<T> find() {
+ return Optional.ofNullable(getOrNull());
+ }
+
+ /**
* Adds a change listener to this property view.
*
* @param listener the added listener