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

import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.EventObject; import java.util.EventObject;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;


import com.vaadin.event.SerializableEventListener; import com.vaadin.event.SerializableEventListener;
import com.vaadin.server.Setter; import com.vaadin.server.Setter;
return null; 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. * Returns whether this {@code HasValue} is considered to be empty.
* <p> * <p>

Loading…
Cancel
Save