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:org.shept.util.BeanUtilsExtended.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static boolean isInstanceVisited(Collection coll, Object value) throws Exception {
    for (Iterator<?> it = coll.iterator(); it.hasNext();) {
        Object v = it.next();
        if (v.equals(value)) {
            return true;
        }/*w ww  .j a v  a 2s  .  co  m*/
    }
    // sometimes ConcurrentModificationExceptions here
    coll.add(value);
    return false;
}

From source file:me.xhh.utils.Util.java

/**
 * Compare two objects without needing of checking <code>null</code>.
 * //from  ww w .  jav a  2  s.co m
 * @param a
 *            the first object to compare with
 * @param b
 *            the second object to compare with
 * @return <code>true</code> if both <code>a</code> and <code>b</code> are <code>null</code>, or <code>a.equals(b)</code> is
 *         <code>true</code>. Otherwise <code>false</code>.
 * @see #notEqual(Object, Object)
 */
public static boolean isEqual(Object a, Object b) {
    return a == null ? (b == null) : a.equals(b);
}

From source file:edu.cornell.kfs.sys.util.RestXmlUtil.java

protected static Object populateBusinessObject(DataObjectEntry doe, Map<?, ?> m) {
    Object bo = ObjectUtils.createNewObjectFromClass(doe.getDataObjectClass());
    PersistenceStructureService persistenceStructureService = SpringContext
            .getBean(PersistenceStructureService.class);

    for (Object key : m.keySet()) {
        String propertyName = (String) key;
        Class<?> propertyType = ObjectUtils.getPropertyType(bo, propertyName, persistenceStructureService);

        if (propertyType != null) {
            try {
                Object propertyValue = m.get(key);
                if (propertyValue != null && !propertyValue.equals("null")) {
                    String value = (String) propertyValue;
                    if (TypeUtils.isIntegralClass(propertyType)) {
                        propertyValue = Integer.parseInt(value);
                    } else if (TypeUtils.isDecimalClass(propertyType)) {
                        propertyValue = Float.parseFloat(value);
                    } else if (TypeUtils.isTemporalClass(propertyType)) {
                        propertyValue = KfsDateUtils.convertToSqlDate(DateUtils.parseDate(value, DATE_FORMAT));
                    } else if (TypeUtils.isBooleanClass(propertyType)) {
                        propertyValue = Boolean.parseBoolean(value);
                    }/*from  w  w  w .  j a v  a 2  s .co m*/
                } else {
                    propertyValue = null;
                }

                ObjectUtils.setObjectProperty(bo, propertyName, propertyValue);
            } catch (Exception ex) {
                LOG.error(ex);
            }
        }
    }

    return bo;
}

From source file:com.jigsforjava.util.ObjectUtils.java

public static boolean areEqual(Object object1, Object object2) {
    if (object1 == null) {
        return (object2 == null);
    } else if (object2 == null) {
        return false;
    }/*  ww  w.  j a  v  a  2 s  .com*/

    return object1.equals(object2);
}

From source file:Main.java

/**
 * Checks to see if an array contains an item. Works on unsorted arrays. If
 * the array is null this method will always return false. If the item is
 * null, will return true if the array contains a null entry, false
 * otherwise. In all other cases, item.equals() is used to determine
 * equality.//  w  w w.ja va  2s  . co m
 * 
 * @param arr
 *            the array to scan for the item.
 * @param item
 *            the item to be looked for
 * @return true if item is contained in the array, false otherwise
 */
public static boolean contains(Object[] arr, Object item) {
    if (arr == null)
        return false;

    for (int i = 0; i < arr.length; ++i) {
        if (item == null && arr[i] == null)
            return true;
        if (item != null && item.equals(arr[i]))
            return true;
    }

    return false;
}

From source file:Main.java

/**
 * Finds an item by iterating through the specified iterator.
 * //from w w w . ja va2s  .  co m
 * @param item the object to find
 * @param iter the iterator to examine
 * @return list index of the item or -1 if the item was not found
 */
public static int findObject(Object item, ListIterator<?> iter) {
    while (iter.hasNext()) {
        Object o = iter.next();
        if (item == null ? o == null : item.equals(o)) {
            return iter.previousIndex();
        }
    }
    return -1;
}

From source file:Main.java

/**
 * Checks if the input Objects are Non NULL and Equal
 *///from  w ww. j a  v  a  2s . c o  m

public static boolean areNonNullAndEqual(Object obj1, Object obj2)

{

    if ((obj1 == null) || (obj2 == null))

        return false;

    return obj1.equals(obj2);

}

From source file:com.aw.support.beans.BeanUtils.java

public static boolean equals(Object value1, Object value2) {
    if (value1 == null && value2 == null)
        return true;
    if (value1 != null)
        return value1.equals(value2);
    else//from  w  w  w.j  av a  2s. co  m
        return value2.equals(value1);
}

From source file:com.p000ison.dev.copybooks.util.Helper.java

public static ArrayList<String> fromJSONStringtoList(String key, String string) {

    if (string != null && !string.isEmpty()) {
        ArrayList<String> out = new ArrayList<String>();

        JSONObject flags = (JSONObject) JSONValue.parse(string);

        if (flags != null) {
            for (Object keys : flags.keySet()) {
                try {

                    if (keys.equals(key)) {
                        JSONArray list = (JSONArray) flags.get(keys);

                        if (list != null) {
                            for (Object k : list) {
                                out.add(k.toString());
                            }//from   w  ww.ja  v a2s  .  co  m
                        }
                    }

                } catch (Exception ex) {
                    CopyBooks.debug(String.format("Failed reading flag: %s", keys));
                    CopyBooks.debug(String.format("Value: %s", flags.get(key)));
                    CopyBooks.debug(null, ex);
                }
            }
        }
        return out;
    }
    return null;
}

From source file:Main.java

/**
 * For a list of Map find the entry that best matches the fieldsByPriority Ordered Map; null field values in a Map
 * in mapList match against any value but do not contribute to maximal match score, otherwise value for each field
 * in fieldsByPriority must match for it to be a candidate.
 *//*from  www .j a v a  2  s.  c o m*/
public static Map<String, Object> findMaximalMatch(List<Map<String, Object>> mapList,
        LinkedHashMap<String, Object> fieldsByPriority) {
    int numFields = fieldsByPriority.size();
    String[] fieldNames = new String[numFields];
    Object[] fieldValues = new Object[numFields];
    int index = 0;
    for (Map.Entry<String, Object> entry : fieldsByPriority.entrySet()) {
        fieldNames[index] = entry.getKey();
        fieldValues[index] = entry.getValue();
        index++;
    }

    int highScore = -1;
    Map<String, Object> highMap = null;
    for (Map<String, Object> curMap : mapList) {
        int curScore = 0;
        boolean skipMap = false;
        for (int i = 0; i < numFields; i++) {
            String curField = fieldNames[i];
            Object compareValue = fieldValues[i];
            // if curMap value is null skip field (null value in Map means allow any match value
            Object curValue = curMap.get(curField);
            if (curValue == null)
                continue;
            // if not equal skip Map
            if (!curValue.equals(compareValue)) {
                skipMap = true;
                break;
            }
            // add to score based on index (lower index higher score), also add numFields so more fields matched weights higher
            curScore += (numFields - i) + numFields;
        }

        if (skipMap)
            continue;
        // have a higher score?
        if (curScore > highScore) {
            highScore = curScore;
            highMap = curMap;
        }
    }

    return highMap;
}