List of usage examples for java.lang Object equals
public boolean equals(Object obj)
From source file:com.segment.analytics.internal.Utils.java
/** * Wraps the given object if necessary. {@link JSONObject#wrap(Object)} is only available on API * 19+, so we've copied the implementation. Deviates from the original implementation in * that it always returns {@link JSONObject#NULL} instead of {@code null} in case of a failure, * and returns the {@link Object#toString} of any object that is of a custom (non-primitive or * non-collection/map) type.//from w w w .ja va 2 s .com * * <p>If the object is null or , returns {@link JSONObject#NULL}. * If the object is a {@link JSONArray} or {@link JSONObject}, no wrapping is necessary. * If the object is {@link JSONObject#NULL}, no wrapping is necessary. * If the object is an array or {@link Collection}, returns an equivalent {@link JSONArray}. * If the object is a {@link Map}, returns an equivalent {@link JSONObject}. * If the object is a primitive wrapper type or {@link String}, returns the object. * Otherwise returns the result of {@link Object#toString}. * If wrapping fails, returns JSONObject.NULL. */ private static Object wrap(Object o) { if (o == null) { return JSONObject.NULL; } if (o instanceof JSONArray || o instanceof JSONObject) { return o; } if (o.equals(JSONObject.NULL)) { return o; } try { if (o instanceof Collection) { return new JSONArray((Collection) o); } else if (o.getClass().isArray()) { final int length = Array.getLength(o); JSONArray array = new JSONArray(); for (int i = 0; i < length; ++i) { array.put(wrap(Array.get(array, i))); } return array; } if (o instanceof Map) { //noinspection unchecked return toJsonObject((Map) o); } if (o instanceof Boolean || o instanceof Byte || o instanceof Character || o instanceof Double || o instanceof Float || o instanceof Integer || o instanceof Long || o instanceof Short || o instanceof String) { return o; } // Deviate from original implementation and return the String representation of the object // regardless of package. return o.toString(); } catch (Exception ignored) { } // Deviate from original and return JSONObject.NULL instead of null. return JSONObject.NULL; }
From source file:com.github.hateoas.forms.spring.xhtml.XhtmlResourceMessageConverter.java
private static Object getContentAsScalarValue(Object content) { Object value = null;//from w ww .j a v a 2 s .c om if (content == null) { value = NULL_VALUE; } else if (content instanceof String || content instanceof Number || content.equals(false) || content.equals(true)) { value = content; } return value; }
From source file:com.afeng.common.utils.reflection.MyBeanUtils.java
/** * MapkeyBean??BEAN/*from ww w. jav a 2s. c o m*/ * @param bean Object * @param properties Map * @throws IllegalAccessException * @throws java.lang.reflect.InvocationTargetException */ public static void copyMap2Bean(Object bean, Map properties) throws IllegalAccessException, InvocationTargetException { // Do nothing unless both arguments have been specified if ((bean == null) || (properties == null)) { return; } // Loop through the property name/value pairs to be set Iterator names = properties.keySet().iterator(); while (names.hasNext()) { String name = (String) names.next(); // Identify the property name and value(s) to be assigned if (name == null) { continue; } Object value = properties.get(name); try { Class clazz = PropertyUtils.getPropertyType(bean, name); if (null == clazz) { continue; } String className = clazz.getName(); if (className.equalsIgnoreCase("java.sql.Timestamp")) { if (value == null || value.equals("")) { continue; } } setProperty(bean, name, value); } catch (NoSuchMethodException e) { continue; } } }
From source file:Main.java
/** * Determine if <code>obj2</code> exists in <code>obj1</code>. * * <table borer="1">//from w w w .j a v a 2 s.c om * <tr> * <td>Type Of obj1</td> * <td>Comparison type</td> * </tr> * <tr> * <td>null<td> * <td>always return false</td> * </tr> * <tr> * <td>Map</td> * <td>Map containsKey(obj2)</td> * </tr> * <tr> * <td>Collection</td> * <td>Collection contains(obj2)</td> * </tr> * <tr> * <td>Array</td> * <td>there's an array element (e) where e.equals(obj2)</td> * </tr> * <tr> * <td>Object</td> * <td>obj1.equals(obj2)</td> * </tr> * </table> * * * @param obj1 * @param obj2 * @return */ public static boolean contains(Object obj1, Object obj2) { if ((obj1 == null) || (obj2 == null)) { //log.debug("obj1 or obj2 are null."); return false; } if (obj1 instanceof Map) { if (((Map) obj1).containsKey(obj2)) { //log.debug("obj1 is a map and contains obj2"); return true; } } if (obj1 instanceof Iterable) { Iterator iter = ((Iterable) obj1).iterator(); while (iter.hasNext()) { Object value = iter.next(); if (obj2.equals(value) || obj2.toString().equals(value)) { return true; } } } else if (obj1.getClass().isArray()) { for (int i = 0; i < Array.getLength(obj1); i++) { Object value = null; value = Array.get(obj1, i); if (obj2.equals(value)) { //log.debug("obj1 is an array and contains obj2"); return true; } } } else if (obj1.toString().equals(obj2.toString())) { //log.debug("obj1 is an object and it's String representation equals obj2's String representation."); return true; } else if (obj1.equals(obj2)) { //log.debug("obj1 is an object and equals obj2"); return true; } //log.debug("obj1 does not contain obj2: " + obj1 + ", " + obj2); return false; }
From source file:com.afeng.common.utils.reflection.MyBeanUtils.java
/** * MapkeyBean??BEAN//from w ww. ja v a 2 s.c o m * ? * @param bean Object * @param properties Map * @param defaultValue String * @throws IllegalAccessException * @throws java.lang.reflect.InvocationTargetException */ public static void copyMap2Bean(Object bean, Map properties, String defaultValue) throws IllegalAccessException, InvocationTargetException { // Do nothing unless both arguments have been specified if ((bean == null) || (properties == null)) { return; } // Loop through the property name/value pairs to be set Iterator names = properties.keySet().iterator(); while (names.hasNext()) { String name = (String) names.next(); // Identify the property name and value(s) to be assigned if (name == null) { continue; } Object value = properties.get(name); try { Class clazz = PropertyUtils.getPropertyType(bean, name); if (null == clazz) { continue; } String className = clazz.getName(); if (className.equalsIgnoreCase("java.sql.Timestamp")) { if (value == null || value.equals("")) { continue; } } if (className.equalsIgnoreCase("java.lang.String")) { if (value == null) { value = defaultValue; } } setProperty(bean, name, value); } catch (NoSuchMethodException e) { continue; } } }
From source file:com.evolveum.midpoint.util.MiscUtil.java
public static boolean equals(Object a, Object b) { if (a == null && b == null) { return true; }/*from w w w . ja v a 2 s . c o m*/ if (a == null || b == null) { return false; } return a.equals(b); }
From source file:edu.umass.cs.utils.Util.java
public static Object getRandomOtherThan(Set<?> all, Object exclude) { for (Object obj : all) if (!obj.equals(exclude)) return obj; return null;//w ww . j a v a 2 s . c o m }
From source file:com.medsphere.fileman.FMRecord.java
private static boolean valuesChanged(Object obj1, Object obj2) { return (obj1 == null) != (obj2 == null) || !(obj1 == null || obj1.equals(obj2)); }
From source file:com.afeng.common.utils.reflection.MyBeanUtils.java
/** * Map key/*from w w w . jav a2 s. com*/ * MapkeyBean??BEAN * @param bean Object * @param properties Map * @throws IllegalAccessException * @throws java.lang.reflect.InvocationTargetException */ public static void copyMap2Bean_Nobig(Object bean, Map properties) throws IllegalAccessException, InvocationTargetException { // Do nothing unless both arguments have been specified if ((bean == null) || (properties == null)) { return; } // Loop through the property name/value pairs to be set Iterator names = properties.keySet().iterator(); while (names.hasNext()) { String name = (String) names.next(); // Identify the property name and value(s) to be assigned if (name == null) { continue; } Object value = properties.get(name); name = name.toLowerCase(); try { Class clazz = PropertyUtils.getPropertyType(bean, name); if (null == clazz) { continue; } String className = clazz.getName(); if (className.equalsIgnoreCase("java.sql.Timestamp")) { if (value == null || value.equals("")) { continue; } } setProperty(bean, name, value); } catch (NoSuchMethodException e) { continue; } } }
From source file:com.gtx.cooliris.imagecache.ImageWorker.java
/** * Returns true if the current work has been canceled or if there was no work in * progress on this image view.//from www. j a va 2 s. com * Returns false if the work in progress deals with the same data. The work is not * stopped in that case. */ public static boolean cancelPotentialWork(Object data, IAsyncImageView imageView) { final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); if (bitmapWorkerTask != null) { final Object bitmapData = bitmapWorkerTask.data; if (bitmapData == null || !bitmapData.equals(data)) { bitmapWorkerTask.cancel(true); // Add by liulin // Cancel the HTTP connection //bitmapWorkerTask.cancelConnection(); if (BuildConfig.DEBUG) { LogUtil.d(TAG, "cancelPotentialWork - cancelled work for " + data); } } else { // The same work is already in progress. return false; } } return true; }