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 boolean contains(final Object[] array, final Object[] values) {
    if (array == null || values == null)
        return false;
    for (final Object item : array) {
        for (final Object value : values) {
            if (item == null || value == null) {
                if (item == value)
                    return true;
                continue;
            }/*from   w  w w  . ja v a  2  s. com*/
            if (item.equals(value))
                return true;
        }
    }
    return false;
}

From source file:com.bstek.dorado.view.output.OutputUtils.java

/**
 * ?//from w  w  w. j a v  a 2s .  c o  m
 * 
 * @param value
 *            
 * @param escapeValue
 *            
 * @return ?
 */
public static boolean isEscapeValue(Object value, Object escapeValue) {
    if (value != escapeValue) {
        if (ESCAPE_VALUE.equals(escapeValue)) {
            return (value == null || (value instanceof String && value.equals(""))
                    || (value instanceof Number && ((Number) value).doubleValue() == 0)
                    || (value instanceof Boolean && !((Boolean) value).booleanValue())
                    || (value instanceof Collection<?> && ((Collection<?>) value).isEmpty())
                    || (value instanceof Ignorable && ((Ignorable) value).isIgnored()));
        } else if (IGNORE_VALUE.equals(escapeValue)) {
            return true;
        }
        return String.valueOf(value).equals(String.valueOf(escapeValue));
    }
    return true;
}

From source file:com.autobizlogic.abl.logic.LogicSvcs.java

/**
 * Determine whether the given attribute has changed between the current state and the old state.
 * @param aChildLogicRunner/*from w w  w . j ava2s  .c  om*/
 * @param anAttributeName
 * @return true if anAttributeName's value changed from aChildLogicRunner's current/priorDomainObject
 */
public static boolean isAttributeChanged(LogicRunner aChildLogicRunner, String anAttributeName) {
    PersistentBean priorDomainObject = aChildLogicRunner.getPriorDomainObject();
    if (priorDomainObject == null) {
        throw new RuntimeException("Attempted to compare old and new state, but there is no old state.");
    }
    Object oldValue = priorDomainObject.get(anAttributeName);

    PersistentBean currentDomainObject = aChildLogicRunner.getCurrentDomainObject();
    if (currentDomainObject == null) {
        throw new RuntimeException("Attempted to compare old and new state, but there is no new state.");
    }
    Object currentValue = currentDomainObject.get(anAttributeName);

    if (currentValue == null && oldValue == null)
        return false;

    if (currentValue == null || oldValue == null)
        return true;

    return !currentValue.equals(oldValue);
}

From source file:Main.java

/**
 * Check if the list contains the member. For objects, it uses standard .equals() method. 
 * For strings, it compares but ignores the case.
 * /*from  w  w w. ja v a 2s . c  o  m*/
 * @param list
 * @param member
 * @return
 */

public static boolean contains(List<? extends Object> list, Object member) {
    if (list.isEmpty() || member == null)
        return false;

    for (Object obj : list) {
        if (obj instanceof String && member instanceof String) {
            if (compareIgnoreCase((String) obj, (String) member))
                return true;
        } else {
            if (member.equals(obj))
                return true;
        }
    }

    return false;
}

From source file:com.parse.ParsePushControllerTest.java

private static boolean containsString(JSONArray array, String value) throws JSONException {
    for (int i = 0; i < array.length(); i++) {
        Object element = array.get(i);
        if (element instanceof String && element.equals(value)) {
            return true;
        }/*from   ww w  .j  ava 2s .co m*/
    }
    return false;
}

From source file:Main.java

/**
 * Counts how often the given Object occurs in the given
 * collection using equals() for comparison.
 *
 * @param c collection in which to search
 * @param o object to search/*from w  w  w .j ava2 s .  com*/
 * @return frequency
 * @since Ant 1.8.0
 */
public static int frequency(Collection<?> c, Object o) {
    // same as Collections.frequency introduced with JDK 1.5
    int freq = 0;
    if (c != null) {
        for (Iterator<?> i = c.iterator(); i.hasNext();) {
            Object test = i.next();
            if (o == null ? test == null : o.equals(test)) {
                freq++;
            }
        }
    }
    return freq;
}

From source file:Main.java

/**
 *  Basic find for small arrays of Object.
 *//*from   www .  ja  v a2 s.  co  m*/
public static int find(Object[] array, Object object) {

    for (int i = 0; i < array.length; i++) {
        if (array[i] == object) {

            // hadles both nulls
            return i;
        }

        if (object != null && object.equals(array[i])) {
            return i;
        }
    }

    return -1;
}

From source file:Main.java

/**
 Equals for possibly-<tt>null</tt> object field.
        /*from w  w  w . jav  a2  s  .co m*/
 <P><em>Does not include arrays</em>. (This restriction will likely be removed in a future version.)
 */
static public boolean areEqual(Object aThis, Object aThat) {

    if (isArray(aThis) || isArray(aThat)) {

        throw new IllegalArgumentException("This method does not currently support arrays.");
    }

    return (aThis == null) ? (aThat == null) : aThis.equals(aThat);
}

From source file:IteratorUtils.java

public static boolean equivalent(Iterator ii, Iterator jj) {
    while (true) {
        boolean ii_hasnext = ii.hasNext();
        boolean jj_hasnext = jj.hasNext();
        if (ii_hasnext ^ jj_hasnext)
            return false;
        else if (ii_hasnext) {
            Object iiNext = ii.next();
            Object jjNext = jj.next();
            if (iiNext == jjNext)
                continue;
            else if (iiNext == null)
                return false;
            else if (!iiNext.equals(jjNext))
                return false;
        } else// w ww  .ja  v  a 2  s .c o m
            return true;
    }
}

From source file:com.jaspersoft.jasperserver.api.metadata.user.service.impl.ProfileAttributeServiceImpl.java

public static boolean equalsWithNull(Object o1, Object o2) {
    return (o1 == null && o2 == null) || (o1 != null && o1.equals(o2));
}