aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/data
diff options
context:
space:
mode:
authorGiovanni Lovato <heruan@aldu.net>2017-01-27 11:35:17 +0100
committerLeif Åstrand <legioth@gmail.com>2017-01-27 12:35:17 +0200
commit5c24cff09f2a51e587e4a29b914bce67404607d5 (patch)
tree011987d4690a1d45c78f8167aaab69563a088cc4 /server/src/main/java/com/vaadin/data
parent8be086b6cbabda2a65b3b970526ed3a69670b04c (diff)
downloadvaadin-framework-5c24cff09f2a51e587e4a29b914bce67404607d5.tar.gz
vaadin-framework-5c24cff09f2a51e587e4a29b914bce67404607d5.zip
Add a default getOptionalValue() to HasValue (#8324)
Fixes #8323
Diffstat (limited to 'server/src/main/java/com/vaadin/data')
-rw-r--r--server/src/main/java/com/vaadin/data/HasValue.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/HasValue.java b/server/src/main/java/com/vaadin/data/HasValue.java
index 962a3e9620..de2f86550f 100644
--- a/server/src/main/java/com/vaadin/data/HasValue.java
+++ b/server/src/main/java/com/vaadin/data/HasValue.java
@@ -19,6 +19,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.EventObject;
import java.util.Objects;
+import java.util.Optional;
import com.vaadin.event.SerializableEventListener;
import com.vaadin.server.Setter;
@@ -220,6 +221,18 @@ public interface HasValue<V> extends Serializable {
}
/**
+ * Returns the current value of this object, wrapped in an {@code Optional}.
+ * <p>
+ * The {@code Optional} will be empty if the value is {@code null} or
+ * {@code isEmpty()} returns {@code true}.
+ *
+ * @return the current value, wrapped in an {@code Optional}
+ */
+ public default Optional<V> getOptionalValue() {
+ return isEmpty() ? Optional.empty() : Optional.ofNullable(getValue());
+ }
+
+ /**
* Returns whether this {@code HasValue} is considered to be empty.
* <p>
* By default this is an equality check between current value and empty