List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:org.apache.axis2.context.OldMessageContext.java
/** * Set up a unique key in the form of/*from w w w. ja v a 2 s. c o m*/ * <OL> * <LI>the class name for the class that owns the key * <LI>delimitor * <LI>the key as a string * <LI>delimitor * <LI>the key's hash code as a string * </OL> * * @param clazz The class that owns the supplied key * @param key The key * @return A string key */ private String generateSelfManagedDataKey(Class<?> clazz, Object key) { return clazz.getName() + selfManagedDataDelimiter + key.toString() + selfManagedDataDelimiter + Integer.toString(key.hashCode()); }
From source file:ponzu.impl.test.Verify.java
/** * Assert that <code>objectA</code> and <code>objectB</code> are equal (via the {@link Object#equals(Object)} method, * and that they both return the same {@link Object#hashCode()}. *//*ww w .j a v a2 s . co m*/ public static void assertEqualsAndHashCode(String itemNames, Object objectA, Object objectB) { try { if (objectA == null || objectB == null) { Assert.fail("Neither item should be null: <" + objectA + "> <" + objectB + '>'); return; } Assert.assertFalse("Neither item should equal null", objectA.equals(null)); Assert.assertFalse("Neither item should equal null", objectB.equals(null)); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectA, objectA); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectB, objectB); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectA, objectB); Assert.assertEquals("Expected " + itemNames + " to be equal.", objectB, objectA); Assert.assertEquals("Expected " + itemNames + " to have the same hashCode().", objectA.hashCode(), objectB.hashCode()); } catch (AssertionError e) { throwMangledException(e); } }
From source file:HashCodeAssist.java
/** * <p>//from w w w . j a v a 2s .c o m * Append a <code>hashCode</code> for an <code>Object</code>. * </p> * * @param object * the Object to add to the <code>hashCode</code> * @return this */ public HashCodeAssist append(Object object) { if (object == null) { iTotal = iTotal * iConstant; } else { // 'Switch' on type of array, to dispatch to the correct handler // This handles multi dimensional arrays if (object instanceof long[]) { append((long[]) object); } else if (object instanceof int[]) { append((int[]) object); } else if (object instanceof short[]) { append((short[]) object); } else if (object instanceof char[]) { append((char[]) object); } else if (object instanceof byte[]) { append((byte[]) object); } else if (object instanceof double[]) { append((double[]) object); } else if (object instanceof float[]) { append((float[]) object); } else if (object instanceof boolean[]) { append((boolean[]) object); } else if (object instanceof Object[]) { // Not an array of primitives append((Object[]) object); } else { iTotal = iTotal * iConstant + object.hashCode(); } } return this; }
From source file:iristk.flow.FlowCompiler.java
private void printStates(List<iristk.xml.flow.State> states) throws FlowCompilerException { for (iristk.xml.flow.State state : states) { currentState = state.getId();/* w w w.jav a 2s . com*/ String ext = "State"; if (state.getExtends() != null) { ext = state.getExtends(); } code.println(); String decl = ""; if (state.isPublic() || flowXml.getInitial().equals(state.getId())) { decl += "public"; } else { decl += "private"; } if (state.isStatic()) { decl += " static"; } decl += " class " + currentState + " extends " + ext; if (flowXml.getInitial() != null && flowXml.getInitial().equals(state.getId())) { decl += " implements Initial"; } code.println(decl + " {"); code.println(); code.println("final State currentState = this;"); if (state.getParam() != null) { printParameters(state.getParam()); } if (state.getVar() != null) { printVariables(state.getVar()); code.println(); } code.println("@Override"); code.println("public void setFlowThread(FlowRunner.FlowThread flowThread) {"); code.println("super.setFlowThread(flowThread);"); for (Object trigger : state.getTrigger()) { if (trigger instanceof Ontime) { Ontime ontime = (Ontime) trigger; String interval = ontime.getInterval(); if (interval != null) { if (interval.contains(",")) {// new usage, in case dev wants to have e.g "x , 400-x" //Assuming interval is now well-formed and resolves to (int, int) code.println("flowThread.addEventClock(" + interval + ", \"timer_" + trigger.hashCode() + "\");"); } else if (interval.contains("-")) { String[] cols = interval.split("-"); try { int min = Integer.parseInt(cols[0]); int max = Integer.parseInt(cols[1]); code.println("flowThread.addEventClock(" + min + ", " + max + ", \"timer_" + trigger.hashCode() + "\");"); } catch (NumberFormatException e) {//In case developer uses variable names instead of an integer. code.println("flowThread.addEventClock(" + cols[0] + ", " + cols[1] + ", \"timer_" + trigger.hashCode() + "\");"); } //code.println("new EventClock(flowRunner, " + min + ", " + max + ", \"timer_" + trigger.hashCode() + "\");"); } else { try { int time = Integer.parseInt(interval); code.println("flowThread.addEventClock(" + time + ", " + time + ", \"timer_" + trigger.hashCode() + "\");"); //code.println("new EventClock(flowRunner, " + time + ", \"timer_" + trigger.hashCode() + "\");"); } catch (NumberFormatException e) {//In case developer uses variable names instead of an integer. code.println("flowThread.addEventClock(" + interval + ", " + interval + ", \"timer_" + trigger.hashCode() + "\");"); } } } //if interval !null } //if instanceof ontime } code.println("}"); code.println(); printOnEntry(state.getTrigger()); code.println(); printEventTriggers(state.getTrigger()); printOnExit(state.getTrigger()); code.println(); code.println("}"); code.println(); } }
From source file:org.mule.devkit.doclet.ClassInfo.java
public int compareTo(Object that) { if (that instanceof ClassInfo) { return mQualifiedName.compareTo(((ClassInfo) that).mQualifiedName); } else {//from w ww . ja v a2 s . com return this.hashCode() - that.hashCode(); } }
From source file:com.ebay.erl.mobius.core.model.Tuple.java
@Override public int hashCode() { int hashCode = 0; for (Object obj : this.values) { //if( obj==null ) // throw new RuntimeException(this.namesToIdxMapping.toString()+":"+this.values.toString()); if (obj == null) continue; hashCode += obj.hashCode(); }/*w w w. j a v a 2 s . com*/ return hashCode; }
From source file:org.structr.core.entity.AbstractNode.java
@Override public boolean equals(final Object o) { if (o == null) { return false; }/*ww w . j a va2 s. c o m*/ if (!(o instanceof AbstractNode)) { return false; } return (Integer.valueOf(this.hashCode()).equals(o.hashCode())); }
From source file:de.innovationgate.utils.WGUtils.java
/** * Finds an object inside any collection based on its hashcode. * @param col The collection to search/* w w w.ja v a2 s . c o m*/ * @param hash HashCode of the searched object * @return The object if it was contained in the collection, null if not */ public static Object findObjectByHash(Collection<?> col, int hash) { Iterator<?> it = col.iterator(); Object obj; while (it.hasNext()) { obj = it.next(); if (obj.hashCode() == hash) { return obj; } } return null; }
From source file:SoftValuedHashMap.java
public boolean containsKey(Object key) { Entry<K, V>[] tab = this.table; if (key != null) { int hash = key.hashCode(); int index = (hash & 0x7fffffff) % tab.length; for (Entry<K, V> e = tab[index], prev = null; e != null; e = e.next) { if (e.get() == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next;//from ww w . j ava 2 s. com } else { tab[index] = e.next; } this.count--; } else if (e.hash == hash && key.equals(e.key)) { return true; } else { prev = e; } } } else { for (Entry<K, V> e = tab[0], prev = null; e != null; e = e.next) { if (e.get() == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[0] = e.next; } this.count--; } else if (e.key == null) { return true; } else { prev = e; } } } return false; }
From source file:SoftValuedHashMap.java
public V get(Object key) { Entry<K, V>[] tab = this.table; if (key != null) { int hash = key.hashCode(); int index = (hash & 0x7fffffff) % tab.length; for (Entry<K, V> e = tab[index], prev = null; e != null; e = e.next) { V entryValue = e.get();//from www . j av a 2 s . c o m if (entryValue == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } count--; } else if (e.hash == hash && key.equals(e.key)) { return (entryValue == KeyFactory.NULL) ? null : entryValue; } else { prev = e; } } } else { for (Entry<K, V> e = tab[0], prev = null; e != null; e = e.next) { V entryValue = e.get(); if (entryValue == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[0] = e.next; } this.count--; } else if (e.key == null) { return (entryValue == KeyFactory.NULL) ? null : entryValue; } else { prev = e; } } } return null; }