List of usage examples for java.lang String hashCode
public int hashCode()
From source file:eagle.log.entity.meta.IndexDefinition.java
private int[] generatePartitionHashCodes(TaggedLogAPIEntity entity) { final String[] partitions = entityDef.getPartitions(); int[] result = null; if (partitions != null) { result = new int[partitions.length]; final Map<String, String> tags = entity.getTags(); for (int i = 0; i < partitions.length; ++i) { final String partition = partitions[i]; final String tagValue = tags.get(partition); if (tagValue != null) { result[i] = tagValue.hashCode(); } else { result[i] = EMPTY_PARTITION_DEFAULT_HASH_CODE; }/*from w w w . j a v a 2 s . c o m*/ } } return result; }
From source file:com.github.stephanarts.cas.ticket.registry.provider.GetMethodTest.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 GetMethod(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); params.put("ticket-id", ticketId); try {/*from ww w. j a va 2 s .c o m*/ 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:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.impl.AbstractVirtualDataSourceQueryServiceImpl.java
private String getJdbcDataSourceID(JdbcDataSource jdbcDataSource) { String key = jdbcDataSource.getConnectionUrl() + "|" + jdbcDataSource.getDriverClass() + "|" + jdbcDataSource.getUsername() + "|" + jdbcDataSource.getPassword(); return key.hashCode() + ""; }
From source file:de.schildbach.wallet.litecoin.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) { LycBtcRate = getLycBtcRate();/*from w ww .j av a2s . c o m*/ if (LycBtcRate == null) return null; Map<String, ExchangeRate> newExchangeRates = getBlockchainInfo(); if (exchangeRates == null && newExchangeRates == null) newExchangeRates = getLycancoinCharts(); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now; } } 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("Lycancoin", "Unable to add an exchange rate. NullPointerException."); } } return cursor; }
From source file:com.wsc.myexample.decisionForest.MyDataset.java
@Override public int hashCode() { int hashCode = labelId + 31 * nbInstances; for (Dataset.Attribute attr : attributes) { hashCode = 31 * hashCode + attr.hashCode(); }//from w ww .j a va2s. com for (String[] valueRow : values) { if (valueRow == null) { continue; } for (String value : valueRow) { hashCode = 31 * hashCode + value.hashCode(); } } return hashCode; }
From source file:com.github.stephanarts.cas.ticket.registry.provider.GetMethod.java
/** * Execute the JSONRPCFunction./*from w w w .j a v a2 s . c o m*/ * * @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(); Ticket ticket; logger.debug("GET"); 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"); ticket = this.map.get(ticketId.hashCode()); if (ticket == null) { throw new JSONRPCException(-32503, "Missing Ticket"); } byte[] serializedTicketArray = { 0 }; try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicketArray = bo.toByteArray(); } catch (final Exception e) { logger.debug(e.getMessage()); throw new JSONRPCException(-32500, "Error extracting Ticket"); } result.put("ticket-id", ticketId); result.put("ticket", DatatypeConverter.printBase64Binary(serializedTicketArray)); return result; }
From source file:Coordinate.java
/** * Overide the default hashcode method//from w w w .j a v a 2 s . c o m * * @return a hashcode for this object */ public int hashCode() { String me = this.getLatitudeAsString() + this.getLongitudeAsString(); return 31 * me.hashCode(); }
From source file:com.yahoo.ycsb.db.JdbcDBClient.java
/** * For the given key, returns what shard contains data for this key. * * @param key Data key to do operation on * @return Shard index/*from w w w. j ava2 s. c o m*/ */ private int getShardIndexByKey(String key) { int ret = Math.abs(key.hashCode()) % conns.size(); return ret; }
From source file:com.opengamma.financial.analytics.ircurve.strips.CurveNodeWithIdentifier.java
@Override protected void propertySet(String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 771167121: // curveNode setCurveNode((CurveNode) newValue); return;/*ww w . j a v a 2 s . c om*/ case -1618432855: // identifier setIdentifier((ExternalId) newValue); return; case -386794640: // dataField setDataField((String) newValue); return; case 1265211220: // fieldType setFieldType((DataFieldType) newValue); return; } super.propertySet(propertyName, newValue, quiet); }
From source file:edu.mayo.cts2.framework.plugin.service.bioportal.transform.AbstractBioportalOntologyVersionTransformTemplate.java
/** * Transform resource versions.//from www . j a va2s. c o m * * @param xml the xml * @return the list */ public List<S> transformResourceVersions(String xml) { if (!this.cachedVersionSummaries.containsKey(xml.hashCode())) { this.cachedVersionSummaries.clear(); this.cachedVersionSummaries.put(xml.hashCode(), this.doTransformResourceVersions(xml)); } return new ArrayList<S>(this.cachedVersionSummaries.get(xml.hashCode())); }