Example usage for java.lang Object hashCode

List of usage examples for java.lang Object hashCode

Introduction

In this page you can find the example usage for java.lang Object hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.ServletHolder.java

/** Comparitor by init order.
 *///from www . j a  va  2 s.c  o m
public int compareTo(Object o) {
    if (o instanceof ServletHolder) {
        ServletHolder sh = (ServletHolder) o;
        if (sh == this)
            return 0;
        if (sh._initOrder < _initOrder)
            return 1;
        if (sh._initOrder > _initOrder)
            return -1;
        int c = _className.compareTo(sh._className);
        if (c == 0)
            c = _name.compareTo(sh._name);
        if (c == 0)
            c = this.hashCode() > o.hashCode() ? 1 : -1;
        return c;
    }
    return 1;
}

From source file:org.apache.hadoop.hbase.ipc.AsyncRpcChannel.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof AsyncRpcChannel) {
        AsyncRpcChannel channel = (AsyncRpcChannel) obj;
        return channel.hashCode() == obj.hashCode();
    }//from   w ww  . ja  va 2  s . c o  m
    return false;
}

From source file:SoftValueMap.java

public Object remove(final Object key) {
    if (key == null)
        throw new IllegalArgumentException("null input: key");

    if ((++m_writeAccessCount % m_writeClearCheckFrequency) == 0)
        removeClearedValues();//from   w w  w.  java 2  s. com

    // index into the corresponding hash bucket:
    final int keyHashCode = key.hashCode();
    final SoftEntry[] buckets = m_buckets;
    final int bucketIndex = (keyHashCode & 0x7FFFFFFF) % buckets.length;

    Object result = null;

    // traverse the singly-linked list of entries in the bucket:
    for (SoftEntry entry = buckets[bucketIndex], prev = null; entry != null; prev = entry, entry = entry.m_next) {
        final Object entryKey = entry.m_key;

        if ((IDENTITY_OPTIMIZATION && (entryKey == key))
                || ((keyHashCode == entryKey.hashCode()) && key.equals(entryKey))) {
            if (prev == null) // head of the list
            {
                buckets[bucketIndex] = entry.m_next;
            } else {
                prev.m_next = entry.m_next;
            }

            final IndexedSoftReference ref = entry.m_softValue;
            result = ref.get(); // can be null already [however, no need to work around 4485942]

            // [regardless of whether the value has been enqueued or not, disable its processing by removeClearedValues() since the entire entry is removed here]
            ref.m_bucketIndex = -1;

            // help GC:
            entry.m_softValue = null;
            entry.m_key = null;
            entry.m_next = null;
            entry = null;

            --m_size;
            break;
        }
    }

    return result;
}

From source file:SoftValueMap.java

/**
 * Returns the value that is mapped to a given 'key'. Returns
 * null if (a) this key has never been mapped or (b) a previously mapped
 * value has been cleared by the garbage collector and removed from the table.
 *
 * @param key mapping key [may not be null].
 *
 * @return Object value mapping for 'key' [can be null].
 *///  www. ja va  2s  . c  o m
public Object get(final Object key) {
    if (key == null)
        throw new IllegalArgumentException("null input: key");

    if ((++m_readAccessCount % m_readClearCheckFrequency) == 0)
        removeClearedValues();

    // index into the corresponding hash bucket:
    final int keyHashCode = key.hashCode();
    final SoftEntry[] buckets = m_buckets;
    final int bucketIndex = (keyHashCode & 0x7FFFFFFF) % buckets.length;

    Object result = null;

    // traverse the singly-linked list of entries in the bucket:
    for (SoftEntry entry = buckets[bucketIndex]; entry != null; entry = entry.m_next) {
        final Object entryKey = entry.m_key;

        if (IDENTITY_OPTIMIZATION) {
            // note: this uses an early identity comparison opimization, making this a bit
            // faster for table keys that do not override equals() [Thread, etc]
            if ((key == entryKey) || ((keyHashCode == entryKey.hashCode()) && key.equals(entryKey))) {
                final Reference ref = entry.m_softValue;
                result = ref.get(); // may return null to the caller

                // [see comment for ENQUEUE_FOUND_CLEARED_ENTRIES]
                if (ENQUEUE_FOUND_CLEARED_ENTRIES && (result == null)) {
                    ref.enqueue();
                }

                return result;
            }
        } else {
            if ((keyHashCode == entryKey.hashCode()) && key.equals(entryKey)) {
                final Reference ref = entry.m_softValue;
                result = ref.get(); // may return null to the caller

                // [see comment for ENQUEUE_FOUND_CLEARED_ENTRIES]
                if (ENQUEUE_FOUND_CLEARED_ENTRIES && (result == null)) {
                    ref.enqueue();
                }

                return result;
            }
        }
    }

    return null;
}

From source file:com.meidusa.amoeba.route.AbstractQueryRouter.java

License:asdf

public ObjectPool getObjectPool(Object key) {
    if (key instanceof String) {
        return ProxyRuntimeContext.getInstance().getPoolMap().get(key);
    } else {/*  w  w w  . jav a  2  s .c  o m*/
        for (ObjectPool pool : ProxyRuntimeContext.getInstance().getPoolMap().values()) {
            if (pool.hashCode() == key.hashCode()) {
                return pool;
            }
        }
    }
    return null;
}

From source file:org.apache.hadoop.hbase.ipc.AsyncRpcChannelImpl.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof AsyncRpcChannelImpl) {
        AsyncRpcChannelImpl channel = (AsyncRpcChannelImpl) obj;
        return channel.hashCode() == obj.hashCode();
    }//  w w  w.j  a  va 2 s  . co m
    return false;
}

From source file:LRUCache.java

/**
 * Get an item from the cache and make it most recently used.
 * /*  w ww  .ja va2s .  c o m*/
 * @param key key to lookup the item
 * @return the matching object in the cache
 */
public V get(K key) {
    Object okey = key;
    if (okey == null)
        okey = NULL;

    int hash = okey.hashCode() & this._mask;
    int count = this._size1 + this._size2 + 1;

    synchronized (this) {
        for (; count >= 0; count--) {
            CacheItem<K, V> item = this._entries[hash];

            if (item == null) {
                this._missCount++;
                return null;
            }

            if (item._key == key || item._key.equals(key)) {
                updateLru(item);

                this._hitCount++;

                return item._value;
            }

            hash = (hash + 1) & this._mask;
        }

        this._missCount++;
    }

    return null;
}

From source file:io.cloudslang.content.database.utils.SQLInputs.java

public int hashCode() {
    final int PRIME = 59;
    int result = 1;
    final Object $sqlCommand = this.getSqlCommand();
    result = result * PRIME + ($sqlCommand == null ? 43 : $sqlCommand.hashCode());
    final Object $dbServer = this.getDbServer();
    result = result * PRIME + ($dbServer == null ? 43 : $dbServer.hashCode());
    final Object $dbName = this.getDbName();
    result = result * PRIME + ($dbName == null ? 43 : $dbName.hashCode());
    result = result * PRIME + this.getDbPort();
    final Object $dbType = this.getDbType();
    result = result * PRIME + ($dbType == null ? 43 : $dbType.hashCode());
    final Object $key = this.getKey();
    result = result * PRIME + ($key == null ? 43 : $key.hashCode());
    final Object $username = this.getUsername();
    result = result * PRIME + ($username == null ? 43 : $username.hashCode());
    final Object $password = this.getPassword();
    result = result * PRIME + ($password == null ? 43 : $password.hashCode());
    final Object $authenticationType = this.getAuthenticationType();
    result = result * PRIME + ($authenticationType == null ? 43 : $authenticationType.hashCode());
    final Object $instance = this.getInstance();
    result = result * PRIME + ($instance == null ? 43 : $instance.hashCode());
    result = result * PRIME + (this.isIgnoreCase() ? 79 : 97);
    result = result * PRIME + this.getTimeout();
    final Object $dbUrl = this.getDbUrl();
    result = result * PRIME + ($dbUrl == null ? 43 : $dbUrl.hashCode());
    final Object $dbClass = this.getDbClass();
    result = result * PRIME + ($dbClass == null ? 43 : $dbClass.hashCode());
    result = result * PRIME + (this.isNetcool() ? 79 : 97);
    final Object $lRowsFiles = this.getLRowsFiles();
    result = result * PRIME + ($lRowsFiles == null ? 43 : $lRowsFiles.hashCode());
    final Object $lRowsNames = this.getLRowsNames();
    result = result * PRIME + ($lRowsNames == null ? 43 : $lRowsNames.hashCode());
    final long $skip = this.getSkip();
    result = result * PRIME + (int) ($skip >>> 32 ^ $skip);
    final Object $strDelim = this.getStrDelim();
    result = result * PRIME + ($strDelim == null ? 43 : $strDelim.hashCode());
    final Object $strColumns = this.getStrColumns();
    result = result * PRIME + ($strColumns == null ? 43 : $strColumns.hashCode());
    final Object $lRows = this.getLRows();
    result = result * PRIME + ($lRows == null ? 43 : $lRows.hashCode());
    result = result * PRIME + this.getIUpdateCount();
    final Object $databasePoolingProperties = this.getDatabasePoolingProperties();
    result = result * PRIME + ($databasePoolingProperties == null ? 43 : $databasePoolingProperties.hashCode());
    final Object $trustStore = this.getTrustStore();
    result = result * PRIME + ($trustStore == null ? 43 : $trustStore.hashCode());
    final Object $trustStorePassword = this.getTrustStorePassword();
    result = result * PRIME + ($trustStorePassword == null ? 43 : $trustStorePassword.hashCode());
    final Object $authLibraryPath = this.getAuthLibraryPath();
    result = result * PRIME + ($authLibraryPath == null ? 43 : $authLibraryPath.hashCode());
    final Object $colDelimiter = this.getColDelimiter();
    result = result * PRIME + ($colDelimiter == null ? 43 : $colDelimiter.hashCode());
    final Object $rowDelimiter = this.getRowDelimiter();
    result = result * PRIME + ($rowDelimiter == null ? 43 : $rowDelimiter.hashCode());
    final Object $resultSetType = this.getResultSetType();
    result = result * PRIME + ($resultSetType == null ? 43 : $resultSetType.hashCode());
    final Object $resultSetConcurrency = this.getResultSetConcurrency();
    result = result * PRIME + ($resultSetConcurrency == null ? 43 : $resultSetConcurrency.hashCode());
    final Object $sqlCommands = this.getSqlCommands();
    result = result * PRIME + ($sqlCommands == null ? 43 : $sqlCommands.hashCode());
    return result;
}

From source file:ArraySet.java

@Override
public boolean containsKey(Object key) {
    Entry<K, V>[] tbl = mapTable;//from   w  w w.  jav  a 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 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:ArraySet.java

@Override
public V get(Object key) {
    Entry<K, V>[] tbl = mapTable;/*from w ww .  ja va  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 e.value;
            }
        }
    } else {
        for (Entry<K, V> e = tbl[0]; e != null; e = e.next) {
            if (e.key == null) {
                return e.value;
            }
        }
    }
    return null;
}