List of usage examples for java.util SortedMap get
V get(Object key);
From source file:com.vrem.wifianalyzer.vendor.model.VendorServiceTest.java
@Test public void testFindAll() throws Exception { // setup/*from ww w .jav a 2 s . co m*/ List<VendorData> vendorData = withVendorData(); when(database.findAll()).thenReturn(vendorData); // execute SortedMap<String, List<String>> actual = fixture.findAll(); // validate verify(database).findAll(); assertEquals(3, actual.size()); assertEquals(1, actual.get(VendorNameUtils.cleanVendorName(vendorData.get(0).getName())).size()); assertEquals(3, actual.get(VendorNameUtils.cleanVendorName(vendorData.get(1).getName())).size()); assertEquals(1, actual.get(VendorNameUtils.cleanVendorName(vendorData.get(4).getName())).size()); List<String> macs = actual.get(VendorNameUtils.cleanVendorName(vendorData.get(1).getName())); assertEquals(vendorData.get(3).getMac(), macs.get(0)); assertEquals(vendorData.get(1).getMac(), macs.get(1)); assertEquals(vendorData.get(2).getMac(), macs.get(2)); }
From source file:wzw.util.TestUtils.java
/** * //from w ww . j a v a 2 s . c om * <p>public? * ?main??</p> * @author Zeven on 2008-2-1 * @param clazz */ public static void testAllMethod(Class<?> clazz) { try { String[] defaultMethods = { "equals", "wait", "getClass", "notify", "hashCode", "toString", "main", "notifyAll" }; SortedMap<String, String> map = new TreeMap<String, String>(); Method[] md = clazz.getMethods(); for (int i = 0, j = 1; i < md.length; i++) { if (ArrayUtils.contains(defaultMethods, md[i].getName())) { continue; } map.put("" + j++, md[i].getName()); } map.put("q", "quit from class test."); //get a br BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); //read characters Iterator<Map.Entry<String, String>> it = null; Map.Entry<String, String> mapen = null; String val = null; String k; System.out.println("please chose ..."); it = map.entrySet().iterator(); do { while (it.hasNext()) { mapen = it.next(); System.out.println(mapen.getKey() + "\t" + mapen.getValue()); } System.out.print("> "); k = br1.readLine(); if ("q".equals(k)) { break; } if (map.get(k) != null) { val = map.get(k).toString(); System.out.println("**************** begin *" + val + "* ..."); clazz.getMethod(val, null).invoke(null, null); System.out.println("**************** *" + val + "* test success."); continue; } System.out.println("invalid choose,please choose again!"); System.out.println("please chose ..."); it = map.entrySet().iterator(); } while (true); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openmrs.module.drughistory.api.impl.DrugSnapshotServiceImpl.java
private Map<Person, SortedMap<Date, List<DrugEvent>>> groupByPersonAndDate(List<DrugEvent> events) { Map<Person, SortedMap<Date, List<DrugEvent>>> m = new HashMap<Person, SortedMap<Date, List<DrugEvent>>>(); for (DrugEvent de : events) { if (!m.containsKey(de.getPerson())) { m.put(de.getPerson(), new TreeMap<Date, List<DrugEvent>>()); }/* w w w .j av a2 s.co m*/ SortedMap<Date, List<DrugEvent>> mm = m.get(de.getPerson()); if (!mm.containsKey(de.getDateOccurred())) { mm.put(de.getDateOccurred(), new ArrayList<DrugEvent>()); } mm.get(de.getDateOccurred()).add(de); } return m; }
From source file:com.github.lukaszbudnik.dqueue.OrderedQueueClientIntegrationTest.java
@After public void after() throws Exception { session.execute("drop keyspace " + cassandraKeyspace); SortedMap<String, Timer> timers = metricRegistry.getTimers(); timers.keySet().stream().forEach(k -> { Timer t = timers.get(k); System.out.println(k);/* w ww . ja v a 2 s.co m*/ System.out.println("\ttimes called ==> " + t.getCount()); System.out.println("\tmedian ==> " + t.getSnapshot().getMedian() / 1000 / 1000); System.out.println("\t75th percentile ==> " + t.getSnapshot().get75thPercentile() / 1000 / 1000); System.out.println("\t99th percentile ==> " + t.getSnapshot().get99thPercentile() / 1000 / 1000); }); SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks(); healthChecks.keySet().stream().forEach(k -> { HealthCheck.Result healthCheck = healthChecks.get(k); System.out.println(k + " healthy? ==> " + healthCheck.isHealthy()); }); queueClient.close(); }
From source file:com.octo.mbo.domain.ApproachingMatcher.java
public Optional<String> findBestMatch(Collection<String> srcSlidesKeys, Collection<String> tgtSlideKeys, String tgtKeyToMatch) {//from w w w. ja v a 2 s.co m assert srcSlidesKeys != null; assert tgtSlideKeys != null; assert tgtKeyToMatch != null; SortedMap<Integer, Set<String>> sortedSrcSlidesKeys = sortByDistanceWithKey(srcSlidesKeys, tgtKeyToMatch); int smallestDistanceBtwTgtKeyToMatchAndSrcKey = sortedSrcSlidesKeys.firstKey(); Set<String> potentialKeys = sortedSrcSlidesKeys.get(smallestDistanceBtwTgtKeyToMatchAndSrcKey); if (potentialKeys.size() > 1) { log.warn("Tgt key '{}' could both match {} with levenstein distance {}", tgtKeyToMatch, potentialKeys, smallestDistanceBtwTgtKeyToMatchAndSrcKey); return Optional.empty(); } else { String potentialKey = potentialKeys.iterator().next(); //Be sure that this potential key is to at the equal distance of another tgtKey SortedMap<Integer, Set<String>> sortedTgtSlideKeys = sortByDistanceWithKey(tgtSlideKeys, potentialKey); int smallestDistanceBtwPotentialKeyAndTgtKey = sortedTgtSlideKeys.firstKey(); Set<String> potentialTgtKeys = sortedTgtSlideKeys.get(smallestDistanceBtwPotentialKeyAndTgtKey); if (potentialTgtKeys.size() > 1) { log.warn( "Potential Src key '{}' matching Tgt keys {} could both match TgtKeys {} with levenstein distance {}", tgtKeyToMatch, potentialKeys, potentialTgtKeys, smallestDistanceBtwTgtKeyToMatchAndSrcKey); return Optional.empty(); } else { String potentialTgtKey = potentialTgtKeys.iterator().next(); if (potentialTgtKey.equals(tgtKeyToMatch)) { log.info("Src key '{}' has been associated with Tgt key '{}'", potentialKey, potentialTgtKey); return Optional.of(potentialKey); } else { log.warn( "Potential Src key '{}' matches Tgt key '{}' with distance '{}' with is different from the Tgt we looked up '{}'", potentialKey, potentialTgtKey, smallestDistanceBtwPotentialKeyAndTgtKey, tgtKeyToMatch); return Optional.empty(); } } } }
From source file:org.openmrs.module.drughistory.api.impl.DrugSnapshotServiceImpl.java
/** * Plow through drug events and create snapshots from them * TODO find a way to batch or use a cursor *//* w w w .ja v a 2 s. c o m*/ @Override public void generateDrugSnapshots(Patient patient, Date sinceWhen) { // set up params for drug event query Properties params = new Properties(); if (patient != null) { params.put("person", patient); } if (sinceWhen != null) { params.put("since", sinceWhen); } // get the drug events List<DrugEvent> events = Context.getService(DrugEventService.class).getDrugEvents(params); // order events by person and date Map<Person, SortedMap<Date, List<DrugEvent>>> byPersonAndDate = groupByPersonAndDate(events); // create snapshots and save after processing each person List<DrugSnapshot> snapshots = new ArrayList<DrugSnapshot>(); for (Person p : byPersonAndDate.keySet()) { DrugSnapshot s = new DrugSnapshot(); s.setPerson(p); // for each date, calculate the new set of relevant concepts SortedMap<Date, List<DrugEvent>> dateListMap = byPersonAndDate.get(p); for (Date d : dateListMap.keySet()) { s.setDateTaken(d); for (DrugEvent de : dateListMap.get(d)) { if (de.getEventType() == DrugEventType.START || de.getEventType() == DrugEventType.CONTINUE) { s.addConcept(de.getConcept()); } else if (de.getEventType() == DrugEventType.STOP) { s.removeConcept(de.getConcept()); } // the snapshot's encounter will be the one from the last-added observation s.setEncounter(de.getEncounter()); } // add a copy to snapshots, since we want to reuse this one DrugSnapshot ds = s.copy(); // ... and give it a UUID ds.setUuid(UUID.randomUUID().toString()); snapshots.add(ds); } // save and clear snapshots saveSnapshots(snapshots); snapshots.clear(); // flush the context so we don't run into memory issues Context.flushSession(); Context.clearSession(); } }
From source file:com.openkappa.rst.Classifier.java
private Container findWithPrefix(int attributeIndex, String prefix) { SortedMap<String, Container> prefixMap = criteria[attributeIndex].prefixMap(prefix); if (null == prefixMap || prefixMap.isEmpty()) { return fallback(attributeIndex); }/* w ww . ja v a 2s. co m*/ return prefixMap.get(prefixMap.firstKey()); }
From source file:org.italiangrid.storm.webdav.metrics.StormMetricsReporter.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from ww w . j ava2 s .c o m*/ public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { Gauge<Double> heapUsage = gauges.get("jvm.memory.heap.usage"); Gauge<Long> heapUsed = gauges.get("jvm.memory.heap.used"); Timer handlerDispatches = timers.get("storm.http.handler.dispatches"); final Snapshot snapshot = handlerDispatches.getSnapshot(); Long lastMinuteCount = null; if (lastCountValue != null) { lastMinuteCount = handlerDispatches.getCount() - lastCountValue; } lastCountValue = handlerDispatches.getCount(); logger.info( "Heap[usage={}, used={}] Requests[m1_count={}, count={}, max={}, min={}, mean={}, mean_rate={}, m1_rate={}, m5_rate={}, m15_rate={}] Duration_units={}, Rate_units={}", heapUsage.getValue(), FileUtils.byteCountToDisplaySize(heapUsed.getValue()), lastMinuteCount, handlerDispatches.getCount(), convertDuration(snapshot.getMax()), convertDuration(snapshot.getMin()), convertDuration(snapshot.getMean()), convertRate(handlerDispatches.getMeanRate()), convertRate(handlerDispatches.getOneMinuteRate()), convertRate(handlerDispatches.getFiveMinuteRate()), convertRate(handlerDispatches.getFifteenMinuteRate()), getDurationUnit(), getRateUnit()); }
From source file:FocusTraversalExample.java
public Component getComponentBefore(Container focusCycleRoot, Component aComponent) { if (!(aComponent instanceof JButton)) { return null; }//w w w . j av a 2 s .c om SortedMap buttons = getSortedButtons(focusCycleRoot); SortedMap prevButtons = // Find all buttons before this one. buttons.headMap(((JButton) aComponent).getText()); if (prevButtons.isEmpty()) { // Wrapped back to end. if (!buttons.isEmpty()) { return (Component) buttons.get(buttons.lastKey()); } return null; // Degenerate case of no buttons. } return (Component) prevButtons.get(prevButtons.lastKey()); }
From source file:com.octo.mbo.domain.ApproachingMatcher.java
/** * Sort the list of keys according to their distance with the reference key * @param keysOfSlides List of keys/*from w w w. j a va 2 s. c o m*/ * @param key A reference key that will be compared to each String * @return A map whose index are the distances and values a list of keys for the corresponding distance. */ public SortedMap<Integer, Set<String>> sortByDistanceWithKey(Collection<String> keysOfSlides, String key) { assert keysOfSlides != null; assert key != null; SortedMap<Integer, Set<String>> keysSortedByDistance = new TreeMap<>(); for (String slideKey : keysOfSlides) { int distK2k = levenshteinDistance.apply(normalize(key), normalize(slideKey)); if (keysSortedByDistance.containsKey(distK2k)) { keysSortedByDistance.get(distK2k).add(slideKey); } else { keysSortedByDistance.put(distK2k, new HashSet<>((Collections.singletonList(slideKey)))); } } log.trace("Sort by least distance to '{}' after normalization : {}", key, keysSortedByDistance); return keysSortedByDistance; }