Class BuilderDefaults


  • public class BuilderDefaults
    extends java.lang.Object
    This is a utility class with useful methods for builders
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T defaultIfAbsent​(T newValue, T defaultValue)
      Returns this default value if the new value is null
      static java.lang.String emptyToNull​(java.lang.String test)  
      static AllowableValues emptyToNull​(AllowableValues newValue, AllowableValues current)
      Retains current allowable values if then new value is null
      static java.lang.String nullToEmpty​(java.lang.String test)  
      static <T> T[] nullToEmptyArray​(T[] newValues)
      Returns an empty list if the newValue is null
      static <T> java.util.List<T> nullToEmptyList​(java.util.Collection<T> newValue)
      Returns an empty list if the newValue is null
      static <K,​V>
      java.util.Map<K,​V>
      nullToEmptyMap​(java.util.Map<K,​V> newValue)
      Returns an empty map if the input is null
      static <K,​V>
      java.util.Map<K,​java.util.List<V>>
      nullToEmptyMultimap​(java.util.Map<K,​java.util.List<V>> newValue)
      Returns an empty map if the input is null
      static <T> java.util.Set<T> nullToEmptySet​(java.util.Set<T> newValue)
      Returns an empty set if the newValue is null
      static com.fasterxml.classmate.ResolvedType replaceIfMoreSpecific​(com.fasterxml.classmate.ResolvedType replacement, com.fasterxml.classmate.ResolvedType defaultValue)
      Coalesces the resolved type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • defaultIfAbsent

        public static <T> T defaultIfAbsent​(T newValue,
                                            T defaultValue)
        Returns this default value if the new value is null
        Type Parameters:
        T - - Represents any type that is nullable
        Parameters:
        newValue - - new value
        defaultValue - - default value
        Returns:
        Coalesces the newValue and defaultValue to return a non-null value
      • nullToEmptyList

        public static <T> java.util.List<T> nullToEmptyList​(java.util.Collection<T> newValue)
        Returns an empty list if the newValue is null
        Type Parameters:
        T - - any type
        Parameters:
        newValue - - a list
        Returns:
        non-null list
      • nullToEmptyArray

        public static <T> T[] nullToEmptyArray​(T[] newValues)
        Returns an empty list if the newValue is null
        Type Parameters:
        T - - any type
        Parameters:
        newValues - - an array
        Returns:
        non-null list
      • nullToEmptyMap

        public static <K,​V> java.util.Map<K,​V> nullToEmptyMap​(java.util.Map<K,​V> newValue)
        Returns an empty map if the input is null
        Type Parameters:
        K - - map key
        V - - map value
        Parameters:
        newValue - - nullable map value
        Returns:
        non-null Map
      • nullToEmptyMultimap

        public static <K,​V> java.util.Map<K,​java.util.List<V>> nullToEmptyMultimap​(java.util.Map<K,​java.util.List<V>> newValue)
        Returns an empty map if the input is null
        Type Parameters:
        K - - map key
        V - - map value
        Parameters:
        newValue - - nullable map value
        Returns:
        non-null Map
      • nullToEmptySet

        public static <T> java.util.Set<T> nullToEmptySet​(java.util.Set<T> newValue)
        Returns an empty set if the newValue is null
        Type Parameters:
        T - - any type
        Parameters:
        newValue - - a set
        Returns:
        non-null set
      • replaceIfMoreSpecific

        public static com.fasterxml.classmate.ResolvedType replaceIfMoreSpecific​(com.fasterxml.classmate.ResolvedType replacement,
                                                                                 com.fasterxml.classmate.ResolvedType defaultValue)
        Coalesces the resolved type. Preservers the default value if the replacement is either null or represents a type that is less specific than the default value. For e.g. if default value represents a String then the replacement value has to be any value that is a subclass of Object. If it represents Object.class then the default value is preferred
        Parameters:
        replacement - - replacement value
        defaultValue - - default value
        Returns:
        most specific resolved type
      • emptyToNull

        public static AllowableValues emptyToNull​(AllowableValues newValue,
                                                  AllowableValues current)
        Retains current allowable values if then new value is null
        Parameters:
        newValue - - new value
        current - - existing values
        Returns:
        the appropriate value
      • emptyToNull

        public static java.lang.String emptyToNull​(java.lang.String test)
      • nullToEmpty

        public static java.lang.String nullToEmpty​(java.lang.String test)