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

public static ArrayList<View> getViewsByTag(ViewGroup root, String tag) {
    ArrayList<View> views = new ArrayList<View>();
    final int childCount = root.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = root.getChildAt(i);
        if (child instanceof ViewGroup) {
            views.addAll(getViewsByTag((ViewGroup) child, tag));
        }// w  ww.  j a  va  2  s.  c  om

        final Object tagObj = child.getTag();
        if (tagObj != null && tagObj.equals(tag)) {
            views.add(child);
        }

    }
    return views;
}

From source file:Main.java

public static boolean isIn(Object obj, ArrayList list) {
    for (int i = 0; i < list.size(); i++) {
        if (obj.equals(list.get(i)))
            return true;
    }//www  .j  a  v  a 2  s  .  c  om

    return false;
}

From source file:Main.java

/**
 * Compare two objects using equals method. Additionally object are marked as
 * equals if both objects are nulls./*w w w .  j a  v a2  s  .c o m*/
 *
 * @param arg1 First object
 * @param arg2 Second object
 * @return True is objects are the same, otherwise returns false
 */
public static boolean areObjectsEquals(Object arg1, Object arg2) {
    if (arg1 != null) {
        return arg1.equals(arg2);
    } else {
        return arg2 == null;
    }
}

From source file:Main.java

public static boolean iteratesEqualSequence(Iterator<?> iter1, Iterator<?> iter2) {
    while (iter1.hasNext()) {

        if (!iter2.hasNext())
            return false;
        Object o1 = iter1.next();
        Object o2 = iter2.next();
        if (!o1.equals(o2))
            return false;

    }// ww  w .j  a  va2 s. c om

    if (iter2.hasNext())
        return false;

    return true;
}

From source file:Main.java

public static <T> void removeAll(List<? extends T> removeFrom, List<? super T> c2) {
    for (Object o : c2) {
        for (int i = 0; i < removeFrom.size(); i++) {
            if (o.equals(removeFrom.get(i))) {
                removeFrom.remove(i);// www  . j  av  a  2s.  c om
            }
        }
    }

}

From source file:Main.java

static boolean areObjectsEqual(Object obj1, Object obj2) {
    if (obj1 == null) {
        return obj2 == null;
    }/*from  ww  w.jav  a 2  s  .  com*/
    return obj1.equals(obj2);
}

From source file:Main.java

public static boolean isEqual(Object obj1, Object obj2) {
    if (obj1 == null) {
        return obj2 == null;
    }/*from w ww  . j  a va2 s.  co m*/
    return obj1.equals(obj2);
}

From source file:Main.java

static boolean jsonObjectContainsValue(JSONObject jsonObject, Object value) {
    @SuppressWarnings("unchecked")
    Iterator<String> keys = (Iterator<String>) jsonObject.keys();
    while (keys.hasNext()) {
        Object thisValue = jsonObject.opt(keys.next());
        if (thisValue != null && thisValue.equals(value)) {
            return true;
        }/*from ww w.  ja v a  2s .com*/
    }
    return false;
}

From source file:Main.java

/**
 * Convenience method for determining whether two objects are either
 * equal or both null./* w  w  w  .  ja v a  2 s  . com*/
 *
 * @param obj1 the first reference object to compare.
 * @param obj2 the second reference object to compare.
 * @return true if obj1 and obj2 are equal or if both are null,
 * false otherwise
 */
public static boolean equals(Object obj1, Object obj2) {
    return obj1 == null ? obj2 == null : obj1.equals(obj2);
}

From source file:Main.java

/**
 * Returns true iff l1 is a sublist of l (i.e., every member of l1 is in l,
 * and for every e1 < e2 in l1, there is an e1 < e2 occurrence in l).
 */// w  w  w  .  jav a  2 s.c o m
public static <T> boolean isSubList(List<T> l1, List<? super T> l) {
    Iterator<? super T> it = l.iterator();
    for (T o1 : l1) {
        if (!it.hasNext()) {
            return false;
        }
        Object o = it.next();
        while ((o == null && !(o1 == null)) || (o != null && !o.equals(o1))) {
            if (!it.hasNext()) {
                return false;
            }
            o = it.next();
        }
    }
    return true;
}