Class Sugar

java.lang.Object
de.galan.commons.util.Sugar

public class Sugar extends Object
Simple syntax sugar/shortener
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    Casts an object by type inference.
    static <T> T
    fallback(T val, T fallback)
    Returns the given value, or the fallback if the value is null.
    static <T> T
    first(T... values)
    Returns the first non-null value.
    static <T> Predicate<T>
    not(Predicate<T> t)
    Deprecated.
    Use Predicate.not(..) instead (since Java 11)
    static <T> Optional<T>
    optional(T value)
    Shortens the Optional.ofNullable(..) syntax.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sugar

      public Sugar()
  • Method Details

    • optional

      public static <T> Optional<T> optional(T value)
      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

      public static <T> Predicate<T> not(Predicate<T> t)
      Deprecated.
      Use Predicate.not(..) instead (since Java 11)
      Negates the given Predicate
    • cast

      public static <T> T cast(Object x)
      Casts an object by type inference. see also http://weblogs.java.net/blog/emcmanus/archive/2007/03/getting_rid_of.html See Generics
      Parameters:
      x - Object that will be casted