List of usage examples for java.util SortedMap containsKey
boolean containsKey(Object key);
From source file:edu.northwestern.bioinformatics.studycalendar.restlets.SchedulePreviewResource.java
public SortedMap<Date, List<ScheduledActivity>> createActivitiesByDate( List<ScheduledActivity> scheduledActivities) { SortedMap<Date, List<ScheduledActivity>> byDate = new TreeMap<Date, List<ScheduledActivity>>(); Collections.sort(scheduledActivities); for (ScheduledActivity scheduledActivity : scheduledActivities) { Date key = scheduledActivity.getActualDate(); if (!byDate.containsKey(key)) { byDate.put(key, new ArrayList<ScheduledActivity>()); }//from w w w .ja va 2 s. c om byDate.get(key).add(scheduledActivity); } return byDate; }
From source file:org.apache.hadoop.hbase.regionserver.tableindexed.IndexedRegion.java
private void removeOldIndexEntry(IndexSpecification indexSpec, byte[] row, SortedMap<byte[], byte[]> oldColumnValues) throws IOException { for (byte[] indexedCol : indexSpec.getIndexedColumns()) { if (!oldColumnValues.containsKey(indexedCol)) { LOG.debug("Index [" + indexSpec.getIndexId() + "] not trying to remove old entry for row [" + Bytes.toString(row) + "] because col [" + Bytes.toString(indexedCol) + "] is missing"); return; }// ww w.j a v a 2 s . com } byte[] oldIndexRow = indexSpec.getKeyGenerator().createIndexKey(row, oldColumnValues); LOG.debug( "Index [" + indexSpec.getIndexId() + "] removing old entry [" + Bytes.toString(oldIndexRow) + "]"); getIndexTable(indexSpec).deleteAll(oldIndexRow); }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setAndGetSiblings() { String accountAddress = randomAddress(); Repository repository = new RepositoryImpl(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Block genesis = BlockGenerator.getGenesisBlock(); Block block = BlockGenerator.createChildBlock(genesis); Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1); Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2); List<Sibling> siblings = new ArrayList<>(); siblings.add(sibling1);/* w w w . ja va 2 s . c o m*/ siblings.add(sibling2); provider.getSiblings().put(Long.valueOf(1), siblings); SortedMap<Long, List<Sibling>> map = provider.getSiblings(); Assert.assertNotNull(map); Assert.assertFalse(map.isEmpty()); Assert.assertTrue(map.containsKey(Long.valueOf(1))); Assert.assertEquals(2, map.get(Long.valueOf(1)).size()); }
From source file:de.micromata.genome.gwiki.controls.GWikiUserRightsPropsDescriptorValue.java
@Override public String render(GWikiPropsEditorArtefakt<?> editor, PropsEditContext pct) { GWikiAuthorization auth = pct.getWikiContext().getWikiWeb().getAuthorization(); if ((auth instanceof GWikiAuthorizationExt) == false) { return super.render(editor, pct); }//w w w . ja va 2 s.c o m GWikiAuthorizationExt authx = (GWikiAuthorizationExt) auth; SortedMap<String, GWikiRight> systemRights = authx.getSystemRights(pct.getWikiContext()); String pval = pct.getPropsValue(); SortedMap<String, GWikiRight> usr = authx.getUserRight(pct.getWikiContext(), systemRights, pval); for (Map.Entry<String, GWikiRight> me : usr.entrySet()) { if (systemRights.containsKey(me.getKey()) == false) { systemRights.put(me.getKey(), me.getValue()); } } Map<String, List<GWikiRight>> groups = new TreeMap<String, List<GWikiRight>>(); for (Map.Entry<String, GWikiRight> me : systemRights.entrySet()) { List<GWikiRight> gr = groups.get(me.getValue().getCategory()); if (gr == null) { gr = new ArrayList<GWikiRight>(); groups.put(me.getValue().getCategory(), gr); } gr.add(me.getValue()); } StringBuilder sb = new StringBuilder(); sb.append("<ul>\n"); for (Map.Entry<String, List<GWikiRight>> ge : groups.entrySet()) { sb.append("<li>").append(ge.getKey()).append("<br/><ul>"); for (GWikiRight r : ge.getValue()) { if (r.isPrivateRight() == true) { continue; } sb.append("<li><input type=\"checkbox\" name=\"right.").append(r.getName()).append("\""); if (usr.containsKey(r.getName()) == true) { sb.append(" checked=\"checked\""); } sb.append(">"); if (StringUtils.isNotBlank(r.getDescription()) == true) { sb.append("<a href=\"#\" title=\"") // .append(StringEscapeUtils.escapeXml(r.getDescription())).append("\">") .append(StringEscapeUtils.escapeXml(r.getName())).append("</a>"); } else { sb.append(StringEscapeUtils.escapeXml(r.getName())); } sb.append("</li>\n"); } sb.append("</ul></li>\n"); } // for (Map.Entry<String, GWikiRight> me : systemRights.entrySet()) { // // } sb.append("</ul>\n"); return sb.toString();// + super.render(editor, pct); }
From source file:com.opengamma.web.server.push.ViewportDefinition.java
/** Helper method to get the row numbers and timestamps from JSON */ private static SortedMap<Integer, Long> getRows(JSONObject jsonObject, String viewportId) throws JSONException { JSONObject viewportJson = jsonObject.optJSONObject(viewportId); SortedMap<Integer, Long> rows = new TreeMap<Integer, Long>(); if (viewportJson == null) { return rows; }/*from ww w . jav a 2s. c o m*/ JSONArray rowIds = viewportJson.getJSONArray(ROW_IDS); if (rowIds.length() < 1) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, a viewport must contain at least one row"); } JSONArray lastTimestamps = viewportJson.getJSONArray(LAST_TIMESTAMPS); if (rowIds.length() != lastTimestamps.length()) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, the viewport definition must specify the same number " + "of rows and timestamps"); } for (int i = 0; i < rowIds.length(); i++) { int rowId = rowIds.getInt(i); if (rowId < 0) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, row numbers must not be negative"); } if (rows.containsKey(rowId)) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, duplicate row number: " + rowId); } Long timestamp = lastTimestamps.optLong(i); if (timestamp < 0) { throw new IllegalArgumentException( "Unable to create ViewportDefinition from JSON, timestamps must not be negative: " + timestamp); } else if (timestamp == 0) { timestamp = null; } rows.put(rowId, timestamp); } return rows; }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setSaveRetrieveAndGetSiblings() throws IOException { String accountAddress = randomAddress(); Repository repository = new RepositoryImplForTesting(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Block genesis = BlockGenerator.getGenesisBlock(); Block block = BlockGenerator.createChildBlock(genesis); Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1); Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2); List<Sibling> siblings = new ArrayList<>(); siblings.add(sibling1);/*from w w w .j a v a2 s. c o m*/ siblings.add(sibling2); provider.getSiblings().put(Long.valueOf(1), siblings); provider.save(); RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress); SortedMap<Long, List<Sibling>> map = newProvider.getSiblings(); Assert.assertNotNull(map); Assert.assertFalse(map.isEmpty()); Assert.assertTrue(map.containsKey(Long.valueOf(1))); Assert.assertEquals(2, map.get(Long.valueOf(1)).size()); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java
@SuppressWarnings("unchecked") public static void printResultStatistics(File xmlFile) throws IllegalAccessException { Map<String, Map<String, GraphCleaningResults>> results = (Map<String, Map<String, GraphCleaningResults>>) XStreamTools .getXStream().fromXML(xmlFile); // System.out.println(results); SortedMap<String, List<GraphCleaningResults>> resultsGroupedByMethod = new TreeMap<>(); for (Map.Entry<String, Map<String, GraphCleaningResults>> entry : results.entrySet()) { // System.out.println(entry.getKey()); for (Map.Entry<String, GraphCleaningResults> e : entry.getValue().entrySet()) { // System.out.println(e.getKey()); // System.out.println(e.getValue()); if (!resultsGroupedByMethod.containsKey(e.getKey())) { resultsGroupedByMethod.put(e.getKey(), new ArrayList<GraphCleaningResults>()); }/*from w ww.j a va 2s .c om*/ resultsGroupedByMethod.get(e.getKey()).add(e.getValue()); } } String header = null; // collect statistics for (Map.Entry<String, List<GraphCleaningResults>> entry : resultsGroupedByMethod.entrySet()) { List<GraphCleaningResults> value = entry.getValue(); SortedMap<String, DescriptiveStatistics> stringDescriptiveStatisticsMap = collectStatisticsOverGraphCleaningResults( value); if (header == null) { header = StringUtils.join(stringDescriptiveStatisticsMap.keySet(), "\t"); System.out.println("\t\t" + header); } List<Double> means = new ArrayList<>(); List<Double> stdDevs = new ArrayList<>(); for (DescriptiveStatistics statistics : stringDescriptiveStatisticsMap.values()) { means.add(statistics.getMean()); stdDevs.add(statistics.getStandardDeviation()); } List<String> meansString = new ArrayList<>(); for (Double mean : means) { meansString.add(String.format(Locale.ENGLISH, "%.2f", mean)); } List<String> stdDevString = new ArrayList<>(); for (Double stdDev : stdDevs) { stdDevString.add(String.format(Locale.ENGLISH, "%.2f", stdDev)); } System.out.println(entry.getKey() + "\tmean\t" + StringUtils.join(meansString, "\t")); // System.out.println(entry.getKey() + "\tstdDev\t" + StringUtils.join(stdDevString, "\t")); } }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createSaveAndRecreateInstanceWithTxsWaitingForSignatures() throws IOException { BtcTransaction tx1 = createTransaction(); BtcTransaction tx2 = createTransaction(); BtcTransaction tx3 = createTransaction(); Sha3Hash hash1 = PegTestUtils.createHash3(); Sha3Hash hash2 = PegTestUtils.createHash3(); Sha3Hash hash3 = PegTestUtils.createHash3(); Repository repository = new RepositoryImpl(); Repository track = repository.startTracking(); BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); provider0.getRskTxsWaitingForSignatures().put(hash1, tx1); provider0.getRskTxsWaitingForSignatures().put(hash2, tx2); provider0.getRskTxsWaitingForSignatures().put(hash3, tx3); provider0.save();//w w w .jav a 2s . com track.commit(); track = repository.startTracking(); BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); SortedMap<Sha3Hash, BtcTransaction> signatures = provider.getRskTxsWaitingForSignatures(); Assert.assertNotNull(signatures); Assert.assertTrue(signatures.containsKey(hash1)); Assert.assertTrue(signatures.containsKey(hash2)); Assert.assertTrue(signatures.containsKey(hash3)); Assert.assertEquals(tx1.getHash(), signatures.get(hash1).getHash()); Assert.assertEquals(tx2.getHash(), signatures.get(hash2).getHash()); Assert.assertEquals(tx3.getHash(), signatures.get(hash3).getHash()); }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createSaveAndRecreateInstanceWithTxsWaitingForConfirmations() throws IOException { BtcTransaction tx1 = createTransaction(); BtcTransaction tx2 = createTransaction(); BtcTransaction tx3 = createTransaction(); Sha3Hash hash1 = PegTestUtils.createHash3(); Sha3Hash hash2 = PegTestUtils.createHash3(); Sha3Hash hash3 = PegTestUtils.createHash3(); Repository repository = new RepositoryImpl(); Repository track = repository.startTracking(); BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); provider0.getRskTxsWaitingForConfirmations().put(hash1, tx1); provider0.getRskTxsWaitingForConfirmations().put(hash2, tx2); provider0.getRskTxsWaitingForConfirmations().put(hash3, tx3); provider0.save();//from w w w . ja v a 2s . com track.commit(); track = repository.startTracking(); BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); SortedMap<Sha3Hash, BtcTransaction> confirmations = provider.getRskTxsWaitingForConfirmations(); Assert.assertNotNull(confirmations); Assert.assertTrue(confirmations.containsKey(hash1)); Assert.assertTrue(confirmations.containsKey(hash2)); Assert.assertTrue(confirmations.containsKey(hash3)); Assert.assertEquals(tx1.getHash(), confirmations.get(hash1).getHash()); Assert.assertEquals(tx2.getHash(), confirmations.get(hash2).getHash()); Assert.assertEquals(tx3.getHash(), confirmations.get(hash3).getHash()); }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createSaveAndRecreateInstanceWithTxsWaitingForBroadcasting() throws IOException { BtcTransaction tx1 = createTransaction(); BtcTransaction tx2 = createTransaction(); BtcTransaction tx3 = createTransaction(); Sha3Hash hash1 = PegTestUtils.createHash3(); Sha3Hash hash2 = PegTestUtils.createHash3(); Sha3Hash hash3 = PegTestUtils.createHash3(); Repository repository = new RepositoryImpl(); Repository track = repository.startTracking(); BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); provider0.getRskTxsWaitingForBroadcasting().put(hash1, Pair.of(tx1, new Long(1))); provider0.getRskTxsWaitingForBroadcasting().put(hash2, Pair.of(tx2, new Long(2))); provider0.getRskTxsWaitingForBroadcasting().put(hash3, Pair.of(tx3, new Long(3))); provider0.save();//from w ww. j a va 2 s .com track.commit(); track = repository.startTracking(); BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> broadcasting = provider.getRskTxsWaitingForBroadcasting(); Assert.assertNotNull(broadcasting); Assert.assertTrue(broadcasting.containsKey(hash1)); Assert.assertTrue(broadcasting.containsKey(hash2)); Assert.assertTrue(broadcasting.containsKey(hash3)); Assert.assertEquals(tx1.getHash(), broadcasting.get(hash1).getLeft().getHash()); Assert.assertEquals(tx2.getHash(), broadcasting.get(hash2).getLeft().getHash()); Assert.assertEquals(tx3.getHash(), broadcasting.get(hash3).getLeft().getHash()); Assert.assertEquals(1, broadcasting.get(hash1).getRight().intValue()); Assert.assertEquals(2, broadcasting.get(hash2).getRight().intValue()); Assert.assertEquals(3, broadcasting.get(hash3).getRight().intValue()); }