Java Object Equal areEqual(Object o1, Object o2)

Here you can find the source of areEqual(Object o1, Object o2)

Description

This is a utility method that compares two objects when one or both of the objects might be null The result of this method is determined as follows:
  1. If o1 and o2 are the same object according to the == operator, return true.

    License

    Open Source License

    Declaration

    public static final boolean areEqual(Object o1, Object o2) 
    

    Method Source Code

    //package com.java2s;
    /**//w w  w . j  a v a 2  s. c  om
     * $RCSFile$
     * $Revision: 18467 $
     * $Date: 2005-02-15 14:36:52 -0800 (Tue, 15 Feb 2005) $
     *
     * Copyright (C) 2004-2008 Jive Software. All rights reserved.
     *
     * This software is published under the terms of the GNU Public License (GPL),
     * a copy of which is included in this distribution, or a commercial license
     * agreement with Jive.
     */
    
    public class Main {
        /**
         * This is a utility method that compares two objects when one or
         * both of the objects might be <CODE>null</CODE>  The result of
         * this method is determined as follows:
         * <OL>
         * <LI>If <CODE>o1</CODE> and <CODE>o2</CODE> are the same object
         * according to the <CODE>==</CODE> operator, return
         * <CODE>true</CODE>.
         * <LI>Otherwise, if either <CODE>o1</CODE> or <CODE>o2</CODE> is
         * <CODE>null</CODE>, return <CODE>false</CODE>.
         * <LI>Otherwise, return <CODE>o1.equals(o2)</CODE>.
         * </OL>
         * <p/>
         * This method produces the exact logically inverted result as the
         * {@link #areDifferent(Object, Object)} method.<P>
         * <p/>
         * For array types, one of the <CODE>equals</CODE> methods in
         * {@link java.util.Arrays} should be used instead of this method.
         * Note that arrays with more than one dimension will require some
         * custom code in order to implement <CODE>equals</CODE> properly.
         */
        public static final boolean areEqual(Object o1, Object o2) {
            if (o1 == o2) {
                return true;
            } else if (o1 == null || o2 == null) {
                return false;
            } else {
                return o1.equals(o2);
            }
        }
    }
    

    Related

    1. areEqual(final Object x, final Object y)
    2. areEqual(Object o1, Object o2)
    3. areEqualStr(Object o1, Object o2)
    4. deepEquals(Object o1, Object o2)
    5. equalObjects(Object object1, Object object2)
    6. equals(BSONObject a, BSONObject b)