Class Objects


  • public final class Objects
    extends java.lang.Object
    Date: 30.08.2011
    Author:
    James R. Perkins
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Objects.HashCodeBuilder
      A builder to simplify the building of hash codes.
      static class  Objects.ToStringBuilder
      A builder to build a default Object#toString() value.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areEqual​(boolean first, boolean second)
      Checks to see if two booleans are equal.
      static boolean areEqual​(char first, char second)
      Checks to see if two characters are equal.
      static boolean areEqual​(double first, double second)
      Checks to see if two doubles are equal.
      static boolean areEqual​(float first, float second)
      Checks to see if two floats are equal.
      static boolean areEqual​(long first, long second)
      Checks to see if two longs are equal.
      static boolean areEqual​(java.lang.Object first, java.lang.Object second)
      Checks to see if two objects are equal.
      static <T> T checkNonNull​(T ref)
      Checks to see if an object is null, otherwise throws an IllegalArgumentException.
      static <T> T checkNonNull​(T ref, java.lang.String message)
      Checks to see if an object is null, otherwise throws an IllegalArgumentException.
      static <T> T checkNonNull​(T ref, java.lang.String message, java.lang.Object... args)
      Checks to see if an object is null, otherwise throws an IllegalArgumentException.
      • Methods inherited from class java.lang.Object

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

      • areEqual

        public static boolean areEqual​(boolean first,
                                       boolean second)
        Checks to see if two booleans are equal.
        Parameters:
        first - the first boolean.
        second - the second boolean.
        Returns:
        true if the first is equal to the second, otherwise false.
      • areEqual

        public static boolean areEqual​(char first,
                                       char second)
        Checks to see if two characters are equal.
        Parameters:
        first - the first character.
        second - the second character.
        Returns:
        true if the first is equal to the second, otherwise false.
      • areEqual

        public static boolean areEqual​(long first,
                                       long second)
        Checks to see if two longs are equal. This method is also used for int's, shorts, and bytes.
        Parameters:
        first - the first long.
        second - the second long.
        Returns:
        true if the first is equal to the second, otherwise false.
      • areEqual

        public static boolean areEqual​(float first,
                                       float second)
        Checks to see if two floats are equal.
        Parameters:
        first - the first float.
        second - the second float.
        Returns:
        true if the first is equal to the second, otherwise false.
      • areEqual

        public static boolean areEqual​(double first,
                                       double second)
        Checks to see if two doubles are equal.
        Parameters:
        first - the first double.
        second - the second double.
        Returns:
        true if the first is equal to the second, otherwise false.
      • areEqual

        public static boolean areEqual​(java.lang.Object first,
                                       java.lang.Object second)
        Checks to see if two objects are equal.

        Note this method does not handle arrays. The Arrays class has utilities for equality of arrays.

        Parameters:
        first - the first optionally null object.
        second - the second optionally null object.
        Returns:
        true if the first is equal to the second, otherwise false.
      • checkNonNull

        public static <T> T checkNonNull​(T ref)
        Checks to see if an object is null, otherwise throws an IllegalArgumentException.
        Type Parameters:
        T - the type of the object.
        Parameters:
        ref - the reference to the object.
        Returns:
        the reference if it is not null.
      • checkNonNull

        public static <T> T checkNonNull​(T ref,
                                         java.lang.String message)
        Checks to see if an object is null, otherwise throws an IllegalArgumentException.
        Type Parameters:
        T - the type of the object.
        Parameters:
        ref - the reference to the object.
        message - the message used in the IllegalArgumentException constructor.
        Returns:
        the reference if it is not null.
      • checkNonNull

        public static <T> T checkNonNull​(T ref,
                                         java.lang.String message,
                                         java.lang.Object... args)
        Checks to see if an object is null, otherwise throws an IllegalArgumentException.
        Type Parameters:
        T - the type of the object.
        Parameters:
        ref - the reference to the object.
        message - the message format used in the IllegalArgumentException constructor.
        args - the arguments used to format the message.
        Returns:
        the reference if it is not null.