Java Object Compare areEqual(Object one, Object another)

Here you can find the source of areEqual(Object one, Object another)

Description

Return true if one is equal to another.

License

BSD License

Parameter

Parameter Description
one a parameter
another a parameter

Return

true if one is equal to another.

Declaration

public static final boolean areEqual(Object one, Object another) 

Method Source Code

//package com.java2s;
/*L/*from  w  ww .  j  av a  2s. c om*/
 * Copyright SAIC, SAIC-Frederick.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caadapter/LICENSE.txt for details.
 */

public class Main {
    /**
    * Return true if one is equal to another.
    * @param one
    * @param another
    * @return true if one is equal to another.
    */
    public static final boolean areEqual(Object one, Object another) {
        boolean result = (one == null ? another == null : one.equals(another));
        return result;
    }

    /**
     * Return true if one is equal to another.
     * @param one
     * @param another
     * @param treatNullAndBlankStringEquals if true will treat null and blank string the same; otherwise, it will not.
     * @return true if one is equal to another.
     */
    public static final boolean areEqual(Object one, Object another, boolean treatNullAndBlankStringEquals) {
        boolean result = (one == null ? another == null : one.equals(another));
        if (!result && treatNullAndBlankStringEquals) {
            String oneStr = one == null ? "" : one.toString();
            String anotherStr = another == null ? "" : another.toString();
            result = isBlank(oneStr) && isBlank(anotherStr);
        }
        return result;
    }

    /**
     * Null string or blank string is considered as blank
     * @param s
     * @return true if blank
     */
    public static final boolean isBlank(String s) {
        return (s == null) || (s.trim().length() == 0);
    }
}

Related

  1. areEqual(Object obj, Object obj2)
  2. areEqual(Object obj1, Object obj2)
  3. areEqual(Object obj1, Object obj2)
  4. areEqual(Object obj1, Object obj2)
  5. areEqual(Object object1, Object object2)
  6. areEqual(Object parameter, Object otherParameter)
  7. areEqual(Object value, Object otherValue)
  8. areEqual(Object value1, Object value2)
  9. areEqual(T obj1, T obj2)