Class MoreObjects


  • public class MoreObjects
    extends java.lang.Object
    Methods that java.util.Objects should include.
    Author:
    jjlauer
    • Constructor Summary

      Constructors 
      Constructor Description
      MoreObjects()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T first​(java.lang.Iterable<T> values)  
      static <T> T first​(T[] values)  
      static <T> boolean in​(T value, java.lang.Iterable<T> values)
      Checks whether the value is in the list of values.
      static <T> boolean in​(T value, T... values)
      Checks whether the value is in the list of values.
      static boolean isBlank​(java.lang.CharSequence chars)
      Checks if the string is null, empty, or has only characters consisting of spaces.
      static boolean isEmpty​(java.lang.CharSequence chars)
      Checks if the string is null or has zero chars.
      static boolean isEmpty​(java.lang.Iterable<?> values)
      Null-safe evaluation of whether an Iterable is empty.
      static boolean isEmpty​(java.util.Collection<?> values)
      Null-safe evaluation of whether a collection is empty.
      static boolean isEmpty​(java.util.Map<?,​?> map)
      Null-safe evaluation of whether a map is empty.
      static <T> boolean isEmpty​(T[] values)
      Null-safe evaluation of whether an array is empty.
      static boolean isTrue​(java.lang.Boolean value)
      Null-safe evaluation of whether a boolean is true.
      static <T> java.lang.Iterable<T> iterable​(java.lang.Iterable<T> values)
      Null-safe iterable to simplify use in for-loops, etc.
      static <T> java.lang.Iterable<T> iterable​(T[] values)
      Null-safe iterable to simplify use in for-loops, etc.
      static <T> T last​(java.lang.Iterable<T> values)  
      static <T> T last​(T[] values)  
      static int size​(java.lang.Object[] values)
      Null-safe evaluation of the length of an array.
      static int size​(java.util.Collection<?> values)
      Null-safe evaluation of the size of a collection.
      static int size​(java.util.Map<?,​?> map)
      Null-safe evaluation of the size of a map.
      • Methods inherited from class java.lang.Object

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

      • MoreObjects

        public MoreObjects()
    • Method Detail

      • isTrue

        public static boolean isTrue​(java.lang.Boolean value)
        Null-safe evaluation of whether a boolean is true.
        Parameters:
        value - The value to check
        Returns:
        True if value is non-null AND true otherwise false
      • in

        public static <T> boolean in​(T value,
                                     T... values)
        Checks whether the value is in the list of values.
        Type Parameters:
        T - The type
        Parameters:
        value - The value to check
        values - The list of values to check against
        Returns:
        True if the value is contained otherwise false
      • in

        public static <T> boolean in​(T value,
                                     java.lang.Iterable<T> values)
        Checks whether the value is in the list of values.
        Type Parameters:
        T - The type
        Parameters:
        value - The value to check
        values - The list of values to check against
        Returns:
        True if the value is contained otherwise false
      • iterable

        public static <T> java.lang.Iterable<T> iterable​(T[] values)
        Null-safe iterable to simplify use in for-loops, etc.
        Type Parameters:
        T -
        Parameters:
        values -
        Returns:
        An empty iterable if values is null otherwise an iterable of values.
      • iterable

        public static <T> java.lang.Iterable<T> iterable​(java.lang.Iterable<T> values)
        Null-safe iterable to simplify use in for-loops, etc.
        Type Parameters:
        T -
        Parameters:
        values -
        Returns:
        An empty iterable if values is null otherwise an iterable of values.
      • size

        public static int size​(java.lang.Object[] values)
        Null-safe evaluation of the length of an array.
        Parameters:
        values -
        Returns:
        0 if array is null or empty otherwise the length
      • size

        public static int size​(java.util.Collection<?> values)
        Null-safe evaluation of the size of a collection.
        Parameters:
        values -
        Returns:
        0 if collection is null or empty otherwise the length
      • size

        public static int size​(java.util.Map<?,​?> map)
        Null-safe evaluation of the size of a map.
        Parameters:
        map -
        Returns:
        0 if map is null or empty otherwise the length
      • first

        public static <T> T first​(T[] values)
      • first

        public static <T> T first​(java.lang.Iterable<T> values)
      • last

        public static <T> T last​(T[] values)
      • last

        public static <T> T last​(java.lang.Iterable<T> values)
      • isEmpty

        public static <T> boolean isEmpty​(T[] values)
        Null-safe evaluation of whether an array is empty.
        Type Parameters:
        T -
        Parameters:
        values - The array
        Returns:
        True if array is null or has 0 elements
      • isEmpty

        public static boolean isEmpty​(java.util.Collection<?> values)
        Null-safe evaluation of whether a collection is empty.
        Parameters:
        values - The collection
        Returns:
        True if the collection is null or has 0 elements.
      • isEmpty

        public static boolean isEmpty​(java.lang.Iterable<?> values)
        Null-safe evaluation of whether an Iterable is empty.
        Parameters:
        values - The iterable
        Returns:
        True if the iterable is null or has 0 elements.
      • isEmpty

        public static boolean isEmpty​(java.util.Map<?,​?> map)
        Null-safe evaluation of whether a map is empty.
        Parameters:
        map - The map
        Returns:
        True if the map is null or has 0 elements.
      • isEmpty

        public static boolean isEmpty​(java.lang.CharSequence chars)
        Checks if the string is null or has zero chars.
      • isBlank

        public static boolean isBlank​(java.lang.CharSequence chars)
        Checks if the string is null, empty, or has only characters consisting of spaces.