Class FunctionalUtils


  • public class FunctionalUtils
    extends Object
    These methods are linked to the functional paradigm and use Functional interfaces of java 8+, all the main interfaces are in the package java.util.function.
    Author:
    Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
    • Method Detail

      • getDefaultOrBuild

        public static <T> T getDefaultOrBuild​(T defaultValue,
                                              Supplier<T> builder)
        Tests that defaultValue isn't null. If this test is positive, then returns the defaultValue; Otherwise builds a new instance using the builder
        Parameters:
        defaultValue - default instance value
        builder - instance generator
        Returns:
        corresponding non-null instance
      • getCheckDefaultOrBuild

        public static <T> T getCheckDefaultOrBuild​(Predicate<T> defaultValueChecker,
                                                   T defaultValue,
                                                   Supplier<T> builder)
        Tests the defaultValue using the defaultValueChecker. If its test is positive, then returns the defaultValue; Otherwise builds a new instance using the builder
        Parameters:
        defaultValueChecker - checker that tests the defaultValue
        defaultValue - default instance value
        builder - supplier that generates a typed instance
        Returns:
        corresponding instance after check