Class Objects


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

      • Objects

        public Objects()
    • Method Detail

      • compare

        public static <T extends 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.