Sfoglia il codice sorgente

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

Fixes #8323
tags/8.0.0.beta2
Giovanni Lovato 7 anni fa
parent
commit
5c24cff09f
1 ha cambiato i file con 13 aggiunte e 0 eliminazioni
  1. 13
    0
      server/src/main/java/com/vaadin/data/HasValue.java

+ 13
- 0
server/src/main/java/com/vaadin/data/HasValue.java Vedi 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…
Annulla
Salva