Example usage for java.util HashMap hashCode

List of usage examples for java.util HashMap hashCode

Introduction

In this page you can find the example usage for java.util HashMap hashCode.

Prototype

int hashCode();

Source Link

Document

Returns the hash code value for this map.

Usage

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

public void testHashCode() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(hashMap);

    // Check that hashCode changes
    int hashCode1 = hashMap.hashCode();
    hashMap.put(KEY_KEY, VALUE_VAL);/*  ww w. ja  v a2s . c  om*/
    int hashCode2 = hashMap.hashCode();

    assertTrue(hashCode1 != hashCode2);
}

From source file:net.opentsdb.tsd.GraphHandler.java

/** Returns the base path to use for the Gnuplot files. */
private String getGnuplotBasePath(final TSDB tsdb, final HttpQuery query) {
    final Map<String, List<String>> q = query.getQueryString();
    q.remove("ignore");
    // Super cheap caching mechanism: hash the query string.
    final HashMap<String, List<String>> qs = new HashMap<String, List<String>>(q);
    // But first remove the parameters that don't influence the output.
    qs.remove("png");
    qs.remove("json");
    qs.remove("ascii");
    return tsdb.getConfig().getDirectoryName("tsd.http.cachedir") + Integer.toHexString(qs.hashCode());
}

From source file:org.apereo.services.persondir.support.AttributeBasedCacheKeyGenerator.java

/**
 * Gets the hash of the key elements from the seed {@link Map}. The key elements are specified by
 * the <code>cacheKeyAttributes</code> {@link Set} or if it is <code>null</code> the
 * <code>defaultAttributeName</code> is used as the key attribute.
 *
 * @param seed Seed/* w ww.  ja  v a  2 s  . c om*/
 * @return Hash of key elements from the seed
 */
protected Integer getKeyHash(final Map<String, Object> seed) {
    //Determine the attributes to build the cache key with
    final Set<String> cacheAttributes;
    if (this.useAllAttributes) {
        cacheAttributes = seed.keySet();
    } else if (this.cacheKeyAttributes != null) {
        cacheAttributes = this.cacheKeyAttributes;
    } else {
        cacheAttributes = this.defaultAttributeNameSet;
    }

    //Build the cache key based on the attribute Set
    final HashMap<String, Object> cacheKey = new HashMap<>(cacheAttributes.size());
    for (final String attr : cacheAttributes) {
        if (seed.containsKey(attr)) {
            final Object value = seed.get(attr);

            if (!this.ignoreEmptyAttributes) {
                cacheKey.put(attr, value);
            } else if (value instanceof Collection) {
                if (!CollectionUtils.isEmpty((Collection<?>) value)) {
                    cacheKey.put(attr, value);
                }
            } else if (value instanceof String) {
                if (StringUtils.isNotEmpty((String) value)) {
                    cacheKey.put(attr, value);
                }
            } else if (value != null) {
                cacheKey.put(attr, value);
            }
        }
    }

    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Generated cache Map " + cacheKey + " from seed Map " + seed);
    }

    //If no entries don't return a key
    if (cacheKey.isEmpty()) {
        return null;
    }

    //Return the key map's hash code
    return cacheKey.hashCode();
}

From source file:pt.webdetails.cdf.dd.ResourceManager.java

public static String buildCacheKey(final String path, final HashMap<String, String> tokens) {

    final StringBuilder keyBuilder = new StringBuilder(path);

    if (tokens != null) {
        keyBuilder.append(tokens.hashCode());
    }//from ww w.ja va  2  s . co  m

    return keyBuilder.toString();
}