Java API Improvements

netbeans at netbeans at
Thu Apr 16 13:18:29 UTC 2020

Improvement Stream<T>:

public default Stream<T> unless(Predicate<T> predicate) { //predicate.negate
public default Stream<T> nonNull() { //So instead of filter((o) -> o != 
public <Y, Z extends Class<Y> > Stream<Y> cast(Z cl) // instead of filter(
(o)->o == null || o instanceof Class).map(Class::cast)
//Maybe more readable for non-native-English-speakers
public default Stream<T> andIf(Predicate<T> predicate) //alias for filter
public default Stream<T> andIfNot(Predicate<T> predicate) //alias to unless

Improvement Optional<T>:

implements Serializable //if T instanceof Serializable 
public void ifEmpty(Runnable action)
public <Y, Z extends Class<Y> > Optional<Y> cast(Z cl) //filter((o)->o 
instanceof Class).map(Class::cast)
public Optional<T> unless(Predicate<T> predicate)
//Maybe more readable for non-native-English-speakers
public Optional<T> andIf(Predicate<T> predicate)
public Optional<T> andIfNot(Predicate<T> predicate)

Improvement Predicate<T>:

implements Serializable //if T instanceof Serializable 
public default Predicate<T> andNot(Predicate<T> predicate) //less lambdas
public static Predicate<Z> allMatch(Z... what)
public static Predicate<Z> noneMatch(Z... what)
public static Predicate<Z> anyMatch(Z... what)
public static Predicate<Z> isNull() 
public static Predicate<Z> nonNull()

Improvement String:

public static boolean isNotNullAndBlank(String value) 
public static boolean isNotNullAndEmpty(String value) 

Improving "var":

SomeClass z; ...
ofNullable(z).filter(var::isSomething) // instead of filter(SomeClass::

More information about the jdk-dev mailing list