Example usage for java.lang Object equals

List of usage examples for java.lang Object equals

Introduction

In this page you can find the example usage for java.lang Object equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:Main.java

/**
 * Tests if the two objects are equal//  w w  w.j a  va2  s.  c  om
 *
 * @param o1 first object
 * @param o2 second object
 * @since ostermillerutils 1.06.00
 */
private static boolean equalObjects(Object o1, Object o2) {
    if (o1 == null && o2 == null)
        return true;
    if (o1 == null || o2 == null)
        return false;
    return o1.equals(o2);
}

From source file:Main.java

/**
 * assert two objects whether equals or not?
 * @param obj1/*from w  ww  . ja  v  a  2  s  . c o  m*/
 *           the obj1 argument.
 * @param obj2
 *           the obj2 argument;
 * @return
 *         flag .
 */
private static boolean objectEquals(Object obj1, Object obj2) {
    if (obj1 == null && obj2 == null) {
        return true;
    }
    if (obj1 == null || obj2 == null) {
        return false;
    }
    return obj1.equals(obj2);
}

From source file:baggage.BaseTestCase.java

protected static final void assertNotEquals(Object left, Object right) {
    if (left.equals(right)) {
        Assert.fail(left + " is equal to " + right);
    }//from  www . j a  va 2  s  . c  o  m
}

From source file:it.govpay.model.BasicModel.java

public static <T extends Comparable<? super T>> boolean equals(List<T> a, List<T> b) {
    if (a == null || b == null)
        return a == null && b == null;

    if (a.size() != b.size())
        return false;

    Collections.sort(a);//from  w  w w . j a v  a  2 s .  c  om
    Collections.sort(b);

    for (int index = 0; index < a.size(); index++) {
        Object a1 = b.get(index);
        Object b1 = b.get(index);

        if (!a1.equals(b1))
            return false;
    }

    return true;
}

From source file:net.sf.jasperreports.functions.standard.LogicalFunctions.java

/**
 * Checks if the two specified objects are equal.
 *//*  w  ww.  j  a  v  a 2 s.  c o  m*/
@Function("EQUALS")
@FunctionParameters({ @FunctionParameter("obj1"), @FunctionParameter("obj2") })
public static Boolean EQUALS(Object obj1, Object obj2) {
    if (obj1 != null) {
        return obj1.equals(obj2);
    } else if (obj2 != null) {
        return obj2.equals(obj1);
    }
    return true; // both null
}

From source file:com.qwazr.search.index.BackupStatus.java

private static final boolean equalsNull(Object o1, Object o2) {
    if (o1 == null)
        return o2 == null;
    if (o2 == null)
        return false;
    return o1.equals(o2);
}

From source file:Main.java

public static boolean equals(Object object1, Object object2) {
    if (object1 == object2) {
        return true;
    }//  w ww. j a v  a 2  s .  c  o m
    if (object1 == null || object2 == null) {
        return false;
    }
    return object1.equals(object2);

}

From source file:Main.java

/**
 * Dictionary does not have an equals.//from  w w  w  .ja v a  2  s  .  c om
 * Please use  Map.equals().
 *
 * <p>Follows the equals contract of Java 2's Map.</p>
 * @param d1 the first directory.
 * @param d2 the second directory.
 * @return true if the directories are equal.
 * @since Ant 1.5
 * @deprecated since 1.6.x.
 */
public static boolean equals(Dictionary<?, ?> d1, Dictionary<?, ?> d2) {
    if (d1 == d2) {
        return true;
    }

    if (d1 == null || d2 == null) {
        return false;
    }

    if (d1.size() != d2.size()) {
        return false;
    }

    Enumeration<?> e1 = d1.keys();
    while (e1.hasMoreElements()) {
        Object key = e1.nextElement();
        Object value1 = d1.get(key);
        Object value2 = d2.get(key);
        if (value2 == null || !value1.equals(value2)) {
            return false;
        }
    }

    // don't need the opposite check as the Dictionaries have the
    // same size, so we've also covered all keys of d2 already.

    return true;
}

From source file:Main.java

/**
 * This method is a helper for classes to implement {@link java.lang.Object#equals(java.lang.Object)}
 * checks if two objects are equals - two levels of checks are
 * made - first if both are null or not null. If either is null,
 * check is made whether both are null./*from   www.  ja va  2s.  c  om*/
 * If both are non null, equality also is checked if so indicated
 * @param obj1 first object to be compared
 * @param obj2 second object to be compared
 * @param checkEquality flag to indicate whether object equality should
 * be checked if obj1 and obj2 are non-null
 * @return true if the two objects are equal
 * false otherwise
 * 
 * source from: https://github.com/apache/pig/blob/89c2e8e76c68d0d0abe6a36b4e08ddc56979796f/src/org/apache/pig/impl/util/Utils.java
 */
public static boolean checkNullEquals(Object obj1, Object obj2, boolean checkEquality) {
    if (obj1 == null || obj2 == null) {
        return obj1 == obj2;
    }
    if (checkEquality) {
        if (!obj1.equals(obj2)) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

private static int safeCompare(Object f1, Object f2) {
    if (f1 == null && f2 == null)
        return 0;
    if (f1 == null && f2 != null)
        return -1;
    if (f1 != null && f2 == null)
        return 1;
    if (f1.equals(f2))
        return 0;
    return safeCompare(f1.toString(), f2.toString());
}