Class Objects


  • public class Objects
    extends java.lang.Object
    Useful functions for working with different objects.
    Since:
    8.1
    Author:
    Leonid Bushuev from JetBrains
    • Constructor Summary

      Constructors 
      Constructor Description
      Objects()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.Comparable<? super T>>
      int
      compare​(T object1, T object2)
      Compares two comparable objects.
      static <T> T ifNull​(T value, T defaultValue)
      Returns the given value if it is not null, or the default value otherwise.
      • Methods inherited from class java.lang.Object

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

      • Objects

        public Objects()
    • Method Detail

      • compare

        public static <T extends java.lang.Comparable<? super T>> int compare​(@Nullable
                                                                              T object1,
                                                                              @Nullable
                                                                              T object2)
        Compares two comparable objects. Null is treated as less than a not null object.
        Type Parameters:
        T - type of objects.
        Parameters:
        object1 - the first object to compare.
        object2 - the second object to compare.
        Returns:
        the comparison result.
      • ifNull

        @NotNull
        public static <T> T ifNull​(@Nullable
                                   T value,
                                   @NotNull
                                   T defaultValue)
        Returns the given value if it is not null, or the default value otherwise.
        Type Parameters:
        T - type of value.
        Parameters:
        value - value to check and return if it is not null.
        defaultValue - default value - to return if the value is null.
        Returns:
        non-null value.