Package de.galan.commons.util
Class Sugar
java.lang.Object
de.galan.commons.util.Sugar
Simple syntax sugar/shortener
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TCasts an object by type inference.static <T> Tfallback(T val, T fallback) Returns the given value, or the fallback if the value is null.static <T> Tfirst(T... values) Returns the first non-null value.static <T> Predicate<T>Deprecated.Use Predicate.not(..) instead (since Java 11)static <T> Optional<T>optional(T value) Shortens the Optional.ofNullable(..) syntax.
-
Constructor Details
-
Sugar
public Sugar()
-
-
Method Details
-
optional
Shortens the Optional.ofNullable(..) syntax. -
fallback
public static <T> T fallback(T val, T fallback) Returns the given value, or the fallback if the value is null. -
first
public static <T> T first(T... values) Returns the first non-null value. -
not
Deprecated.Use Predicate.not(..) instead (since Java 11)Negates the given Predicate -
cast
Casts an object by type inference. see also http://weblogs.java.net/blog/emcmanus/archive/2007/03/getting_rid_of.html SeeGenerics- Parameters:
x- Object that will be casted
-