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

/**
 * Answer the junction between a and b. Answer is of the same type as a.
 * //ww  w  .ja  va2 s.c  o  m
 * @param a
 * @param b
 * @return
 */
public static Collection junction(Collection a, Collection b) {
    Collection answer = createCollection(a);
    for (Iterator i = a.iterator(); i.hasNext();) {
        Object oa = i.next();
        for (Iterator k = b.iterator(); k.hasNext();) {
            Object ob = k.next();
            if (oa.equals(ob)) {
                answer.add(oa);
            }
        }
    }
    return answer;
}

From source file:Main.java

public static boolean contains(Iterator<?> iteratorToCheck, Object item) {
    while (iteratorToCheck.hasNext()) {
        Object o = iteratorToCheck.next();
        if (o == null ? item == null : o.equals(item)) {
            return true;
        }//www.  j ava  2  s.  c  om
    }
    return false;
}

From source file:Main.java

public static boolean equals(List list1, List list2) {
    if (list1 == null && list2 == null) {
        // both are null
        return true;
    }/* www .  j ava  2  s .  c om*/

    if (list1 == null || list2 == null) {
        // we know both aren't null, so if one is null them obviously false
        return false;
    }

    if (list1.size() != list2.size()) {
        return false;
    }

    if (list1.isEmpty() && list2.isEmpty()) {
        return true;
    }

    for (Object item1 : list1) {
        boolean exists = false;
        for (Object item2 : list2) {
            if (item1.equals(item2)) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            return false;
        }
    }

    return true;
}

From source file:com.apptentive.android.sdk.util.JsonDiffer.java

private static boolean isEmpty(Object value) {
    return value == null || value.equals("");
}

From source file:com.mocha.bsm.bizsm.db4otemplate.util.ObjectUtils.java

/**
 * Determine if the given objects are equal, returning true if both are null
 * or false if only one is null.//w w  w.  j a v  a  2 s. c  o m
 * @param o1 first Object to compare
 * @param o2 second Object to compare
 * @return whether the given objects are equal
 */
public static boolean nullSafeEquals(Object o1, Object o2) {
    return (o1 == o2 || (o1 != null && o1.equals(o2)));
}

From source file:DefaultParameterizedType.java

static boolean eq(Object a, Object b) {
    if ((a == null) != (b == null))
        return false;
    if (a != null && !a.equals(b))
        return false;
    return true;//w w w  .java2s . c  o m
}

From source file:harschware.collections.containers.Pair.java

public static final boolean equal(Object o1, Object o2) {
    if (o1 == null) {
        return o2 == null;
    }//from  www. j av a 2s. co  m
    return o1.equals(o2);
}

From source file:Main.java

public static boolean contains(Object[] array, Object value) {
    if (array == null) {
        return false;
    }//from w w w.j  ava 2  s.co m
    for (Object object : array) {
        if (object == null) {
            if (value == null) {
                return true;
            }
        } else if (object.equals(value)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

private static boolean objectEquals(Object obj1, Object obj2) {
    if (obj1 == null && obj2 == null)
        return true;
    if (obj1 == null || obj2 == null)
        return false;
    else// w  w  w  .  jav  a  2  s  .c  o m
        return obj1.equals(obj2);
}

From source file:Main.java

/**
 * Checks if passed objects are equal. /*w  w  w . j  ava  2s .  c o m*/
 * 
 * @param o1 {@link Object}
 * @param o2 {@link Object}
 * @return true if equal
 */
public static boolean safeEquals(Object o1, Object o2) {
    if (o1 == null && o2 == null)
        return true;
    if (o1 == null || o2 == null)
        return false;
    return o1.equals(o2);
}