List of usage examples for java.util SortedMap isEmpty
boolean isEmpty();
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);/*from w w w .ja va2 s .c om*/ 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: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 ww w . j a va2 s.c om 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:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java
private TupleModelDataSet getDataSet(final ITimeseriesCache humidity, final Calendar ptr, final String type) { final TreeMap<Date, TupleModelDataSet[]> valueMap = humidity.getValueMap(); final Date base = ptr.getTime(); final SortedMap<Date, TupleModelDataSet[]> headMap = valueMap.headMap(base); final SortedMap<Date, TupleModelDataSet[]> tailMap = valueMap.tailMap(base); if (!headMap.isEmpty() && DateUtils.isSameDay(headMap.lastKey(), base)) return getDataSet(headMap.get(headMap.lastKey()), type); else if (!tailMap.isEmpty() && DateUtils.isSameDay(tailMap.firstKey(), base)) return getDataSet(tailMap.get(tailMap.firstKey()), type); return null;//from ww w . j av a2s . c o m }
From source file:org.apache.hyracks.maven.license.GenerateFileMojo.java
private void resolveArtifactFiles(final String name, Predicate<JarEntry> filter, BiConsumer<Project, String> consumer, UnaryOperator<String> contentTransformer) throws MojoExecutionException, IOException { for (Project p : getProjects()) { File artifactFile = new File(p.getArtifactPath()); if (!artifactFile.exists()) { throw new MojoExecutionException("Artifact file " + artifactFile + " does not exist!"); } else if (!artifactFile.getName().endsWith(".jar")) { getLog().info("Skipping unknown artifact file type: " + artifactFile); continue; }//from www.j av a 2s . c om try (JarFile jarFile = new JarFile(artifactFile)) { SortedMap<String, JarEntry> matches = gatherMatchingEntries(jarFile, filter); if (matches.isEmpty()) { getLog().warn("No " + name + " file found for " + p.gav()); } else { if (matches.size() > 1) { getLog().warn("Multiple " + name + " files found for " + p.gav() + ": " + matches.keySet() + "; taking first"); } else { getLog().info(p.gav() + " has " + name + " file: " + matches.keySet()); } resolveContent(p, jarFile, matches.values().iterator().next(), contentTransformer, consumer, name); } } } }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setSaveRetrieveAndGetManySiblings() throws IOException { String accountAddress = randomAddress(); Repository repository = new RepositoryImplForTesting(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Block genesis = BlockGenerator.getGenesisBlock(); Block block1 = BlockGenerator.createChildBlock(genesis); Block block2 = BlockGenerator.createChildBlock(block1); Block block3 = BlockGenerator.createChildBlock(block2); Block block4 = BlockGenerator.createChildBlock(block3); Block block5 = BlockGenerator.createChildBlock(block4); Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1); Sibling sibling2 = new Sibling(block1.getHeader(), block1.getCoinbase(), 2); Sibling sibling3 = new Sibling(block2.getHeader(), block2.getCoinbase(), 3); Sibling sibling4 = new Sibling(block3.getHeader(), block3.getCoinbase(), 4); Sibling sibling5 = new Sibling(block4.getHeader(), block4.getCoinbase(), 5); Sibling sibling6 = new Sibling(block5.getHeader(), block5.getCoinbase(), 6); List<Sibling> siblings0 = new ArrayList<>(); List<Sibling> siblings1 = new ArrayList<>(); List<Sibling> siblings2 = new ArrayList<>(); siblings0.add(sibling1);/* w w w .j a va2 s . c o m*/ siblings0.add(sibling2); siblings1.add(sibling3); siblings1.add(sibling4); siblings2.add(sibling5); siblings2.add(sibling6); provider.getSiblings().put(Long.valueOf(0), siblings0); provider.getSiblings().put(Long.valueOf(1), siblings1); provider.getSiblings().put(Long.valueOf(2), siblings2); 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(0))); Assert.assertTrue(map.containsKey(Long.valueOf(1))); Assert.assertTrue(map.containsKey(Long.valueOf(2))); Assert.assertEquals(2, map.get(Long.valueOf(0)).size()); Assert.assertEquals(2, map.get(Long.valueOf(1)).size()); Assert.assertEquals(2, map.get(Long.valueOf(2)).size()); List<Sibling> list0 = map.get(Long.valueOf(0)); List<Sibling> list1 = map.get(Long.valueOf(1)); List<Sibling> list2 = map.get(Long.valueOf(2)); Assert.assertEquals(1, list0.get(0).getIncludedHeight()); Assert.assertArrayEquals(genesis.getHeader().getHash(), list0.get(0).getHash()); Assert.assertEquals(2, list0.get(1).getIncludedHeight()); Assert.assertArrayEquals(block1.getHeader().getHash(), list0.get(1).getHash()); Assert.assertEquals(3, list1.get(0).getIncludedHeight()); Assert.assertArrayEquals(block2.getHeader().getHash(), list1.get(0).getHash()); Assert.assertEquals(4, list1.get(1).getIncludedHeight()); Assert.assertArrayEquals(block3.getHeader().getHash(), list1.get(1).getHash()); Assert.assertEquals(5, list2.get(0).getIncludedHeight()); Assert.assertArrayEquals(block4.getHeader().getHash(), list2.get(0).getHash()); Assert.assertEquals(6, list2.get(1).getIncludedHeight()); Assert.assertArrayEquals(block5.getHeader().getHash(), list2.get(1).getHash()); }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createInstance() throws IOException { Repository repository = new RepositoryImpl(); BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR); SortedSet<Sha256Hash> processed = provider.getBtcTxHashesAlreadyProcessed(); Assert.assertNotNull(processed);//from w w w.j ava 2 s . c om Assert.assertTrue(processed.isEmpty()); SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> broadcasting = provider.getRskTxsWaitingForBroadcasting(); Assert.assertNotNull(broadcasting); Assert.assertTrue(broadcasting.isEmpty()); SortedMap<Sha3Hash, BtcTransaction> confirmations = provider.getRskTxsWaitingForConfirmations(); Assert.assertNotNull(confirmations); Assert.assertTrue(confirmations.isEmpty()); SortedMap<Sha3Hash, BtcTransaction> signatures = provider.getRskTxsWaitingForSignatures(); Assert.assertNotNull(signatures); Assert.assertTrue(signatures.isEmpty()); List<UTXO> utxos = provider.getBtcUTXOs(); Assert.assertNotNull(utxos); Assert.assertTrue(utxos.isEmpty()); Wallet wallet = provider.getWallet(); Assert.assertNotNull(wallet); Assert.assertNotNull(wallet.getCoinSelector()); }
From source file:org.apache.fop.afp.fonts.RasterFont.java
/** * Get the character set metrics for the specified point size. * * @param sizeInMpt the point size (in mpt) * @return the character set metrics//from w ww . j a v a2s . c om */ public CharacterSet getCharacterSet(int sizeInMpt) { Integer requestedSize = Integer.valueOf(sizeInMpt); CharacterSet csm = (CharacterSet) charSets.get(requestedSize); double sizeInPt = sizeInMpt / 1000.0; if (csm != null) { return csm; } if (substitutionCharSets != null) { //Check first if a substitution has already been added csm = (CharacterSet) substitutionCharSets.get(requestedSize); } if (csm == null && !charSets.isEmpty()) { // No match or substitution found, but there exist entries // for other sizes // Get char set with nearest, smallest font size SortedMap<Integer, CharacterSet> smallerSizes = charSets.headMap(requestedSize); SortedMap<Integer, CharacterSet> largerSizes = charSets.tailMap(requestedSize); int smallerSize = smallerSizes.isEmpty() ? 0 : ((Integer) smallerSizes.lastKey()).intValue(); int largerSize = largerSizes.isEmpty() ? Integer.MAX_VALUE : ((Integer) largerSizes.firstKey()).intValue(); Integer fontSize; if (!smallerSizes.isEmpty() && (sizeInMpt - smallerSize) <= (largerSize - sizeInMpt)) { fontSize = Integer.valueOf(smallerSize); } else { fontSize = Integer.valueOf(largerSize); } csm = (CharacterSet) charSets.get(fontSize); if (csm != null) { // Add the substitute mapping, so subsequent calls will // find it immediately if (substitutionCharSets == null) { substitutionCharSets = new HashMap<Integer, CharacterSet>(); } substitutionCharSets.put(requestedSize, csm); // do not output the warning if the font size is closer to an integer less than 0.1 if (!(Math.abs(fontSize.intValue() / 1000.0 - sizeInPt) < 0.1)) { String msg = "No " + sizeInPt + "pt font " + getFontName() + " found, substituted with " + fontSize.intValue() / 1000f + "pt font"; LOG.warn(msg); } } } if (csm == null) { // Still no match -> error String msg = "No font found for font " + getFontName() + " with point size " + sizeInPt; LOG.error(msg); throw new FontRuntimeException(msg); } return csm; }
From source file:org.cloudata.core.client.TabletLocationCache.java
private void removeFromCache(TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, TabletInfo removeTablet) { if (cache.containsKey(cacheRowKey)) { cache.remove(cacheRowKey);/*from w w w . j av a2s . c om*/ } SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey); if (tailMap.isEmpty()) { return; } Row.Key tailFirst = tailMap.firstKey(); TabletInfo tabletInfo = tailMap.get(tailFirst); if (tabletInfo.equals(removeTablet)) { cache.remove(tailFirst); } }
From source file:org.apache.sling.commons.metrics.internal.MetricWebConsolePlugin.java
private void addGaugeDetails(PrintWriter pw, SortedMap<String, Gauge> gauges) { if (gauges.isEmpty()) { return;/*w w w. j a v a2 s. c om*/ } pw.println("<br>"); pw.println("<div class='table'>"); pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Gauges</div>"); pw.println("<table class='nicetable' id='data-guages'>"); pw.println("<thead>"); pw.println("<tr>"); pw.println("<th class='header'>Name</th>"); pw.println("<th class='header'>Value</th>"); pw.println("</tr>"); pw.println("</thead>"); pw.println("<tbody>"); String rowClass = "odd"; for (Map.Entry<String, Gauge> e : gauges.entrySet()) { Gauge g = e.getValue(); String name = e.getKey(); pw.printf("<tr class='%s ui-state-default'>%n", rowClass); pw.printf("<td>%s</td>", name); pw.printf("<td>%s</td>", g.getValue()); pw.println("</tr>"); rowClass = "odd".equals(rowClass) ? "even" : "odd"; } pw.println("</tbody>"); pw.println("</table>"); pw.println("</div>"); }
From source file:org.apache.sling.commons.metrics.internal.MetricWebConsolePlugin.java
private void addCounterDetails(PrintWriter pw, SortedMap<String, Counter> counters) { if (counters.isEmpty()) { return;/*from w w w . j a v a 2 s.c om*/ } pw.println("<br>"); pw.println("<div class='table'>"); pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Counters</div>"); pw.println("<table class='nicetable' id='data-counters'>"); pw.println("<thead>"); pw.println("<tr>"); pw.println("<th class='header'>Name</th>"); pw.println("<th class='header'>Count</th>"); pw.println("</tr>"); pw.println("</thead>"); pw.println("<tbody>"); String rowClass = "odd"; for (Map.Entry<String, Counter> e : counters.entrySet()) { Counter c = e.getValue(); String name = e.getKey(); pw.printf("<tr class='%s ui-state-default'>%n", rowClass); pw.printf("<td>%s</td>", name); pw.printf("<td>%d</td>", c.getCount()); pw.println("</tr>"); rowClass = "odd".equals(rowClass) ? "even" : "odd"; } pw.println("</tbody>"); pw.println("</table>"); pw.println("</div>"); }