List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:gsn.vsensor.ChartVirtualSensor.java
public boolean equals(Object obj) { if (obj == null && !(obj instanceof ChartInfo)) return false; return (obj.hashCode() == hashCode()); }
From source file:com.taobao.tddl.common.util.TDDLMBeanServer.java
private void registerMBean0(Object o, String name) { // MBean/*w w w . j a v a 2 s .c om*/ if (null != mbs) { try { mbs.registerMBean(o, new ObjectName(o.getClass().getPackage().getName() + ":type=" + o.getClass().getSimpleName() + (null == name ? (",id=" + o.hashCode()) : (",name=" + name + "-" + o.hashCode())))); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:CompactHashSet.java
/** * Removes the specified element from the set. *//*from w w w . j a va2 s . c o m*/ @SuppressWarnings("unchecked") public boolean remove(Object o) { if (o == null) o = nullObject; int hash = o.hashCode(); int index = (hash & 0x7FFFFFFF) % objects.length; int offset = 1; // search for the object (continue while !null and !this object) while (objects[index] != null && !(objects[index].hashCode() == hash && objects[index].equals(o))) { index = ((index + offset) & 0x7FFFFFFF) % objects.length; offset = offset * 2 + 1; if (offset == -1) offset = 2; } // we found the right position, now do the removal if (objects[index] != null) { // we found the object // same problem here as with add objects[index] = (E) deletedObject; modCount++; elements--; return true; } else // we did not find the object return false; }
From source file:com.jdon.aop.interceptor.PoolInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { ProxyMethodInvocation proxyMethodInvocation = (ProxyMethodInvocation) invocation; TargetMetaDef targetMetaDef = targetMetaRequestsHolder.getTargetMetaRequest().getTargetMetaDef(); if (targetMetaDef.isEJB()) return invocation.proceed(); if (!isPoolabe(targetMetaDef)) { // Debug.logVerbose("[JdonFramework] target service is not Poolable: " // + targetMetaDef.getClassName() + " pool unactiive", module); return invocation.proceed(); // interceptor }/*from w w w .ja v a2 s . c om*/ Debug.logVerbose("[JdonFramework] enter PoolInterceptor", module); CommonsPoolFactory commonsPoolFactory = (CommonsPoolFactory) poolFactorys.get(targetMetaDef.getCacheKey()); if (commonsPoolFactory == null) { commonsPoolFactory = getCommonsPoolFactory(targetMetaDef); poolFactorys.put(targetMetaDef.getCacheKey(), commonsPoolFactory); } Pool pool = commonsPoolFactory.getPool(); Object poa = null; Object result = null; try { poa = pool.acquirePoolable(); Debug.logVerbose("[JdonFramework] borrow a object:" + targetMetaDef.getClassName() + " id:" + poa.hashCode() + " from pool", module); Debug.logVerbose( "[JdonFramework]pool state: active=" + pool.getNumActive() + " free=" + pool.getNumIdle(), module); // set the object that borrowed from pool to MethodInvocation // so later other Interceptors or MethodInvocation can use it! proxyMethodInvocation.setThis(poa); result = invocation.proceed(); } catch (Exception ex) { Debug.logError(ex, module); } finally { if (poa != null) { pool.releasePoolable(poa); Debug.logVerbose("[JdonFramework] realease a object:" + targetMetaDef.getClassName() + " to pool", module); } } return result; }
From source file:CompactHashMap.java
/** * INTERNAL: Rehashes the hashmap to a bigger size. *///from w w w .jav a 2 s . c om protected void rehash(int newCapacity) { int oldCapacity = keys.length; K[] newKeys = (K[]) new Object[newCapacity]; V[] newValues = (V[]) new Object[newCapacity]; for (int ix = 0; ix < oldCapacity; ix++) { Object k = keys[ix]; if (k == null || k == deletedObject) continue; int hash = k.hashCode(); int index = (hash & 0x7FFFFFFF) % newCapacity; int offset = 1; // search for the key while (newKeys[index] != null) { // no need to test for duplicates index = ((index + offset) & 0x7FFFFFFF) % newCapacity; offset = offset * 2 + 1; if (offset == -1) offset = 2; } newKeys[index] = (K) k; newValues[index] = values[ix]; } keys = newKeys; values = newValues; freecells = keys.length - elements; }
From source file:ReferenceCountMap.java
/** * Standard base slot computation for a key. * //from w ww . j a va 2 s. c om * @param key key value to be computed * @return base slot for key */ private final int standardSlot(Object key) { return (key.hashCode() & Integer.MAX_VALUE) % m_arraySize; }
From source file:com.github.aptd.simulation.elements.IBaseElement.java
@Override public final boolean equals(final Object p_object) { return (p_object != null) && (p_object instanceof IElement<?>) && (p_object.hashCode() == this.hashCode()); }
From source file:CompactHashSet.java
/** * Adds the specified element to this set if it is not already present. * /* w w w . ja v a 2 s .c o m*/ * @param o * element to be added to this set. * @return <tt>true</tt> if the set did not already contain the specified * element. */ @SuppressWarnings("unchecked") public boolean add(Object o) { if (o == null) o = nullObject; int hash = o.hashCode(); int index = (hash & 0x7FFFFFFF) % objects.length; int offset = 1; int deletedix = -1; // search for the object (continue while !null and !this object) while (objects[index] != null && !(objects[index].hashCode() == hash && objects[index].equals(o))) { // if there's a deleted object here we can put this object here, // provided it's not in here somewhere else already if (objects[index] == deletedObject) deletedix = index; index = ((index + offset) & 0x7FFFFFFF) % objects.length; offset = offset * 2 + 1; if (offset == -1) offset = 2; } if (objects[index] == null) { // wasn't present already if (deletedix != -1) // reusing a deleted cell index = deletedix; else freecells--; modCount++; elements++; // here we face a problem regarding generics: // add(E o) is not possible because of the null Object. We cant do // 'new E()' or '(E) new Object()' // so adding an empty object is a problem here // If (! o instanceof E) : This will cause a class cast exception // If (o instanceof E) : This will work fine objects[index] = (E) o; // do we need to rehash? if (1 - (freecells / (double) objects.length) > LOAD_FACTOR) rehash(); return true; } else // was there already return false; }
From source file:org.apache.wsrp4j.persistence.xml.driver.PersistentHandlerImpl.java
/** * Restore all known XML files from the persistent store into the * PersistentDataObject. The class type, which is part of the filename * is stored in the PersistentInformation object of the * PersistentDataObject./*from w w w . ja v a2 s. com*/ * * @param persistentDataObject * @return PersistentDataObject * * @throws WSRPException */ public PersistentDataObject restoreMultiple(PersistentDataObject persistentDataObject) throws WSRPException { String MN = "restoreMultiple"; if (log.isDebugEnabled()) { log.debug(Utility.strEnter(MN)); } Mapping mapping = null; Unmarshaller unmarshaller = null; try { PersistentInformationXML persistentInformation = (PersistentInformationXML) persistentDataObject .getPersistentInformation(); if (persistentInformation.getMappingFileName() != null) { mapping = new Mapping(); mapping.loadMapping(persistentInformation.getMappingFileName()); unmarshaller = new Unmarshaller(mapping); } File file = new File(persistentInformation.getStoreDirectory()); if (file.exists()) { File[] files = file.listFiles(); for (int x = 0; x < files.length; x++) { if (files[x].isFile()) { String currentFileName = files[x].getName(); // check for valid xml file if (currentFileName.endsWith(persistentInformation.getExtension())) { // check for valid object if (currentFileName.startsWith(persistentInformation.getFilenameStub())) { // load object try { FileReader fileReader = new FileReader(files[x]); ((PersistentDataObjectXML) persistentDataObject).unMarshalFile(fileReader, unmarshaller); fileReader.close(); Object o = persistentDataObject.getLastElement(); int hashCode = o.hashCode(); String code = new Integer(hashCode).toString(); _filenameMap.put(code, files[x].getAbsolutePath()); if (log.isDebugEnabled()) { log.debug("File: " + files[x].getAbsolutePath() + " added with hashCode = " + code); } } catch (Exception e) { // restore error WSRPXHelper.throwX(log, ErrorCodes.RESTORE_OBJECT_ERROR, e); } } } } } } } catch (Exception e) { // restore error WSRPXHelper.throwX(log, ErrorCodes.RESTORE_OBJECT_ERROR, e); } if (log.isDebugEnabled()) { log.debug(Utility.strExit(MN)); } return persistentDataObject; }
From source file:org.lightjason.agentspeak.common.CPath.java
@Override @SuppressFBWarnings("EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS") public final boolean equals(final Object p_object) { return (p_object != null) && (((p_object instanceof IPath) && (this.hashCode() == p_object.hashCode())) || ((p_object instanceof String) && (this.getPath().hashCode() == p_object.hashCode()))); }