List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:org.jaffa.soa.dataaccess.TransformerUtils.java
/** * Same as printGraph(Object source), except the objectStack lists all the parent * objects its printed, and if this is one of them, it stops. This allows detection * of possible infinite recusion./*from w w w . j a v a2s .com*/ * * @param source Javabean who's contents should be printed * @param objectStack List of objects already traversed * @return multi-line string of this beans properties and their values */ public static String printGraph(Object source, List objectStack) { if (source == null) return null; // Prevent infinite object recursion if (objectStack != null) if (objectStack.contains(source)) return "Object Already Used. " + source.getClass().getName() + '@' + source.hashCode(); else objectStack.add(source); else { objectStack = new ArrayList(); objectStack.add(source); } StringBuffer out = new StringBuffer(); out.append(source.getClass().getName()); out.append("\n"); try { BeanInfo sInfo = Introspector.getBeanInfo(source.getClass()); PropertyDescriptor[] sDescriptors = sInfo.getPropertyDescriptors(); if (sDescriptors != null && sDescriptors.length != 0) for (int i = 0; i < sDescriptors.length; i++) { PropertyDescriptor sDesc = sDescriptors[i]; Method sm = sDesc.getReadMethod(); if (sm != null && sDesc.getWriteMethod() != null) { if (!sm.isAccessible()) sm.setAccessible(true); Object sValue = sm.invoke(source, (Object[]) null); out.append(" "); out.append(sDesc.getName()); if (source instanceof GraphDataObject) { if (((GraphDataObject) source).hasChanged(sDesc.getName())) out.append('*'); } out.append('='); if (sValue == null) out.append("<--NULL-->\n"); else if (sm.getReturnType().isArray() && !sm.getReturnType().getComponentType().isPrimitive()) { StringBuffer out2 = new StringBuffer(); out2.append("Array of "); out2.append(sm.getReturnType().getComponentType().getName()); out2.append("\n"); // Loop through array Object[] a = (Object[]) sValue; for (int j = 0; j < a.length; j++) { out2.append('['); out2.append(j); out2.append("] "); if (a[j] == null) out2.append("<--NULL-->"); else if (GraphDataObject.class.isAssignableFrom(a[j].getClass())) out2.append(((GraphDataObject) a[j]).toString(objectStack)); else //out2.append(StringHelper.linePad(a[j].toString(), 4, " ",true)); out2.append(a[j].toString()); } out.append(StringHelper.linePad(out2.toString(), 4, " ", true)); } else { if (GraphDataObject.class.isAssignableFrom(sValue.getClass())) out.append(StringHelper.linePad(((GraphDataObject) sValue).toString(objectStack), 4, " ", true)); else { out.append(StringHelper.linePad(sValue.toString(), 4, " ", true)); out.append("\n"); } } } } } catch (IllegalAccessException e) { TransformException me = new TransformException(TransformException.ACCESS_ERROR, "???", e.getMessage()); log.error(me.getLocalizedMessage(), e); //throw me; } catch (InvocationTargetException e) { TransformException me = new TransformException(TransformException.INVOCATION_ERROR, "???", e); log.error(me.getLocalizedMessage(), me.getCause()); //throw me; } catch (IntrospectionException e) { TransformException me = new TransformException(TransformException.INTROSPECT_ERROR, "???", e.getMessage()); log.error(me.getLocalizedMessage(), e); //throw me; } return out.toString(); }
From source file:org.apache.ojb.odmg.collections.DListImpl.java
public int hashCode() { int hashCode = 1; Iterator it = elements.iterator(); while (it.hasNext()) { Object obj = it.next(); hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); }// www . j a v a2 s . c o m return hashCode; }
From source file:com.kdmanalytics.toif.assimilator.XMLNode.java
public boolean equals(Object o) { if (!(o instanceof XMLNode)) return false; if (o.hashCode() == hashCode()) return true; return false; }
From source file:org.jabsorb.client.Client.java
/** * This method is public because of the inheritance from the * InvokationHandler -- should never be called directly. *//*from w w w . j a v a 2 s. c o m*/ public Object invoke(Object proxyObj, Method method, Object[] args) throws Exception { String methodName = method.getName(); if (methodName.equals("hashCode")) { return new Integer(System.identityHashCode(proxyObj)); } else if (methodName.equals("equals")) { return (proxyObj == args[0] ? Boolean.TRUE : Boolean.FALSE); } else if (methodName.equals("toString")) { return proxyObj.getClass().getName() + '@' + Integer.toHexString(proxyObj.hashCode()); } return invoke(proxyMap.getString(proxyObj), method.getName(), args, method.getReturnType()); }
From source file:org.jactr.core.slot.DefaultConditionalSlot.java
public boolean matchesCondition(Object test) { if (test instanceof ISlot) test = ((ISlot) test).getValue(); if (LOGGER.isDebugEnabled()) { StringBuffer sb = new StringBuffer("Test value : "); sb.append(test);/* w w w .j a va 2s.c om*/ if (test != null) { sb.append(", "); sb.append(test.getClass().getName()); sb.append(", "); sb.append(test.hashCode()); } LOGGER.debug(sb.toString()); sb.delete(0, sb.length()); sb.append("Cond value : "); Object tmp = getValue(); sb.append(tmp); if (tmp != null) { sb.append(", "); sb.append(tmp.getClass().getName()); sb.append(", "); sb.append(tmp.hashCode()); } LOGGER.debug(sb.toString()); } boolean rtn = false; try { switch (_condition) { case EQUALS: rtn = equalValues(test); break; case LESS_THAN: rtn = lessThan(test); break; case LESS_THAN_EQUALS: rtn = equalValues(test) | lessThan(test); break; case GREATER_THAN: rtn = greaterThan(test); break; case GREATER_THAN_EQUALS: rtn = equalValues(test) | greaterThan(test); break; case NOT_EQUALS: rtn = !equalValues(test); break; case WITHIN: rtn = within(test); break; } } catch (Exception e) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Unknown failure comparing " + this + " with " + test, e); } if (LOGGER.isDebugEnabled()) LOGGER.debug("matchesCondition " + this + " " + test + " : " + rtn); return rtn; }
From source file:com.music.util.cache.CacheKeyGenerator.java
@Override public Object generate(Object target, Method method, Object... params) { StringBuilder key = new StringBuilder(); key.append(target.getClass().getSimpleName()).append(".").append(method.getName()).append(":"); if (params.length == 0) { key.append(NO_PARAM_KEY).toString(); }//from w w w .j a v a2 s . c o m for (Object param : params) { if (param == null) { key.append(NULL_PARAM_KEY); } else if (ClassUtils.isPrimitiveOrWrapper(param.getClass()) || param instanceof String) { key.append(param); } else if (param instanceof CacheKey) { key.append(((CacheKey) param).getCacheKey()); } else { logger.warn("Using object " + param + " as cache key. Either use key='..' or implement CacheKey. Method is " + target.getClass() + "#" + method.getName()); key.append(param.hashCode()); } } return key.toString(); }
From source file:org.springmodules.util.ObjectsTests.java
/** * Asserts that the given hash code is equal to the one obtained from * <code>{@link Objects#nullSafeHashCode(Object)}</code>. * /*from ww w . j a v a2 s .c om*/ * @param expected * the expected hash code. * @param array * the array of primitives. */ private void assertEqualHashCodes(int expected, Object array) { int actual = Objects.nullSafeHashCode(array); assertEquals(expected, actual); assertTrue(array.hashCode() != actual); }
From source file:org.t2framework.commons.util.ArrayMap.java
public boolean containsKey(final Object key) { Entry<K, V>[] tbl = mapTable;/*from w w w . ja v a 2 s . c o m*/ if (key != null) { int hashCode = key.hashCode(); int index = (hashCode & 0x7FFFFFFF) % tbl.length; for (Entry<K, V> e = tbl[index]; e != null; e = e.next_) { if (e.hashCode_ == hashCode && key.equals(e.key_)) { return true; } } } else { for (Entry<K, V> e = tbl[0]; e != null; e = e.next_) { if (e.key_ == null) { return true; } } } return false; }
From source file:org.t2framework.commons.util.ArrayMap.java
public V get(final Object key) { Entry<K, V>[] tbl = mapTable;/*from w w w . j a va 2 s . c om*/ if (key != null) { int hashCode = key.hashCode(); int index = (hashCode & 0x7FFFFFFF) % tbl.length; for (Entry<K, V> e = tbl[index]; e != null; e = e.next_) { if (e.hashCode_ == hashCode && key.equals(e.key_)) { return e.value_; } } } else { for (Entry<K, V> e = tbl[0]; e != null; e = e.next_) { if (e.key_ == null) { return e.value_; } } } return null; }
From source file:org.cloudgraph.store.lang.DefaultAssembler.java
/** * Creates a unique mappable key using the qualified type name and all key * property values from the given row.//from w w w . j a va 2s . c o m * * @param type * the type * @param row * the data values * @return the key */ protected int createHashKey(PlasmaType type, List<PropertyPair> row) { PropertyPair[] pairs = new PropertyPair[row.size()]; row.toArray(pairs); Arrays.sort(pairs, this.nameComparator); int pkHash = type.getQualifiedName().hashCode(); int fallBackHash = type.getQualifiedName().hashCode(); int pks = 0; for (int i = 0; i < pairs.length; i++) { Object value = pairs[i].getValue(); if (value == null) { log.warn("null voue for property, " + pairs[i].getProp().toString()); continue; } if (pairs[i].getProp().isKey(KeyType.primary)) { pkHash = pkHash ^ value.hashCode(); fallBackHash = fallBackHash ^ value.hashCode(); pks++; } else { fallBackHash = fallBackHash ^ value.hashCode(); } } if (pks > 0) { List<Property> pkProps = type.findProperties(KeyType.primary); if (pkProps.size() == pks) return pkHash; } return fallBackHash; }