Example usage for java.lang Integer hashCode

List of usage examples for java.lang Integer hashCode

Introduction

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

Prototype

@Override
public int hashCode() 

Source Link

Document

Returns a hash code for this Integer .

Usage

From source file:Main.java

public static void main(String[] args) {

    Integer intObject = new Integer(999);
    System.out.println(intObject.hashCode());
}

From source file:edu.temple.cis3238.wiki.utils.StringUtils.java

/**
 * Random semi-unique string// w w  w  .j  a  v a  2s.  c  o  m
 *
 * @param prefix
 * @param length
 * @return
 */
public static final String getRandomString(String prefix, int length) {
    Integer r = (int) (Math.random() * 1000000.0);
    if (length < StringUtils.toS(prefix).length() + 6) {
        length = StringUtils.toS(prefix).length() + 6;
    }
    Integer hash = r.hashCode();
    Integer random = (11 * r) + (hash * 11);
    int end = Math.abs(length - StringUtils.toS(prefix).length()) + 1;
    return org.apache.commons.lang3.StringUtils.rightPad(prefix, length, random.toString());
    //     prefix + random.toString().substring(0, end < random.toString().length()
    //           ? end
    //           : random.toString().length() - 1);

}

From source file:com.aurel.track.fieldType.runtime.base.WBSComparable.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    if (wbsOnLevelsList != null) {
        int length = wbsOnLevelsList.size();
        for (int i = 0; i < length; i++) {
            Integer wbsOnLevel = wbsOnLevelsList.get(i);
            result = prime * result + ((wbsOnLevel == null) ? 0 : wbsOnLevel.hashCode());
        }/*ww  w.  j  a v  a2 s .  c  o  m*/
    } else {
        result = prime * result;
    }
    return result;
}

From source file:IntHashMap.java

/**
 * Returns a collection view of the mappings contained in this map.  Each
 * element in the returned collection is a <tt>Map.Entry</tt>.  The
 * collection is backed by the map, so changes to the map are reflected in
 * the collection, and vice-versa.  The collection supports element
 * removal, which removes the corresponding mapping from the map, via the
 * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
 * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
 *
 * @return a collection view of the mappings contained in this map.
 *///from  www.j a  v a  2s .c  om
public Set<Map.Entry<Integer, V>> entrySet() {
    if (entrySet == null) {
        entrySet = new AbstractSet<Map.Entry<Integer, V>>() {
            public Iterator iterator() {
                return (Iterator) new IntHashIterator(ENTRIES);
            }

            public boolean contains(Object o) {
                if (!(o instanceof Map.Entry)) {
                    return false;
                }
                Map.Entry entry = (Map.Entry) o;
                Integer key = (Integer) entry.getKey();
                Entry tab[] = table;
                int hash = (key == null ? 0 : key.hashCode());
                int index = (hash & 0x7fffffff) % tab.length;

                for (Entry e = tab[index]; e != null; e = e.next) {
                    if (e.key == hash && e.equals(entry)) {
                        return true;
                    }
                }
                return false;
            }

            public boolean remove(Object o) {
                if (!(o instanceof Map.Entry)) {
                    return false;
                }
                Map.Entry entry = (Map.Entry) o;
                Integer key = (Integer) entry.getKey();
                Entry tab[] = table;
                int hash = (key == null ? 0 : key.hashCode());
                int index = (hash & 0x7fffffff) % tab.length;

                for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) {
                    if (e.key == hash && e.equals(entry)) {
                        modCount++;
                        if (prev != null) {
                            prev.next = e.next;
                        } else {
                            tab[index] = e.next;
                        }

                        count--;
                        e.value = null;
                        return true;
                    }
                }
                return false;
            }

            public int size() {
                return count;
            }

            public void clear() {
                IntHashMap.this.clear();
            }
        };
    }

    return entrySet;
}

From source file:org.agnitas.beans.impl.ProfileFieldImpl.java

public int hashCode() {
    Integer i = new Integer(companyID);

    return i.hashCode() * column.hashCode();
}

From source file:org.largecollections.FastIntIntCacheMap.java

private void initializeBloomFilter() {
    this.myFunnel = new Funnel<Integer>() {
        public void funnel(Integer obj, PrimitiveSink into) {
            into.putInt(Math.abs(obj.hashCode()));

        }//  ww w.  ja va  2  s .  c o m
    };
    this.bloomFilter = BloomFilter.create(myFunnel, this.bloomFilterSize);
}

From source file:org.rhq.plugins.www.snmp.SNMPClient.java

public SNMPSession getSession(String host, Integer port, String community, SNMPVersion version)
        throws SNMPException {
    SNMPSession session;//from ww  w  .ja  va  2s .c  o m

    if (host == null) {
        host = DEFAULT_HOST;
    }

    if (port == null) {
        port = DEFAULT_PORT;
    }

    if (community == null) {
        community = DEFAULT_COMMUNITY;
    }

    if (version == null) {
        version = DEFAULT_VERSION;
    }

    int id = host.hashCode() ^ port.hashCode() ^ community.hashCode() ^ version.hashCode();

    synchronized (SESSION_CACHE) {
        session = SESSION_CACHE.get(id);
    }

    if (session != null) {
        return session;
    }

    InetAddress ip;
    try {
        ip = InetAddress.getByName(host);
    } catch (UnknownHostException e) {
        throw new SNMPException("Invalid Host: '" + host + "': " + e);
    }

    if ((port < 1) || (port > 65535)) {
        throw new SNMPException("Invalid Port: " + port);
    }

    if (!community.trim().equals(community)) {
        throw new SNMPException("Invalid Community: '" + community + "': whitespace is not permitted");
    }

    try {
        session = startSession(version);

        switch (version) {
        case V1:
        case V2C: {
            ((SNMPSession_v1) session).init(host, port, community);
            break;
        }

        case V3: {
            // TODO
            String user = "TODO";
            String pass = "TODO";
            int authType = parseAuthMethod("TODO");
            ((SNMPSession_v3) session).init(host, port, user, pass, authType);
            break;
        }

        default: {
            throw new SNMPException("unsupported SNMP version");
        }
        }

        //should be enough for properly functioning SNMP
        //and not too long for one that is not functioning at all
        session.setTimeout(SESSION_TIMEOUT);
        session.setRetries(SESSION_RETRIES);
        log.info("Initialized SNMP session for agent at " + ip + ":" + port);
    } catch (SNMPException e) {
        String msg = "Failed to initialize snmp session";
        throw new SNMPException(msg, e);
    }

    session = SNMPSessionCache.newInstance(session, this.sessionCacheExpire);

    synchronized (SESSION_CACHE) {
        SESSION_CACHE.put(id, session);
    }

    return session;
}

From source file:org.sapegin.bgp.analyse.ribs.ASPathElement.java

@Override
public int hashCode() {
    HashCodeBuilder hashCode = new HashCodeBuilder();
    for (Integer as : asElement) {
        hashCode.append(as.hashCode());
    }//from   ww w. j  ava  2 s .c  om

    return hashCode.toHashCode();
}