Example usage for java.lang String hashCode

List of usage examples for java.lang String hashCode

Introduction

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

Prototype

public int hashCode() 

Source Link

Document

Returns a hash code for this string.

Usage

From source file:edu.stanford.junction.props2.sample.CollectionProp.java

public void doRandom() {
    ArrayList<String> words = new ArrayList<String>();
    words.add("dude");
    words.add("apple");
    words.add("hat");
    words.add("cat");
    words.add("barge");
    words.add("horse");
    words.add("mango");
    words.add("code");
    Random rng = new Random();
    if (rng.nextInt(2) == 0) {
        JSONObject item = new JSONObject();
        String word = words.get(rng.nextInt(words.size()));
        try {//  ww  w.j a  va  2 s.c om
            item.put("id", word.hashCode());
            item.put("str", word);
            add(item);
        } catch (JSONException e) {
        }
    } else {
        Iterator<JSONObject> it = items().iterator();
        if (it.hasNext()) {
            delete(it.next());
        }
    }
}

From source file:com.lee.sdk.utils.Utils.java

/**
 * A hashing method that changes a string (like a URL) into a hash suitable for using as a disk
 * filename./*from www  . j a va  2 s . co m*/
 */
public static String hashKeyForDisk(String key) {
    String cacheKey;
    try {
        final MessageDigest mDigest = MessageDigest.getInstance("MD5");
        mDigest.update(key.getBytes());
        cacheKey = bytesToHexString(mDigest.digest());
    } catch (NoSuchAlgorithmException e) {
        cacheKey = String.valueOf(key.hashCode());
    }
    return cacheKey;
}

From source file:com.xpn.xwiki.plugin.laszlo.LaszloPlugin.java

public String getFileName(String name, String laszlocode) {
    if ((name == null) || name.trim().equals(""))
        name = "laszlo";

    String filename = name + "-" + Math.abs(laszlocode.hashCode()) + ".lzx";
    return filename;
}

From source file:com.github.shredder121.gh_event_api.filter.GithubMACChecker.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws IOException, ServletException {
    String signatureHeader = request.getHeader(GITHUB_SIGNATURE_HEADER);
    if (shouldFilter(request)) {
        if (signatureHeader != null) {
            HttpServletRequest preReadRequest = new PreReadRequest(request);
            byte[] requestBytes = ByteStreams.toByteArray(preReadRequest.getInputStream());
            String signatureString = "sha1=" + hexDigest(requestBytes);
            if (signatureString.hashCode() != signatureHeader.hashCode()) {
                logger.warn("bad signature {} {}", signatureString, signatureHeader);
                response.sendError(HttpStatus.NO_CONTENT.value());
                // drops the payload
            } else {
                filterChain.doFilter(preReadRequest, response);
            }//from  www.  ja v a2s  .c  o m
        } else {
            response.sendError(HttpStatus.NOT_FOUND.value());
        }
    } else {
        if (signatureHeader != null) {
            logger.warn("Signature checking requested, but Mac is not set up.");
        }
        filterChain.doFilter(request, response);
    }
}

From source file:com.opengamma.batch.domain.FunctionUniqueId.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 3355: // id
        return getId();
    case -294460212: // uniqueId
        return getUniqueId();
    }/*from  w w  w  .  j  av a 2  s  . c o m*/
    return super.propertyGet(propertyName, quiet);
}

From source file:StringIntSizedMap.java

/**
 * Standard base slot computation for a key. This method may be used
 * directly for key lookup using either the <code>hashCode()</code> method
 * defined for the key objects or the <code>System.identityHashCode()</code>
 * method, as selected by the hash technique constructor parameter. To
 * implement a hash class based on some other methods of hashing and/or
 * equality testing, define a separate method in the subclass with a
 * different name and use that method instead. This avoids the overhead
 * caused by overrides of a very heavily used method.
 *
 * @param key key value to be computed//from  w  w  w. j  a va  2  s . c  o  m
 * @return base slot for key
 */
private final int standardSlot(String key) {
    return (key.hashCode() & Integer.MAX_VALUE) % m_arraySize;
}

From source file:com.microsoft.applicationinsights.test.framework.telemetries.TelemetryItem.java

/**
 * Returns the Hashcode of the ID of this object
 * @return The Hashcode of the ID of this object
 *//*from  www  .j  a  v a 2  s .c  om*/
@Override
public int hashCode() {
    int hash = 0;
    for (String propertyName : getDefaultPropertiesToCompare()) {
        String property = getProperty(propertyName);

        if (!LocalStringsUtils.isNullOrEmpty(property)) {
            hash ^= property.hashCode();
        }
    }

    return hash;
}

From source file:com.azaptree.services.commons.TypeReferenceKey.java

protected TypeReferenceKey(final String name, final boolean required, final T defaultValue) {
    super();//from w w  w .j a v  a  2  s.c  o m
    Assert.hasText(name);
    this.name = name;
    this.hashCode = name.hashCode();
    this.required = required;
    this.defaultValue = defaultValue;
}

From source file:com.phoenixnap.oss.ramlapisync.verification.Issue.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;

    result = prime * result + ((description == null) ? 0 : description.hashCode());
    result = prime * result + ((location == null) ? 0 : location.hashCode());
    String ramlLocation = getRamlLocation();
    result = prime * result + ((ramlLocation == null) ? 0 : ramlLocation.hashCode());

    result = prime * result + ((severity == null) ? 0 : severity.hashCode());
    result = prime * result + ((type == null) ? 0 : type.hashCode());
    return result;
}

From source file:com.jxt.web.websocket.OrderedWebSocketFlushRunnable.java

@Override
public int select() {
    String webSocketSessionId = webSocketSession.getId();
    if (StringUtils.isEmpty(webSocketSessionId)) {
        webSocketSessionId = RandomStringUtils.random(1);
    }//from   www.  j av  a  2 s.com

    return webSocketSessionId.hashCode();
}