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:ja.ohac.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();

    if (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 www.  j  a  va  2s  . c o m

            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, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.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 rate = entry.getValue();
            final String currencyCode = rate.currencyCode;
            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.rate.longValue())
                        .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate rate = bestExchangeRate(selectionArg);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.wsi.algorithm.SimpleGraphClusteringInductionAlgorithm.java

/**
 * create a local graph from a term neighborhood
 *
 * @param collection/*from  w ww .  java  2  s.  c om*/
 * @param localGraph
 * @param mod_sim_thres
 */
public void createGraph(Collection<String> collection, Graph<String, Integer> localGraph,
        double mod_sim_thres) {
    final ArrayList<String> vertexlist2 = new ArrayList<String>(collection);
    final int i = 0;
    for (final String v : collection) {
        // vertexlist2.remove(v);
        for (final String w : vertexlist2) {
            if (!w.equals(v)) {

                double similarity;
                /*
                 * Edge ids are calculated by XORing the hashcodes of the corresponding nodes.
                 */
                if (!localGraph.containsEdge(v.hashCode() ^ w.hashCode())) {
                    try {
                        similarity = getSimilarity(v, w);
                        if (similarity > mod_sim_thres) {
                            localGraph.addEdge(v.hashCode() ^ w.hashCode(), v, w);
                        }
                    } catch (final Exception e) {

                        e.printStackTrace();
                    }
                }

            }
        }

    }
}

From source file:org.apache.beam.sdk.io.elasticsearch.ElasticsearchIOTestCommon.java

/**
 * Tests that documents are correctly routed when index, type and document ID functions are
 * provided to overwrite the defaults of using the configuration and auto-generation of the
 * document IDs by Elasticsearch. The scientist name is used for the index, type and document ID.
 * As a result there should be only a single document in each index/type.
 *//*from w w  w.ja  v a 2  s  .c  om*/
void testWriteWithFullAddressing() throws Exception {
    List<String> data = ElasticSearchIOTestUtils.createDocuments(numDocs,
            ElasticSearchIOTestUtils.InjectionMode.DO_NOT_INJECT_INVALID_DOCS);
    pipeline.apply(Create.of(data))
            .apply(ElasticsearchIO.write().withConnectionConfiguration(connectionConfiguration)
                    .withIdFn(new ExtractValueFn("id")).withIndexFn(new ExtractValueFn("scientist"))
                    .withTypeFn(new Modulo2ValueFn("scientist")));
    pipeline.run();

    for (String scientist : FAMOUS_SCIENTISTS) {
        String index = scientist.toLowerCase();
        for (int i = 0; i < 2; i++) {
            String type = "TYPE_" + scientist.hashCode() % 2;
            long count = refreshIndexAndGetCurrentNumDocs(restClient, index, type);
            assertEquals("Incorrect count for " + index + "/" + type, numDocs / NUM_SCIENTISTS, count);
        }
    }
}

From source file:at.jku.rdfstats.RDFStatsModelImpl.java

/** get a key for p, rangeUri (unique id for histograms in the cache map)
 * //from w w  w .  java  2s .  c  om
 * @param sourceUrl
 * @param p
 * @param rangeUri
 * @return
 */
protected int getHistogramKey(String sourceUrl, String p, String rangeUri) {
    int id = 0;
    if (sourceUrl != null)
        id = sourceUrl.hashCode();
    //      if (c != null)
    //         id = id ^ c.hashCode() << 4;
    if (p != null)
        id = id ^ p.hashCode() << 8;
    if (rangeUri != null)
        id = id ^ rangeUri.hashCode() << 12;
    return id;
}

From source file:com.opengamma.masterdb.security.hibernate.capfloor.CapFloorSecurityBean.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 575402001: // currency
        return getCurrency();
    case 1905311443: // dayCount
        return getDayCount();
    case -70023844: // frequency
        return getFrequency();
    case 98258: // cap
        return isCap();
    case 3225788: // ibor
        return isIbor();
    case 106443605: // payer
        return isPayer();
    case -414641441: // maturityDate
        return getMaturityDate();
    case 1585636160: // notional
        return getNotional();
    case -2129778896: // startDate
        return getStartDate();
    case -891985998: // strike
        return getStrike();
    case 368639974: // underlyingIdentifier
        return getUnderlyingIdentifier();
    }// w ww.j  av  a  2 s  . co m
    return super.propertyGet(propertyName, quiet);
}

From source file:com.bushstar.htmlcoin_android_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();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(userAgent);

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*  www  . ja v a 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, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.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 rate = entry.getValue();
            final String currencyCode = rate.currencyCode;
            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.rate.longValue())
                        .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate rate = bestExchangeRate(selectionArg);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:com.opengamma.masterdb.security.hibernate.capfloor.CapFloorCMSSpreadSecurityBean.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 575402001: // currency
        return getCurrency();
    case 1905311443: // dayCount
        return getDayCount();
    case -70023844: // frequency
        return getFrequency();
    case 98258: // cap
        return isCap();
    case 106443605: // payer
        return isPayer();
    case 18113605: // longIdentifier
        return getLongIdentifier();
    case -414641441: // maturityDate
        return getMaturityDate();
    case 1585636160: // notional
        return getNotional();
    case -2054053307: // shortIdentifier
        return getShortIdentifier();
    case -2129778896: // startDate
        return getStartDate();
    case -891985998: // strike
        return getStrike();
    }/*ww w  .j av a 2  s  .c  o  m*/
    return super.propertyGet(propertyName, quiet);
}

From source file:net.sf.jabref.model.database.BibtexDatabase.java

/**
 * Returns the entry with the given bibtex key.
 *///from  w  ww.  java2 s  . c o  m
public synchronized BibtexEntry getEntryByKey(String key) {
    BibtexEntry back = null;

    int keyHash = key.hashCode(); // key hash for better performance

    Set<String> keySet = entries.keySet();
    for (String entryID : keySet) {
        BibtexEntry entry = getEntryById(entryID);
        if ((entry != null) && (entry.getCiteKey() != null)) {
            String citeKey = entry.getCiteKey();
            if (citeKey != null) {
                if (keyHash == citeKey.hashCode()) {
                    back = entry;
                }
            }
        }
    }
    return back;
}

From source file:com.opengamma.masterdb.security.hibernate.equity.EquityVarianceSwapSecurityBean.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 663363412: // annualizationFactor
        return getAnnualizationFactor();
    case 575402001: // currency
        return getCurrency();
    case -1644595926: // firstObservationDate
        return getFirstObservationDate();
    case -1362285436: // lastObservationDate
        return getLastObservationDate();
    case 1585636160: // notional
        return getNotional();
    case -213041520: // observationFrequency
        return getObservationFrequency();
    case -752533291: // parameterisedAsVariance
        return isParameterisedAsVariance();
    case -934795532: // region
        return getRegion();
    case -295948169: // settlementDate
        return getSettlementDate();
    case -714106872: // spotUnderlyingIdentifier
        return getSpotUnderlyingIdentifier();
    case -891985998: // strike
        return getStrike();
    }//from w  w w.  j  av a  2 s.c om
    return super.propertyGet(propertyName, quiet);
}

From source file:com.opengamma.component.factory.livedata.PriorityResolvingCombiningLiveDataServerComponentFactory.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 39794031: // dbConnector
        setDbConnector((DbConnector) newValue);
        return;/*from  w w w.  j a v  a 2  s.  c o  m*/
    case -1452875317: // cacheManager
        setCacheManager((CacheManager) newValue);
        return;
    case 1984149838: // server1
        setServer1((ComponentInfo) newValue);
        return;
    case 1984149839: // server2
        setServer2((ComponentInfo) newValue);
        return;
    case 1984149840: // server3
        setServer3((ComponentInfo) newValue);
        return;
    case 1984149841: // server4
        setServer4((ComponentInfo) newValue);
        return;
    case 1984149842: // server5
        setServer5((ComponentInfo) newValue);
        return;
    case 1984149843: // server6
        setServer6((ComponentInfo) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}