List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.opennaas.extensions.genericnetwork.test.capability.circuitstatistics.CircuitStatisticsCapabilityTest.java
@Test public void parseCSVTest() throws IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { String csvFile = IOUtils.toString(this.getClass().getResourceAsStream(CIRCUIT_STATISTICS_CSV_URL)); // call private method by reflection Method method = circuitStatisticsCapab.getClass().getDeclaredMethod("parseCSV", String.class); method.setAccessible(true);//from ww w . j a v a2 s . com @SuppressWarnings("unchecked") SortedMap<Long, List<CircuitStatistics>> statistics = (SortedMap<Long, List<CircuitStatistics>>) method .invoke(circuitStatisticsCapab, csvFile); Assert.assertNotNull("Parsed statistics should not be null.", statistics); Assert.assertEquals("Parsed statistics should contain 2 different timestamps", 2, statistics.keySet().size()); Assert.assertNotNull("Parsed statistics should contains statistics for timestamp " + FIRST_TIMESTAMP, statistics.get(FIRST_TIMESTAMP)); Assert.assertEquals("Parsed statistics should contain 2 statistics for timestamp" + FIRST_TIMESTAMP, 2, statistics.get(FIRST_TIMESTAMP).size()); CircuitStatistics firstStatistics = statistics.get(FIRST_TIMESTAMP).get(0); Assert.assertNotNull("First circuit statistics should not be null.", firstStatistics); Assert.assertEquals("Flow Id of first circuit statistics should be " + FIRST_CIRCUIT_FLOW_ID, FIRST_CIRCUIT_FLOW_ID, firstStatistics.getSlaFlowId()); Assert.assertEquals("Throughput of first circuit statistics should be " + FIRST_CIRCUIT_THROUGHPUT, FIRST_CIRCUIT_THROUGHPUT, firstStatistics.getThroughput()); Assert.assertEquals("Throughput of first circuit statistics should be " + FIRST_CIRCUIT_PACKET_LOSS, FIRST_CIRCUIT_PACKET_LOSS, firstStatistics.getPacketLoss()); Assert.assertEquals("Jitter of first circuit statistics should be " + FIRST_CIRCUIT_JITTER, FIRST_CIRCUIT_JITTER, firstStatistics.getJitter()); Assert.assertEquals("Flow Data of first circuit statistics should be " + FIRST_CIRCUIT_FLOW_DATA, FIRST_CIRCUIT_FLOW_DATA, firstStatistics.getFlowData()); Assert.assertEquals("Delay of first circuit statistics should be " + FIRST_CIRCUIT_DELAY, FIRST_CIRCUIT_DELAY, firstStatistics.getDelay()); CircuitStatistics secondStatistics = statistics.get(FIRST_TIMESTAMP).get(1); Assert.assertNotNull("Second circuit statistics should not be null.", secondStatistics); Assert.assertEquals("Flow Id of second circuit statistics should be " + SECOND_CIRCUIT_FLOW_ID, SECOND_CIRCUIT_FLOW_ID, secondStatistics.getSlaFlowId()); Assert.assertEquals("Throughput of second circuit statistics should be " + SECOND_CIRCUIT_THROUGHPUT, SECOND_CIRCUIT_THROUGHPUT, secondStatistics.getThroughput()); Assert.assertEquals("Throughput of second circuit statistics should be " + SECOND_CIRCUIT_PACKET_LOSS, SECOND_CIRCUIT_PACKET_LOSS, secondStatistics.getPacketLoss()); Assert.assertEquals("Jitter of second circuit statistics should be " + SECOND_CIRCUIT_JITTER, SECOND_CIRCUIT_JITTER, secondStatistics.getJitter()); Assert.assertEquals("Flow Data of second circuit statistics should be " + SECOND_CIRCUIT_FLOW_DATA, SECOND_CIRCUIT_FLOW_DATA, secondStatistics.getFlowData()); Assert.assertEquals("Delay of second circuit statistics should be " + SECOND_CIRCUIT_DELAY, SECOND_CIRCUIT_DELAY, secondStatistics.getDelay()); CircuitStatistics thirdStatistics = statistics.get(SECOND_TIMESTAMP).get(0); Assert.assertNotNull("Third circuit statistics should not be null.", thirdStatistics); Assert.assertEquals("Flow Id of Third circuit statistics should be " + THIRD_CIRCUIT_FLOW_ID, THIRD_CIRCUIT_FLOW_ID, thirdStatistics.getSlaFlowId()); Assert.assertEquals("Throughput of Third circuit statistics should be " + THIRD_CIRCUIT_THROUGHPUT, THIRD_CIRCUIT_THROUGHPUT, thirdStatistics.getThroughput()); Assert.assertEquals("Throughput of Third circuit statistics should be " + THIRD_CIRCUIT_PACKET_LOSS, THIRD_CIRCUIT_PACKET_LOSS, thirdStatistics.getPacketLoss()); Assert.assertEquals("Jitter of Third circuit statistics should be " + THIRD_CIRCUIT_JITTER, THIRD_CIRCUIT_JITTER, thirdStatistics.getJitter()); Assert.assertEquals("Flow Data of Third circuit statistics should be " + THIRD_CIRCUIT_FLOW_DATA, THIRD_CIRCUIT_FLOW_DATA, thirdStatistics.getFlowData()); Assert.assertEquals("Delay of Third circuit statistics should be " + THIRD_CIRCUIT_DELAY, THIRD_CIRCUIT_DELAY, thirdStatistics.getDelay()); }
From source file:com.restfb.util.InsightUtilsTest.java
@Test public void executeInsightQueriesByDate1() throws IOException, JSONException { // note that the query that is passed to the FacebookClient WebRequestor is // ignored,// w w w . j ava 2s .c om // so arguments of executeInsightQueriesByDate: // (String pageObjectId, Set<String> metrics, Period period) // are effectively ignored. In this test we are validating the // WebRequestor's json // is properly processed SortedMap<Date, JsonArray> results = executeInsightQueriesByDate( createFixedResponseFacebookClient("multiResponse_2metrics_1date.json"), TEST_PAGE_OBJECT, toStringSet("page_fans", "page_fans_gender"), Period.DAY, Collections.singleton(d20101205_0000pst)); Assert.assertNotNull(results); assertEquals(1, results.size()); JsonArray ja = results.get(d20101205_0000pst); Assert.assertNotNull(ja); // not ideal that this test requires on a stable JsonArray.toString() String expectedJson = "[{\"metric\":\"page_fans\",\"value\":3777},{\"metric\":\"page_fans_gender\",\"value\":{\"U\":58,\"F\":1656,\"M\":2014}}]"; JSONAssert.assertEquals(expectedJson, ja.toString(), JSONCompareMode.NON_EXTENSIBLE); }
From source file:fr.landel.utils.commons.MapUtils2Test.java
/** * Test method for/*w w w . ja v a 2 s. c o m*/ * {@link MapUtils2#newMap(java.util.function.Supplier, java.lang.Class, java.lang.Class, java.lang.Object[])}. */ @Test public void testNewMapSupplierClass() { SortedMap<String, Long> map = MapUtils2.newMap(TreeMap::new, String.class, Long.class, "key1", 1L, "key2", 2L); assertTrue(map instanceof TreeMap); assertEquals(2, map.size()); Map<String, Long> expectedMap = new HashMap<>(); expectedMap.put("key1", 1L); expectedMap.put("key2", 2L); for (Entry<String, Long> entry : expectedMap.entrySet()) { assertTrue(map.containsKey(entry.getKey())); assertEquals(entry.getValue(), map.get(entry.getKey())); } map = MapUtils2.newMap(TreeMap::new, String.class, Long.class); assertTrue(map instanceof TreeMap); assertTrue(map.isEmpty()); map = MapUtils2.newMap(() -> new TreeMap<>(Comparators.STRING.desc()), String.class, Long.class, "key1", 1L, "key2", 2L, null, 3L, "key4", null, 2d, 5L, "key6", true); assertTrue(map instanceof TreeMap); assertEquals(4, map.size()); "key2".equals(map.firstKey()); map = MapUtils2.newMap(TreeMap::new, String.class, Long.class, new Object[0]); assertTrue(map instanceof TreeMap); assertTrue(map.isEmpty()); assertException(() -> { MapUtils2.newMap(TreeMap::new, null, Long.class, "", ""); }, NullPointerException.class); assertException(() -> { MapUtils2.newMap(TreeMap::new, String.class, null, "", ""); }, NullPointerException.class); assertException(() -> { MapUtils2.newMap(null, String.class, Long.class, "", ""); }, NullPointerException.class); assertException(() -> { MapUtils2.newMap(TreeMap::new, String.class, Long.class, (Object[]) null); }, IllegalArgumentException.class, "objects cannot be null or empty and has to contain an odd number of elements"); assertException(() -> { MapUtils2.newMap(TreeMap::new, String.class, Long.class, "key"); }, IllegalArgumentException.class, "objects cannot be null or empty and has to contain an odd number of elements"); }
From source file:net.shipilev.fjptrace.tasks.PrintSummaryTask.java
@Override public void doWork() throws Exception { // walk the trees PrintWriter pw = new PrintWriter(fileName); LayerStatistics global = new LayerStatistics(); SortedMap<Integer, LayerStatistics> layerStats = new TreeMap<>(); for (Task t : subgraphs.getParents()) { // compute transitive closure Set<Task> visited = new HashSet<>(); Set<Long> workers = new HashSet<>(); List<Task> prev = new ArrayList<>(); List<Task> cur = new ArrayList<>(); int depth = 0; cur.add(t);//w ww . jav a 2s.co m while (visited.addAll(cur)) { prev.clear(); prev.addAll(cur); cur.clear(); Set<Long> layerWorkers = new HashSet<>(); LayerStatistics layerStat = layerStats.get(depth); if (layerStat == null) { layerStat = new LayerStatistics(); layerStats.put(depth, layerStat); } for (Task c : prev) { Collection<Task> children = c.getChildren(); if (!children.isEmpty()) { cur.addAll(children); } layerStat.arities.addValue(children.size()); layerStat.selfTime.addValue(c.getSelfTime() / 1_000_000.0); layerStat.totalTime.addValue(c.getTotalTime() / 1_000_000.0); global.selfTime.addValue(c.getSelfTime() / 1_000_000.0); global.totalTime.addValue(c.getTotalTime() / 1_000_000.0); global.arities.addValue(children.size()); layerWorkers.add(c.getWorker()); } layerStat.counts.addValue(prev.size()); layerStat.threads.addValue(layerWorkers.size()); workers.addAll(layerWorkers); depth++; } global.depths.addValue(depth); global.counts.addValue(visited.size()); global.threads.addValue(workers.size()); } pw.println("Summary statistics:"); pw.printf(" total external tasks = %.0f\n", layerStats.get(0).counts.getSum()); pw.printf(" total subtasks = %.0f\n", global.counts.getSum()); pw.printf(" total threads = %.0f\n", global.threads.getMean()); pw.println(); pw.println("Per task statistics:"); pw.printf(" tasks: sum = %10.0f, min = %5.2f, avg = %5.2f, max = %5.2f\n", global.counts.getSum(), global.counts.getMin(), global.counts.getMean(), global.counts.getMax()); pw.printf(" depth: min = %5.2f, avg = %5.2f, max = %5.2f\n", global.depths.getMin(), global.depths.getMean(), global.depths.getMax()); pw.printf(" arity: min = %5.2f, avg = %5.2f, max = %5.2f\n", global.arities.getMin(), global.arities.getMean(), global.arities.getMax()); pw.printf(" threads: min = %5.2f, avg = %5.2f, max = %5.2f\n", global.threads.getMin(), global.threads.getMean(), global.threads.getMax()); pw.println(); pw.println("Per task + per depth statistics:"); for (Integer depth : layerStats.keySet()) { LayerStatistics s = layerStats.get(depth); pw.printf(" Depth = %d: \n", depth); pw.printf(" tasks: sum = %10.0f, min = %5.2f, avg = %5.2f, max = %5.2f\n", s.counts.getSum(), s.counts.getMin(), s.counts.getMean(), s.counts.getMax()); pw.printf(" self time (ms): sum = %10.0f, min = %5.2f, avg = %5.2f, max = %5.2f\n", s.selfTime.getSum(), s.selfTime.getMin(), s.selfTime.getMean(), s.selfTime.getMax()); pw.printf(" total time (ms): sum = %10.0f, min = %5.2f, avg = %5.2f, max = %5.2f\n", s.totalTime.getSum(), s.totalTime.getMin(), s.totalTime.getMean(), s.totalTime.getMax()); pw.printf(" arity: min = %5.2f, avg = %5.2f, max = %5.2f\n", s.arities.getMin(), s.arities.getMean(), s.arities.getMax()); pw.printf(" threads: min = %5.2f, avg = %5.2f, max = %5.2f\n", s.threads.getMin(), s.threads.getMean(), s.threads.getMax()); } summarizeEvents(pw, events); pw.flush(); pw.close(); }
From source file:org.apache.falcon.resource.proxy.ExtensionManagerProxy.java
private void updateEntities(String extensionName, String jobName, SortedMap<EntityType, List<Entity>> entityMap, InputStream configStream, HttpServletRequest request) throws FalconException, IOException, JAXBException { List<Entity> feeds = entityMap.get(EntityType.FEED); List<Entity> processes = entityMap.get(EntityType.PROCESS); validateFeeds(feeds);//from ww w. j av a2 s. c o m validateProcesses(processes); List<String> feedNames = new ArrayList<>(); List<String> processNames = new ArrayList<>(); for (Map.Entry<EntityType, List<Entity>> entry : entityMap.entrySet()) { for (final Entity entity : entry.getValue()) { final String entityType = entity.getEntityType().toString(); final String entityName = entity.getName(); final HttpServletRequest bufferedRequest = getEntityStream(entity, entity.getEntityType(), request); entityProxyUtil.proxyUpdate(entityType, entityName, Boolean.FALSE, bufferedRequest, entity); if (!embeddedMode) { super.update(bufferedRequest, entity.getEntityType().toString(), entity.getName(), currentColo, Boolean.FALSE); } if (entity.getEntityType().equals(EntityType.FEED)) { feedNames.add(entity.getName()); } else { processNames.add(entity.getName()); } } } ExtensionMetaStore metaStore = ExtensionStore.getMetaStore(); byte[] configBytes = null; if (configStream != null) { configBytes = IOUtils.toByteArray(configStream); } metaStore.updateExtensionJob(jobName, extensionName, feedNames, processNames, configBytes); }
From source file:org.mule.devkit.doclet.Doclava.java
public static PackageInfo[] chooseModulePackages() { ClassInfo[] classes = Converter.rootClasses(); SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>(); for (ClassInfo cl : classes) { if (!cl.isModule()) { continue; }//from www . j a va 2 s . co m PackageInfo pkg = cl.containingPackage(); String name; if (pkg == null) { name = ""; } else { name = pkg.name(); } sorted.put(name, pkg); } ArrayList<PackageInfo> result = new ArrayList<PackageInfo>(); for (String s : sorted.keySet()) { PackageInfo pkg = sorted.get(s); result.add(pkg); } return result.toArray(new PackageInfo[result.size()]); }
From source file:com.abuabdul.knodex.service.KxDocumentServiceImpl.java
public SortedMap<String, List<KnodexDoc>> listAllSentences() { log.debug("Entered KxDocumentServiceImpl.listAllSentences method"); String indexKey = ""; List<KnodexDoc> indexKnodexList = null; SortedMap<String, List<KnodexDoc>> fullListOfSentences = null; List<KnodexDoc> listAllKnodex = knodexDAO.findAll(); if (listAllKnodex != null && !listAllKnodex.isEmpty()) { log.debug("The size of the overall key with sentences " + listAllKnodex.size()); fullListOfSentences = new TreeMap<String, List<KnodexDoc>>(); for (KnodexDoc knodexDoc : listAllKnodex) { if (knodexDoc != null && !StringUtils.isEmpty(knodexDoc.getKey())) { indexKey = knodexDoc.getKey(); log.debug("Index key to get the list of sentences for each indexBy value " + indexKey); if (!fullListOfSentences.isEmpty() && fullListOfSentences.containsKey(indexKey)) { indexKnodexList = fullListOfSentences.get(indexKey); if (indexKnodexList == null) { // Ideally this code will not execute indexKnodexList = new ArrayList<KnodexDoc>(); }/*from ww w.j a va 2 s .com*/ indexKnodexList.add(knodexDoc); } else { indexKnodexList = new ArrayList<KnodexDoc>(); indexKnodexList.add(knodexDoc); fullListOfSentences.put(indexKey, indexKnodexList); } } } } return fullListOfSentences; }
From source file:org.optaplanner.benchmark.impl.DefaultPlannerBenchmark.java
private List<List<SolverBenchmark>> createSameRankingListList( List<SolverBenchmark> rankableSolverBenchmarkList) { List<List<SolverBenchmark>> sameRankingListList = new ArrayList<List<SolverBenchmark>>( rankableSolverBenchmarkList.size()); if (solverBenchmarkRankingComparator != null) { Comparator<SolverBenchmark> comparator = Collections.reverseOrder(solverBenchmarkRankingComparator); Collections.sort(rankableSolverBenchmarkList, comparator); List<SolverBenchmark> sameRankingList = null; SolverBenchmark previousSolverBenchmark = null; for (SolverBenchmark solverBenchmark : rankableSolverBenchmarkList) { if (previousSolverBenchmark == null || comparator.compare(previousSolverBenchmark, solverBenchmark) != 0) { // New rank sameRankingList = new ArrayList<SolverBenchmark>(); sameRankingListList.add(sameRankingList); }/*from ww w . j a va 2 s .com*/ sameRankingList.add(solverBenchmark); previousSolverBenchmark = solverBenchmark; } } else if (solverBenchmarkRankingWeightFactory != null) { SortedMap<Comparable, List<SolverBenchmark>> rankedMap = new TreeMap<Comparable, List<SolverBenchmark>>( new ReverseComparator()); for (SolverBenchmark solverBenchmark : rankableSolverBenchmarkList) { Comparable rankingWeight = solverBenchmarkRankingWeightFactory .createRankingWeight(rankableSolverBenchmarkList, solverBenchmark); List<SolverBenchmark> sameRankingList = rankedMap.get(rankingWeight); if (sameRankingList == null) { sameRankingList = new ArrayList<SolverBenchmark>(); rankedMap.put(rankingWeight, sameRankingList); } sameRankingList.add(solverBenchmark); } for (Map.Entry<Comparable, List<SolverBenchmark>> entry : rankedMap.entrySet()) { sameRankingListList.add(entry.getValue()); } } else { throw new IllegalStateException("Ranking is impossible" + " because solverBenchmarkRankingComparator and solverBenchmarkRankingWeightFactory are null."); } return sameRankingListList; }
From source file:org.apache.falcon.resource.proxy.ExtensionManagerProxy.java
private void submitEntities(String extensionName, String jobName, SortedMap<EntityType, List<Entity>> entityMap, InputStream configStream, HttpServletRequest request) throws FalconException, IOException, JAXBException { List<Entity> feeds = entityMap.get(EntityType.FEED); List<Entity> processes = entityMap.get(EntityType.PROCESS); validateFeeds(feeds);/*from w w w . j a v a 2 s .co m*/ validateProcesses(processes); List<String> feedNames = new ArrayList<>(); List<String> processNames = new ArrayList<>(); ExtensionMetaStore metaStore = ExtensionStore.getMetaStore(); byte[] configBytes = null; if (configStream != null) { configBytes = IOUtils.toByteArray(configStream); } for (Map.Entry<EntityType, List<Entity>> entry : entityMap.entrySet()) { for (final Entity entity : entry.getValue()) { if (entity.getEntityType().equals(EntityType.FEED)) { feedNames.add(entity.getName()); } else { processNames.add(entity.getName()); } } } metaStore.storeExtensionJob(jobName, extensionName, feedNames, processNames, configBytes); for (Map.Entry<EntityType, List<Entity>> entry : entityMap.entrySet()) { for (final Entity entity : entry.getValue()) { final HttpServletRequest bufferedRequest = getEntityStream(entity, entity.getEntityType(), request); final Set<String> colos = getApplicableColos(entity.getEntityType().toString(), entity); entityProxyUtil.proxySubmit(entity.getEntityType().toString(), bufferedRequest, entity, colos); if (!embeddedMode) { super.submit(bufferedRequest, entity.getEntityType().toString(), currentColo); } } } }
From source file:marytts.language.de.JPhonemiser.java
public void shutdown() { if (logUnknownFileName != null || logEnglishFileName != null) { try {/*from w w w. j a v a2 s . c o m*/ /* print unknown words */ //open file PrintWriter logUnknown = new PrintWriter( new OutputStreamWriter(new FileOutputStream(logUnknownFileName), "UTF-8")); //sort the words Set<String> unknownWords = unknown2Frequency.keySet(); SortedMap<Integer, List<String>> freq2Unknown = new TreeMap<Integer, List<String>>(); for (String nextUnknown : unknownWords) { int nextFreq = unknown2Frequency.get(nextUnknown); //logUnknown.println(nextFreq+" "+nextUnknown); if (freq2Unknown.containsKey(nextFreq)) { List<String> unknowns = freq2Unknown.get(nextFreq); unknowns.add(nextUnknown); } else { List<String> unknowns = new ArrayList<String>(); unknowns.add(nextUnknown); freq2Unknown.put(nextFreq, unknowns); } } //print the words for (int nextFreq : freq2Unknown.keySet()) { List<String> unknowns = freq2Unknown.get(nextFreq); for (int i = 0; i < unknowns.size(); i++) { String unknownWord = (String) unknowns.get(i); logUnknown.println(nextFreq + " " + unknownWord); } } //close file logUnknown.flush(); logUnknown.close(); /* print english words */ //open the file PrintWriter logEnglish = new PrintWriter( new OutputStreamWriter(new FileOutputStream(logEnglishFileName), "UTF-8")); //sort the words SortedMap<Integer, List<String>> freq2English = new TreeMap<Integer, List<String>>(); for (String nextEnglish : english2Frequency.keySet()) { int nextFreq = english2Frequency.get(nextEnglish); if (freq2English.containsKey(nextFreq)) { List<String> englishWords = freq2English.get(nextFreq); englishWords.add(nextEnglish); } else { List<String> englishWords = new ArrayList<String>(); englishWords.add(nextEnglish); freq2English.put(nextFreq, englishWords); } } //print the words for (int nextFreq : freq2English.keySet()) { List<String> englishWords = freq2English.get(nextFreq); for (int i = 0; i < englishWords.size(); i++) { logEnglish.println(nextFreq + " " + englishWords.get(i)); } } //close file logEnglish.flush(); logEnglish.close(); } catch (Exception e) { logger.info("Error printing log files for english and unknown words", e); } } }