List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:Main.java
public static int hashCode(Object paramObject) { int i = 1;/*ww w . j av a 2s. c om*/ Field[] arrayOfField = paramObject.getClass().getDeclaredFields(); int j = arrayOfField.length; for (int k = 0;; k++) { int m; int i1; if (k < j) { Field localField = arrayOfField[k]; localField.setAccessible(true); try { Object localObject = localField.get(paramObject); m = i * 31; if (localObject == null) { i1 = 0; } else { int n = localObject.hashCode(); i1 = n; } } catch (IllegalArgumentException localIllegalArgumentException) { localIllegalArgumentException.printStackTrace(); continue; } catch (IllegalAccessException localIllegalAccessException) { localIllegalAccessException.printStackTrace(); continue; } } else { return i; } i = m + i1; } }
From source file:org.hyperic.hq.plugin.appha.VSphereConnection.java
private static String address(Object obj) { if (obj == null) { return "@NULL"; }//www.j av a2 s . c om return "@" + Integer.toHexString(obj.hashCode()); }
From source file:net.darkmist.clf.LogEntry.java
private static int nullSafeHashCode(Object o) { if (o == null) return 0; return o.hashCode(); }
From source file:ObjectUtils.java
/** * <p>Gets the hash code of an object returning zero when the * object is <code>null</code>.</p> * * <pre>// w w w . j a v a2 s . co m * ObjectUtils.hashCode(null) = 0 * ObjectUtils.hashCode(obj) = obj.hashCode() * </pre> * * @param obj the object to obtain the hash code of, may be <code>null</code> * @return the hash code of the object, or zero if null * @since 2.1 */ public static int hashCode(Object obj) { return (obj == null) ? 0 : obj.hashCode(); }
From source file:Main.java
/** Hash code for an Object./*from www .j a v a2 s . c om*/ <P><tt>aObject</tt> is a possibly-null object field, and possibly an array. If <tt>aObject</tt> is an array, then each element may be a primitive or a possibly-null object. */ public static int hash(int aSeed, Object aObject) { int result = aSeed; if (aObject == null) { result = hash(result, 0); } else if (!isArray(aObject)) { result = hash(result, aObject.hashCode()); } else { int length = Array.getLength(aObject); for (int idx = 0; idx < length; ++idx) { Object item = Array.get(aObject, idx); //recursive call! result = hash(result, item); } } return result; }
From source file:com.turbospaces.spaces.RemoteJSpace.java
private static Address determineDestination(final Address[] addresses, final Object key) { int index = (key.hashCode() & Integer.MAX_VALUE) % addresses.length; return addresses[index]; }
From source file:org.grails.plugin.platform.events.ListenerId.java
public static ListenerId build(String namespace, String topic, Object target, Method callback) { return new ListenerId(namespace, topic, target.getClass().getName(), callback.getName(), Integer.toString(target.hashCode())); }
From source file:BeanUtility.java
/** This method takes a JavaBean and generates a standard toString() type result for it. * @param o JavaBean object to stringinate * @return STRINGIATION! Stringingating the countryside. Stringinating all the peasants. *//*www . ja v a2 s . c o m*/ public static String beanToString(Object o) { StringBuffer result = new StringBuffer(); if (o == null) return "--- null"; result.append("--- begin"); result.append(o.getClass().getName()); result.append(" hash: "); result.append(o.hashCode()); result.append("\r\n"); try { PropertyDescriptor[] pds = Introspector.getBeanInfo(o.getClass()).getPropertyDescriptors(); for (int pdi = 0; pdi < pds.length; pdi++) { try { result.append( "Property: " + pds[pdi].getName() + " Value: " + pds[pdi].getReadMethod().invoke(o)); } catch (IllegalAccessException iae) { result.append("Property: " + pds[pdi].getName() + " (Illegal Access to Value) "); } catch (InvocationTargetException iae) { result.append( "Property: " + pds[pdi].getName() + " (InvocationTargetException) " + iae.toString()); } catch (Exception e) { result.append("Property: " + pds[pdi].getName() + " (Other Exception )" + e.toString()); } result.append("\r\n"); } } catch (IntrospectionException ie) { result.append("Introspection Exception: " + ie.toString()); result.append("\r\n"); } result.append("--- end "); result.append(o.getClass().getName()); result.append(" hash: "); result.append(o.hashCode()); result.append("\n"); return result.toString(); }
From source file:org.apache.spark.network.util.JavaUtils.java
/** Returns a hash consistent with Spark's Utils.nonNegativeHash(). */ public static int nonNegativeHash(Object obj) { if (obj == null) { return 0; }/*from w ww.j a v a2s . c o m*/ int hash = obj.hashCode(); return hash != Integer.MIN_VALUE ? Math.abs(hash) : 0; }
From source file:com.espertech.esper.util.ThreadLogUtil.java
private static void write(String text, Object... objects) { StringBuilder buf = new StringBuilder(); buf.append(text);//from ww w. j a v a2 s . c o m buf.append(' '); for (Object obj : objects) { if ((obj instanceof String) || (obj instanceof Number)) { buf.append(obj.toString()); } else { buf.append(obj.getClass().getSimpleName()); buf.append('@'); buf.append(Integer.toHexString(obj.hashCode())); } buf.append(' '); } write(buf.toString()); }