List of usage examples for java.lang String hashCode
public int hashCode()
From source file:net.demilich.metastone.game.behaviour.decicionTreeBheavior.DecisionDataBase.java
public CardContextKnowledge getCardKnowledge(String name) { int index = this.hashToIndex.get(name.hashCode()); if (index == -1) { System.err.println("could not find " + name); return null; }/*www .j a va 2s .co m*/ return database[this.hashToIndex.get(name.hashCode())]; }
From source file:de.schildbach.wallet.goldcoin.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 (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) { Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts();//getLitecoinCharts(); if (exchangeRates == null && newExchangeRates == null) newExchangeRates = getBlockchainInfo(); if (newExchangeRates == null) newExchangeRates = getLitecoinCharts(); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;//from w w w .j av a2s .c om } } 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(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String code = selectionArgs[0]; final ExchangeRate rate = exchangeRates.get(code); try { cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } catch (NullPointerException e) { Log.e("GoldCoin", "Unable to add an exchange rate. NullPointerException."); } } return cursor; }
From source file:com.cannabiscoin.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_FIELDS); if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_FIELDS); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;/* www . ja v a2 s. 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:net.demilich.metastone.game.behaviour.decicionTreeBheavior.DecisionDataBase.java
public double getDecision(GameContext context, String actionName, Player player) { int hash = actionName.hashCode(); int index = hashToIndex.get(hash); if (index == -1) { //System.err.println("couldn't find card " + actionName); return 0; }//from w w w. ja v a 2 s . com CardContextKnowledge knowledge = database[index]; if (prevTurn == context.getTurn()) { modified = false; } else { prevTurn = context.getTurn(); } furfillOrder(context, knowledge, player); //Example query = new Example(featureData); return knowledge.classify(featureData); // return knowledge.probMax.percentGood; }
From source file:com.opengamma.core.position.impl.SimpleTrade.java
@SuppressWarnings("unchecked") @Override/*from w ww . jav a 2s.co m*/ protected void propertySet(String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -294460212: // uniqueId setUniqueId((UniqueId) newValue); return; case -1285004149: // quantity setQuantity((BigDecimal) newValue); return; case 807992154: // securityLink setSecurityLink((SecurityLink) newValue); return; case -1651301782: // counterparty setCounterparty((Counterparty) newValue); return; case 752419634: // tradeDate setTradeDate((LocalDate) newValue); return; case 752903761: // tradeTime setTradeTime((OffsetTime) newValue); return; case -318452137: // premium setPremium((Double) newValue); return; case 1136581512: // premiumCurrency setPremiumCurrency((Currency) newValue); return; case 651701925: // premiumDate setPremiumDate((LocalDate) newValue); return; case 652186052: // premiumTime setPremiumTime((OffsetTime) newValue); return; case 405645655: // attributes setAttributes((Map<String, String>) newValue); return; } super.propertySet(propertyName, newValue, quiet); }
From source file:cz.cas.lib.proarc.common.export.desa.DesaServices.java
private Nomenclatures getNomenclaturesCache(DesaConfiguration dc, UserProfile user) { File tmpFolder = FileUtils.getTempDirectory(); File cache = null;// w ww . ja va 2 s .co m String operator = getOperatorName(user, dc); if (operator == null || operator.isEmpty()) { throw new IllegalStateException("Missing operator! id: " + dc.getServiceId() + ", user: " + (user == null ? null : user.getUserName())); } long expiration = dc.getNomenclatureExpiration(); if (expiration != 0) { synchronized (DesaServices.this) { // ensure the filename is platform safe and unique for each operator String codeAsFilename = String.valueOf(operator.hashCode() & 0x00000000ffffffffL); cache = new File(tmpFolder, String.format("%s.%s.nomenclatures.cache", dc.getServiceId(), codeAsFilename)); if (cache.exists() && (expiration < 0 || System.currentTimeMillis() - cache.lastModified() < expiration)) { return JAXB.unmarshal(cache, Nomenclatures.class); } } } String producerCode = getProducerCode(user, dc); if (producerCode == null || producerCode.isEmpty()) { throw new IllegalStateException("Missing producer code! id: " + dc.getServiceId() + ", user: " + (user == null ? null : user.getUserName())); } DesaClient desaClient = getDesaClient(dc); Nomenclatures nomenclatures = desaClient.getNomenclatures(operator, producerCode, dc.getNomenclatureAcronyms()); if (cache != null) { synchronized (DesaServices.this) { JAXB.marshal(nomenclatures, cache); } } return nomenclatures; }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueProducerPerplexity.java
double getPerplexity(CrawlURI uri) { assert _lmprvdr != null : "String provider service must not be null here. This should have been checked before."; String cleaned_plaintext = _textExtractorInstance.getCleanedUtf8PlainText(uri).trim(); String cleaned_plaintext_abbr = MULTIPLE_SPACES_PATTERN .matcher(StringUtils.abbreviate(cleaned_plaintext, 50)).replaceAll(" "); addExtraInfo(uri, EXTRA_INFO_PLAINTEXT_ABBREVIATED, cleaned_plaintext_abbr); if (cleaned_plaintext.isEmpty()) return Double.POSITIVE_INFINITY; double perplexity = Double.POSITIVE_INFINITY; try {/*from www .ja v a 2 s. c o m*/ String docid = "#" + Integer.toHexString(cleaned_plaintext.hashCode()); LOG.finest(String.format("Sending text with id '%s' to StringProvider: '%s' (length %d).", docid, cleaned_plaintext_abbr, cleaned_plaintext.length())); perplexity = computePerplexity(cleaned_plaintext); // if (Double.isNaN(perplexity)) { // double perplexity_new = -1d; // LOG.log(Level.WARNING, String.format("[%s '%s'] failed to get meaningful perplexity: %g. Setting perplexity to %g.", uri.toString(), cleaned_plaintext_abbr, perplexity, perplexity_new)); // perplexity = perplexity_new; // } LOG.finest(String.format("[%s, '%s'] perplexity: %g.", uri.toString(), cleaned_plaintext_abbr, perplexity)); } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.SEVERE, String.format("Could not compute perplexity for URI '%s' and text: '%s'. (%d %s:%s)", uri.toString(), cleaned_plaintext_abbr, i, t.getClass().getSimpleName(), t.getMessage()), t); t = t.getCause(); LOG.log(Level.SEVERE, "Requesting to pause crawl."); getCrawlController().requestCrawlPause(); _paused_due_to_error = true; } } if (!Double.isFinite(perplexity) || perplexity <= 1) { LOG.log(Level.FINE, String.format( "[%s '%s'] resetting infinite perplexity to predefined maximum perplexity value (-1).", uri.toString(), cleaned_plaintext_abbr)); perplexity = -1; } return perplexity; }
From source file:net.demilich.metastone.game.behaviour.decicionTreeBheavior.DecisionDataBase.java
public void addFeature(String name, boolean enemy, boolean minion) { int hash = name.hashCode(); if (!enemy) { if (!hashToIndex.containsKey(hash)) { database[databaseCount] = new CardContextKnowledge(name, hash); hashToIndex.put(hash, databaseCount); databaseCount++;/* w w w .ja va 2s . c om*/ } } if (enemy) { featureAndHash[0][enemyHandIndex] = enemyHandIndex; featureAndHash[1][enemyHandIndex] = hash; featureNames[enemyHandIndex] = "EH:" + name; this.featureHashToIndex.put(featureNames[enemyHandIndex].hashCode(), enemyHandIndex); enemyHandIndex++; if (minion) { featureAndHash[0][enemyMinionIndex] = enemyMinionIndex; featureAndHash[1][enemyMinionIndex] = hash; featureNames[enemyMinionIndex] = "EB:" + name; this.featureHashToIndex.put(featureNames[enemyMinionIndex].hashCode(), enemyMinionIndex); enemyMinionIndex++; } } else { featureAndHash[0][myHandIndex] = myHandIndex; featureAndHash[1][myHandIndex] = hash; featureNames[myHandIndex] = "MH:" + name; this.featureHashToIndex.put(featureNames[myHandIndex].hashCode(), myHandIndex); myHandIndex++; if (minion) { featureAndHash[0][myMinionIndex] = myMinionIndex; featureAndHash[1][myMinionIndex] = hash; featureNames[myMinionIndex] = "MB:" + name; this.featureHashToIndex.put(featureNames[myMinionIndex].hashCode(), myMinionIndex); myMinionIndex++; } } }
From source file:com.example.android.uamp.model.RemoteJSONSource.java
private MediaMetadataCompat buildFromJSON(JSONObject json, String basePath) throws JSONException { String title = json.getString(JSON_TITLE); String album = json.getString(JSON_ALBUM); String artist = json.getString(JSON_ARTIST); String genre = json.getString(JSON_GENRE); String source = json.getString(JSON_SOURCE); String iconUrl = json.getString(JSON_IMAGE); int trackNumber = json.getInt(JSON_TRACK_NUMBER); int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT); int duration = json.getInt(JSON_DURATION) * 1000; // ms LogHelper.d(TAG, "Found music track: ", json); // Media is stored relative to JSON file if (!source.startsWith("http")) { source = basePath + source;//from w ww . j a va 2 s. co m } if (!iconUrl.startsWith("http")) { iconUrl = basePath + iconUrl; } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer.java
private void storeStatement(Statement statement) throws IOException { // if the predicate list is empty, accept all predicates. // Otherwise, make sure the predicate is on the "valid" list boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate()); if (isValidPredicate && (statement.getObject() instanceof Literal)) { // Get the tokens String text = statement.getObject().stringValue().toLowerCase(); SortedSet<String> tokens = tokenizer.tokenize(text); if (!tokens.isEmpty()) { // Get Document Data String docContent = StatementSerializer.writeStatement(statement); String docId = Md5Hash.md5Base64(docContent); // Setup partition Text partition = genPartition(docContent.hashCode(), docTableNumPartitions); Mutation docTableMut = new Mutation(partition); List<Mutation> termTableMutations = new ArrayList<Mutation>(); Text docIdText = new Text(docId); // Store the Document Data docTableMut.put(ColumnPrefixes.DOCS_CF_PREFIX, docIdText, new Value(docContent.getBytes(Charsets.UTF_8))); // index the statement parts docTableMut.put(ColumnPrefixes.getSubjColFam(statement), docIdText, EMPTY_VALUE); docTableMut.put(ColumnPrefixes.getPredColFam(statement), docIdText, EMPTY_VALUE); docTableMut.put(ColumnPrefixes.getObjColFam(statement), docIdText, EMPTY_VALUE); docTableMut.put(ColumnPrefixes.getContextColFam(statement), docIdText, EMPTY_VALUE); // index the statement terms for (String token : tokens) { // tie the token to the document docTableMut.put(ColumnPrefixes.getTermColFam(token), docIdText, EMPTY_VALUE); // store the term in the term table (useful for wildcard searches) termTableMutations.add(createEmptyPutMutation(ColumnPrefixes.getTermListColFam(token))); termTableMutations.add(createEmptyPutMutation(ColumnPrefixes.getRevTermListColFam(token))); }/*from w ww . j av a2 s . c om*/ // write the mutations try { docTableBw.addMutation(docTableMut); termTableBw.addMutations(termTableMutations); } catch (MutationsRejectedException e) { logger.error("error adding mutation", e); throw new IOException(e); } } } }