Browse Source

Add a default getOptionalValue() to HasValue (#8324)

Fixes #8323
tags/8.0.0.beta2
Giovanni Lovato 7 years ago
parent
commit
5c24cff09f
1 changed files with 13 additions and 0 deletions
  1. 13
    0
      server/src/main/java/com/vaadin/data/HasValue.java

+ 13
- 0
server/src/main/java/com/vaadin/data/HasValue.java View File

@@ -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;
@@ -219,6 +220,18 @@ public interface HasValue<V> extends Serializable {
return null;
}

/**
* 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>

Loading…
Cancel
Save