List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:alluxio.Configuration.java
@Override public int hashCode() { int hash = 0; for (Object s : mProperties.keySet()) { hash ^= s.hashCode(); }//www.j a va 2 s . c om return hash; }
From source file:com.mawujun.util.ObjectUtils.java
/** * <p>Gets the hash code of an object returning zero when the * object is {@code null}.</p>//w w w .ja v a 2s . com * * <pre> * ObjectUtils.hashCode(null) = 0 * ObjectUtils.hashCode(obj) = obj.hashCode() * </pre> * * @param obj the object to obtain the hash code of, may be {@code null} * @return the hash code of the object, or zero if null * @since 2.1 */ public static int hashCode(Object obj) { // hashCode(Object) retained for performance, as hash code is often critical return (obj == null) ? 0 : obj.hashCode(); }
From source file:CompactHashSet.java
int firstIndex(Object e) { return java.lang.Math.abs(supplementalHash(e.hashCode())) % mBuckets.length; }
From source file:ObjectIntMap.java
/** * Updates the table to map 'key' to 'value'. Any existing mapping is overwritten. * * @param key mapping key [may not be null] * @param value mapping value./*from w ww .j av a2 s.co m*/ */ public void put(final Object key, final int value) { Entry currentKeyEntry = null; // detect if 'key' is already in the table [in which case, set 'currentKeyEntry' to point to its entry]: // index into the corresponding hash bucket: final int keyHash = key.hashCode(); int bucketIndex = (keyHash & 0x7FFFFFFF) % m_buckets.length; // traverse the singly-linked list of entries in the bucket: Entry[] buckets = m_buckets; for (Entry entry = buckets[bucketIndex]; entry != null; entry = entry.m_next) { if ((keyHash == entry.m_key.hashCode()) || entry.m_key.equals(key)) { currentKeyEntry = entry; break; } } if (currentKeyEntry != null) { // replace the current value: currentKeyEntry.m_value = value; } else { // add a new entry: if (m_size >= m_sizeThreshold) rehash(); buckets = m_buckets; bucketIndex = (keyHash & 0x7FFFFFFF) % buckets.length; final Entry bucketListHead = buckets[bucketIndex]; final Entry newEntry = new Entry(key, value, bucketListHead); buckets[bucketIndex] = newEntry; ++m_size; } }
From source file:WeakSet.java
/** @return an index to entries array */ int hashIt(Object o) { return (o.hashCode() & 0x7fffffff) % entries.length; }
From source file:org.silverpeas.core.web.util.viewgenerator.html.arraypanes.ArrayLine.java
@Override public boolean equals(final Object o) { if (this == o) { return true; }/*from www .ja va 2s.c o m*/ if (!(o instanceof ArrayLine)) { return false; } return hashCode() == o.hashCode(); }
From source file:org.eclipse.wb.tests.designer.rcp.model.rcp.EditorPartTest.java
/** * Test for {@link IEditorSite} implementation. *//* w w w . j ava 2s . c om*/ public void test_IEditorSite() throws Exception { EditorPartInfo part = parseJavaInfo("import org.eclipse.ui.*;", "import org.eclipse.ui.part.*;", "public abstract class Test extends EditorPart {", " public static final String ID = 'some.editor.Identifier';", " public Test() {", " }", " public void init(IEditorSite site, IEditorInput input) throws PartInitException {", " setSite(site);", " setInput(input);", " }", " public void createPartControl(Composite parent) {", " Composite container = new Composite(parent, SWT.NULL);", " }", "}"); part.refresh(); // Object editorSite = ReflectionUtils.invokeMethod(part.getObject(), "getEditorSite()"); try { ReflectionUtils.invokeMethod(editorSite, "getShell()"); fail(); } catch (NotImplementedException e) { } assertEquals("IEditorSite_stub", editorSite.toString()); assertEquals(0, editorSite.hashCode()); assertEquals("some.editor.Identifier", ReflectionUtils.invokeMethod(editorSite, "getId()")); { Object window = ReflectionUtils.invokeMethod(editorSite, "getWorkbenchWindow()"); assertSame(DesignerPlugin.getActiveWorkbenchWindow(), window); } // IServiceLocator { IServiceLocator serviceLocator = (IServiceLocator) editorSite; assertTrue(serviceLocator.hasService(IMenuService.class)); assertNotNull(serviceLocator.getService(IMenuService.class)); } }
From source file:org.codebistro.jsonrpc.Client.java
public Object invoke(Object proxyObj, Method method, Object[] args) throws Throwable { 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()); }//from w w w. j a v a 2s . c om JSONObject message = new JSONObject(); String tag = proxyMap.get(proxyObj); String methodTag = tag == null ? "" : tag + "."; methodTag += methodName; message.put("method", methodTag); JSONArray params = new JSONArray(); if (args != null) { for (Object arg : args) { SerializerState state = new SerializerState(); params.put(message2Object.marshall(state, arg)); } } message.put("params", params); message.put("id", 1); JSONObject responseMessage = session.sendAndReceive(message); if (!responseMessage.has("result")) processException(responseMessage); Object rawResult = responseMessage.get("result"); if (rawResult == null) { processException(responseMessage); } Class<?> returnType = method.getReturnType(); if (returnType.equals(Void.TYPE)) return null; SerializerState state = new SerializerState(); return message2Object.unmarshall(state, returnType, rawResult); }
From source file:org.apache.pig.data.DefaultTuple.java
@Override public int hashCode() { int hash = 17; for (Iterator<Object> it = mFields.iterator(); it.hasNext();) { Object o = it.next(); if (o != null) { hash = 31 * hash + o.hashCode(); }// w ww .ja va2 s . c o m } return hash; }
From source file:io.github.data4all.model.DeviceOrientation.java
@Override public boolean equals(Object o) { if (o == this) { return true; }/*from w w w.j av a 2 s . com*/ if ((o instanceof DeviceOrientation) && (Math.abs(azimuth - ((DeviceOrientation) o).getAzimuth()) < EPSILON) && (Math.abs(pitch - ((DeviceOrientation) o).getPitch()) < EPSILON) && (Math.abs(roll - ((DeviceOrientation) o).getRoll()) < EPSILON) && timestamp == ((DeviceOrientation) o).getTimestamp() && this.hashCode() == o.hashCode()) { return true; } else { return false; } }