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:com.opengamma.masterdb.security.hibernate.equity.EquitySecurityBean.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 1989774883: // exchange
        return getExchange();
    case -2028219097: // shortName
        return getShortName();
    case -508582744: // companyName
        return getCompanyName();
    case 575402001: // currency
        return getCurrency();
    case 762040799: // gicsCode
        return getGicsCode();
    case -1294005119: // preferred
        return isPreferred();
    }//from w w  w.  j ava2s  . c  o m
    return super.propertyGet(propertyName, quiet);
}

From source file:com.opengamma.masterdb.security.hibernate.fx.FXForwardSecurityBean.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 1652755475: // forwardDate
        return getForwardDate();
    case -934795532: // region
        return getRegion();
    case -295641895: // payCurrency
        return getPayCurrency();
    case -1338781920: // payAmount
        return getPayAmount();
    case -1228590060: // receiveCurrency
        return getReceiveCurrency();
    case 984267035: // receiveAmount
        return getReceiveAmount();
    }/*  ww w .j  a va 2 s  . com*/
    return super.propertyGet(propertyName, quiet);
}

From source file:com.cisco.oss.foundation.loadbalancer.StickyRoundRobinStrategy.java

private int getHash(S request) {

    String hashField = request.getLbKey();

    if (StringUtils.isNotBlank(hashField)) {
        if (FLOW_CONTEXT.equals(hashField)) {
            FlowContext flowContext = FlowContextFactory.getFlowContext();
            if (flowContext != null) {
                return flowContext.hashCode();
            }/*ww w .  ja va  2 s . c  o  m*/
        } else {
            return hashField.hashCode();
        }
    }
    return -1;
}

From source file:com.github.stephanarts.cas.ticket.registry.provider.GetTicketsMethodTest.java

@Test
public void testSerializationError() throws Exception {
    final HashMap<Integer, Ticket> map = new HashMap<Integer, Ticket>();
    final JSONObject params = new JSONObject();
    final IMethod method = new GetTicketsMethod(map);
    final JSONObject result;

    final String ticketId = "ST-1234567890ABCDEFGHIJKL-crud";
    final ServiceTicket ticket = mock(ServiceTicket.class, withSettings().serializable());

    PowerMockito.whenNew(ObjectOutputStream.class).withAnyArguments().thenThrow(new Exception("broken"));

    map.put(ticketId.hashCode(), ticket);

    try {/* www  .  j a  va2 s  .c  om*/
        result = method.execute(params);
    } catch (final JSONRPCException e) {
        Assert.assertEquals(-32500, e.getCode());
        Assert.assertTrue(e.getMessage().equals("Error extracting Ticket"));
        return;
    } catch (final Exception e) {
        throw new Exception(e);
    }

    Assert.fail("No Exception Thrown");
}

From source file:de.huberlin.wbi.hiway.am.galaxy.GalaxyTaskInstance.java

public GalaxyTaskInstance(long id, UUID workflowId, String taskName, GalaxyTool galaxyTool, String galaxyPath) {
    super(id, workflowId, taskName, Math.abs(taskName.hashCode() + 1), ForeignLambdaExpr.LANGID_BASH);
    this.galaxyTool = galaxyTool;
    toolState = new JSONObject();
    paramScript = new StringBuilder("import os, ast\nimport cPickle as pickle\nimport galaxy.app\n");
    this.postScript = "";
    inputs = new HashSet<>();

    // the task instance's invocScript variable is set here for it to be passed to the Worker thread, which writes the script's content as JsonReportEntry
    // to the log
    setInvocScript("script.sh");

    // As opposed to other Hi-WAY applciation masters, the Galaxy AM ha a fairly static command that can be build at task instance creation time
    StringBuilder commandSb = new StringBuilder();
    commandSb.append("PYTHONPATH=" + galaxyPath + "/lib:$PYTHONPATH; export PYTHONPATH\n");
    commandSb.append("PYTHON_EGG_CACHE=.; export PYTHON_EGG_CACHE\n");
    commandSb.append("python params.py\n");
    commandSb.append("cat pre.sh > script.sh\n");
    commandSb.append("echo `cheetah fill template.tmpl --pickle params.p -p` >> script.sh\n");
    commandSb.append("cat post.sh >> script.sh\n");
    commandSb.append("bash ").append(getInvocScript()).append("\n");
    setCommand(commandSb.toString());/*from w w  w. j  a  v  a 2s  .  c  om*/
}

From source file:maspack.fileutil.vfs.SimpleUserAuthenticator.java

/**
 * {@inheritDoc}//w w  w .j  av a 2  s.co  m
 */
@Override
public int hashCode() {
    String str = "";
    if (username != null) {
        str += username + ":";
    }
    if (domain != null) {
        str += domain + ":";
    }
    if (password != null) {
        str += password + ":";
    }

    return str.hashCode();
}

From source file:alter.vitro.vgw.service.resourceRegistry.ResourceAvailabilityService.java

private int getStringMixedResourceCode(String pToken) {

    int hash = pToken.hashCode();
    return hash < 0 ? hash * -1 : hash;

}

From source file:net.sf.ehcache.distribution.PayloadUtilTest.java

/**
 * 376 s per one gzipping each time./* w w  w  . j  a v  a  2  s . co  m*/
 * .1 s if we compare hashCodes on the String and only gzip as necessary.
 * @throws IOException
 * @throws InterruptedException
 */
public void testGzipSanityAndPerformance() throws IOException, InterruptedException {
    String payload = createReferenceString();
    //warmup vm
    for (int i = 0; i < 10; i++) {
        byte[] compressed = PayloadUtil.gzip(payload.getBytes());
        //make sure we don't forget to close the stream
        assertTrue(compressed.length > 300);
        Thread.sleep(20);
    }
    int hashCode = payload.hashCode();
    StopWatch stopWatch = new StopWatch();
    for (int i = 0; i < 10000; i++) {
        if (hashCode != payload.hashCode()) {
            PayloadUtil.gzip(payload.getBytes());
        }
    }
    long elapsed = stopWatch.getElapsedTime();
    LOG.info("Gzip took " + elapsed / 10F + " s");
}

From source file:de.schildbach.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) {
        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_SOURCE,
                    BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_SOURCE,
                    BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*from  w ww.  ja va 2 s.  c  om*/

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:com.github.stephanarts.cas.ticket.registry.provider.DeleteMethod.java

/**
 * Execute the JSONRPCFunction./*from w  w w .j a v  a2s  .com*/
 *
 * @param params    JSONRPC Method Parameters.
 *
 * @return          JSONRPC result object
 *
 * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error.
 */
public JSONObject execute(final JSONObject params) throws JSONRPCException {

    JSONObject result = new JSONObject();

    String ticketId = null;

    if (params.length() != 1) {
        throw new JSONRPCException(-32602, "Invalid Params");
    }
    if (!(params.has("ticket-id"))) {
        throw new JSONRPCException(-32602, "Invalid Params");
    }

    ticketId = params.getString("ticket-id");

    logger.debug("Delete key {}", ticketId);

    if (!this.map.containsKey(ticketId.hashCode())) {
        logger.warn("Missing Key {}", ticketId);
        throw new JSONRPCException(-32503, "Missing Key");
    }

    this.map.remove(ticketId.hashCode());

    result.put("ticket-id", ticketId);
    result.put("status", "REMOVED");

    return result;
}