From d37bd5259adb79e2043cf63bb0e3578418531952 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Fri, 10 Sep 2021 21:20:16 +0300 Subject: Add ObservableView.hasValue --- .../cottonmc/cotton/gui/widget/data/ObservableProperty.java | 10 +++++++--- .../cottonmc/cotton/gui/widget/data/ObservableView.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src/main') 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 778f431..49dbf9f 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 @@ -40,9 +40,7 @@ public final class ObservableProperty implements ObservableView { return new ObservableProperty<>(initialValue, true); } - /** - * {@return whether this property has been set to a value} - */ + @Override public boolean hasValue() { return hasValue; } @@ -51,6 +49,7 @@ public final class ObservableProperty implements ObservableView { * {@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() { @@ -115,6 +114,11 @@ public final class ObservableProperty implements ObservableView { public ObservableView readOnly() { // Missing delegates from Kotlin... :( return new ObservableView<>() { + @Override + public boolean hasValue() { + return ObservableProperty.this.hasValue(); + } + @Override public T get() { return ObservableProperty.this.get(); 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 8439e80..164f51b 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 @@ -14,6 +14,19 @@ import java.util.function.Supplier; */ @ApiStatus.Experimental public interface ObservableView extends Supplier { + /** + * {@return whether this property has been set to a value} + */ + boolean hasValue(); + + /** + * {@return the value of this property} + * @throws IllegalStateException if not initialized + * @see #hasValue() + */ + @Override + T get(); + /** * Adds a change listener to this property view. * -- cgit