Java Object Equal internalEquals(Object[] o1, Object[] o2)

Here you can find the source of internalEquals(Object[] o1, Object[] o2)

Description

internal Equals

License

Apache License

Declaration

private static boolean internalEquals(Object[] o1, Object[] o2) 

Method Source Code

//package com.java2s;
/* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j.
 * The package name has been changed; there may also be other changes.
 * //from   w w w .j  a  v a2s. com
 * This notice is included to meet the condition in clause 4(b) of the License. 
 */

import java.util.Collection;

public class Main {
    private static boolean internalEquals(Object[] o1, Object[] o2) {
        for (int i1 = 0; i1 < o1.length; i1++) {
            final Object obj1 = o1[i1];
            boolean matchFound = false;
            for (int i2 = 0; !matchFound && i2 < o1.length; i2++) {
                final Object obj2 = o2[i2];
                if (obj1.equals(obj2)) {
                    matchFound = true;
                    o2[i2] = null;
                }
            }
            if (!matchFound)
                return false;
        }
        return true;
    }

    /**
     * <p>Checks whether two collections are equal. Two collections
     * C<sub>1</sub> and C<sub>2</sub> are equal, if the following conditions
     * are true:</p>
     *
     * <ul>
     *
     * <li><p>For each c<sub>1<em>i</em></sub> (element of C<sub>1</sub>) there
     * is a c<sub>2<em>j</em></sub> (element of C<sub>2</sub>), and
     * c<sub>1<em>i</em></sub> equals c<sub>2<em>j</em></sub>.</p></li>
     *
     * <li><p>For each c<sub>2<em>i</em></sub> (element of C<sub>2</sub>) there
     * is a c<sub>1<em>j</em></sub> (element of C<sub>1</sub>) and
     * c<sub>2<em>i</em></sub> equals c<sub>1<em>j</em></sub>.</p></li>
     *
     * </ul>
     *
     * @param c1 the first collection
     * @param c2 the second collection
     * @return <code>true</code> if the collections are equal, else
     * <code>false</code>.
     */
    public static boolean equals(Collection<?> c1, Collection<?> c2) {
        Object[] o1 = c1.toArray();
        Object[] o2 = c2.toArray();
        return internalEquals(o1, o2);
    }

    /**
     * <p>Compares to object arrays with regarding the objects' order. For
     * example, [1, 2, 3] and [2, 1, 3] are equal.</p>
     *
     * @param c1 The first object array.
     * @param c2 The second object array.
     * @return <code>true</code> if the object arrays are equal,
     * <code>false</code> if they are not.
     */
    public static boolean equals(Object[] c1, Object[] c2) {
        final Object[] o1 = c1.clone();
        final Object[] o2 = c2.clone();
        return internalEquals(o1, o2);
    }
}

Related

  1. equals(Object object1, Object object2)
  2. equals(Object thisObj, Object thatObj)
  3. equals(Object v1, Object v2)
  4. equals(Object x, Object y)
  5. equals(Object... objects)
  6. isEquals(final Object lhs, final Object rhs)
  7. isEquals(Object object1, Object object2)
  8. nullSafeEquals(Object o1, Object o2)
  9. nullSafeEquals(Object o1, Object o2)