List of usage examples for java.util SortedMap get
V get(Object key);
From source file:net.ripe.rpki.commons.crypto.rfc3779.ResourceExtensionEncoder.java
/** * IPAddrBlocks ::= SEQUENCE OF IPAddressFamily *//*from w w w . ja v a 2 s . c o m*/ ASN1Object ipAddressBlocksToDer(SortedMap<AddressFamily, IpResourceSet> resources) { List<ASN1Encodable> seq = new ArrayList<ASN1Encodable>(2); for (AddressFamily addressFamily : resources.keySet()) { seq.add(ipAddressFamilyToDer(addressFamily, resources.get(addressFamily))); } return new DERSequence(seq.toArray(new ASN1Encodable[seq.size()])); }
From source file:org.uncommons.reportng.HTMLReporter.java
/** * Group test methods by class and sort alphabetically. *//*from w w w . j av a2 s.c om*/ private SortedMap<IClass, List<ITestResult>> sortByTestClass(IResultMap results) { SortedMap<IClass, List<ITestResult>> sortedResults = new TreeMap<IClass, List<ITestResult>>( CLASS_COMPARATOR); for (ITestResult result : results.getAllResults()) { List<ITestResult> resultsForClass = sortedResults.get(result.getTestClass()); if (resultsForClass == null) { resultsForClass = new ArrayList<ITestResult>(); sortedResults.put(result.getTestClass(), resultsForClass); } int index = Collections.binarySearch(resultsForClass, result, RESULT_COMPARATOR); if (index < 0) { index = Math.abs(index + 1); } resultsForClass.add(index, result); } return sortedResults; }
From source file:testful.coverage.behavior.AbstractorNumber.java
@Override public Abstraction get(Map<String, Object> ctx) { // evaluate the expression and retrieve the result (obj) Object obj = evaluateExpression(ctx); if (obj == null) return new AbstractionObjectReference(expression, true); if (!(obj instanceof Number)) { logger.warning("Expected a number in AbstractorNumber!"); return new Abstraction.AbstractionError(expression); }// ww w. ja v a2 s . com // if there are no intervals, then use the "default" abstraction if (intervalsString == null) return get(expression, obj); double elem = ((Number) obj).doubleValue(); // ensure that this.intervals contains parsed expressions getIntervals(); // retrieve the value of intervals. it may contain null values Double[] values = evaluateIntervals(ctx); // if the value is NaN, calculate the return value if (Double.isNaN(elem)) { String label = null; for (int i = 0; i < values.length; i++) if (values[i] != null && Double.isNaN(values[i])) { if (label == null) label = intervalsString[i]; else label += "," + intervalsString[i]; } if (label == null) return new AbstractionNumber(expression, expression + " is " + AbstractionNumber.NaN); return new AbstractionNumber(expression, expression + " = " + label); } // build the sortedValues Map SortedMap<Double, String> sortedValues = new TreeMap<Double, String>(); for (int i = 0; i < values.length; i++) if (values[i] != null && !Double.isNaN(values[i])) { String label = sortedValues.get(values[i]); if (label == null) label = intervalsString[i]; else label += "," + intervalsString[i]; sortedValues.put(values[i], label); } if (!sortedValues.containsKey(Double.POSITIVE_INFINITY)) sortedValues.put(Double.POSITIVE_INFINITY, AbstractionNumber.P_INF); if (!sortedValues.containsKey(Double.NEGATIVE_INFINITY)) sortedValues.put(Double.NEGATIVE_INFINITY, AbstractionNumber.N_INF); // calculate the interval String prev = null; for (Entry<Double, String> entry : sortedValues.entrySet()) { if (prev != null && elem < entry.getKey()) return new AbstractionNumber(expression, prev + " < " + expression + " < " + entry.getValue()); if (elem == entry.getKey()) return new AbstractionNumber(expression, expression + " = " + entry.getValue()); prev = entry.getValue(); } if (TestFul.DEBUG) TestFul.debug("This point was not supposed to be reachable."); return new AbstractionNumber(expression, expression + " = " + AbstractionNumber.P_INF); }
From source file:org.languagetool.rules.spelling.suggestions.SuggestionsChanges.java
private List<Map<String, Object>> gridsearch(SortedMap<String, List<Object>> grid, List<Map<String, Object>> current) { if (grid.isEmpty()) { // recursion exit return current; }/*from ww w . ja va 2 s . co m*/ String name = grid.lastKey(); List<Object> params = grid.get(name); List<Map<String, Object>> result = new LinkedList<>(); if (current.isEmpty()) { for (Object value : params) { result.add(Collections.singletonMap(name, value)); } } else { for (Map<String, Object> entry : current) { for (Object value : params) { Map<String, Object> modified = new HashMap<>(entry); modified.put(name, value); result.add(modified); } } } return gridsearch(grid.headMap(name), result); }
From source file:com.illustrationfinder.process.post.HtmlPostProcessor.java
@Override public List<String> generateKeywords() { // TODO If two words are always close to each other, they should be considered as an expression and managed like one word if (this.url == null) return null; try {//from w w w.ja v a2 s . c o m // Retrieve the document and store it temporary try (final InputStream stream = this.url.openStream()) { final String rawText = IOUtils.toString(stream); // Retrieve useful HTML data final Document document = Jsoup.parse(rawText); String htmlTitle = document.title(); String htmlKeywords = document.select("meta[name=keywords]").text(); String htmlDescription = document.select("meta[name=description]").text(); // Extract the content of the raw text String content = ArticleExtractor.getInstance().getText(rawText); // Now we apply a simple algorithm to get keywords // 1) We remove all punctuation marks from the title // 2) We remove all words with less than 4 characters // 3) We remove excessive spacing and tabulations htmlTitle = htmlTitle.toLowerCase(); htmlTitle = htmlTitle.replaceAll(PUNCTUATION_REGEX, ""); htmlTitle = htmlTitle.replaceAll(WORD_WITH_LESS_THAN_4_CHARACTERS_REGEX, ""); htmlTitle = htmlTitle.replaceAll(EXCESSIVE_SPACING_REGEX, " "); final List<String> keywords = new ArrayList<>(); final List<String> keywordsList = Arrays.asList(htmlTitle.split(" ")); for (String tmp : keywordsList) { if (tmp.length() >= MINIMUM_WORD_LENGTH) { keywords.add(tmp); } } // If there is enough keywords, we return if (keywords.size() >= MINIMUM_KEYWORDS_COUNT) { return keywords; } else { // Otherwise, we look for more keywords from the text by taking the more frequent words content = content.toLowerCase(); content = content.replaceAll(PUNCTUATION_REGEX, ""); content = content.replaceAll(WORD_WITH_LESS_THAN_4_CHARACTERS_REGEX, ""); content = content.replaceAll(EXCESSIVE_SPACING_REGEX, " "); final Map<String, Integer> frequencies = new HashMap<>(); final String[] words = content.split(" "); // Count word frequencies for (final String word : words) { if (frequencies.containsKey(word)) { frequencies.put(word, frequencies.get(word) + 1); } else { frequencies.put(word, 1); } } // Sort the words per frequency final SortedMap<Integer, HashSet<String>> sortedWords = new TreeMap<>(); for (Map.Entry<String, Integer> entry : frequencies.entrySet()) { if (sortedWords.containsKey(entry.getValue())) { sortedWords.get(entry.getValue()).add(entry.getKey()); } else { final HashSet<String> set = new HashSet<>(); set.add(entry.getKey()); sortedWords.put(entry.getValue(), set); } } // Add the most frequent words until we reach the minimu keywords count while (keywords.size() < MINIMUM_KEYWORDS_COUNT) { final HashSet<String> set = sortedWords.get(sortedWords.lastKey()); final String keyword = set.iterator().next(); set.remove(keyword); if (set.size() == 0) { sortedWords.remove(sortedWords.lastKey()); } if (keyword.length() > MINIMUM_WORD_LENGTH) { keywords.add(keyword); } } return keywords; } } } catch (BoilerpipeProcessingException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } return null; }
From source file:org.apache.hadoop.chukwa.util.DumpChunks.java
protected void updateMatchCatalog(String streamName, ChunkImpl chunk) throws IOException { SortedMap<Long, ChunkImpl> chunksInStream = matchCatalog.get(streamName); if (chunksInStream == null) { chunksInStream = new TreeMap<Long, ChunkImpl>(); matchCatalog.put(streamName, chunksInStream); }/*from w w w . ja va2 s. c o m*/ long startPos = chunk.getSeqID() - chunk.getLength(); ChunkImpl prevMatch = chunksInStream.get(startPos); if (prevMatch == null) chunksInStream.put(startPos, chunk); else { //pick longest if (chunk.getLength() > prevMatch.getLength()) chunksInStream.put(startPos, chunk); } }
From source file:at.christophwurst.orm.service.BurnDownServiceImpl.java
@Override public Map<Date, Float> getBurnDownData(Long sprintId) { Map<Date, Float> result = new HashMap<>(); Sprint sprint = sprintRepository.getSprintAndWorklogs(sprintId); int totalTime = sprint.getRequirements().stream().mapToInt((s) -> { return s.getTasks().stream().mapToInt(Task::getEstimatedTime).sum(); }).sum();/* w w w . ja va 2 s.com*/ SortedMap<Date, List<LogbookEntry>> workLogs = new TreeMap<>(); sprint.getRequirements().forEach((r) -> { r.getTasks().forEach((t) -> { t.getLogbookEntries().forEach((e) -> { Date day = stripDate(e.getStartTime()); if (!workLogs.containsKey(day)) { workLogs.put(day, new ArrayList<>()); } workLogs.get(day).add(e); }); }); }); int left = totalTime; for (Map.Entry<Date, List<LogbookEntry>> entry : workLogs.entrySet()) { long Ldone = entry.getValue().stream().mapToLong(LogbookEntry::getTotalTime).sum(); int done = (int) (Ldone / (1000 * 3600)); left -= done; result.put(entry.getKey(), (float) left / totalTime); } return result; }
From source file:com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter.java
private void addHistograms(SortedMap<String, Histogram> histograms, LinkedList<PutMetricDataRequest> requests, Date timestamp) {/*w ww . j av a 2 s . co m*/ logger.debug("Adding Histograms..."); for (String name : histograms.keySet()) { Histogram histogram = histograms.get(name); Snapshot snapshot = histogram.getSnapshot(); checkAndAddDatum(MetricFilter.Stat.COUNT, name, histogram.getCount(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.MIN, name, snapshot.getMin(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.MAX, name, snapshot.getMax(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.MEAN, name, snapshot.getMean(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.STDDEV, name, snapshot.getStdDev(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.PERCENTILE_75, name, snapshot.get75thPercentile(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.PERCENTILE_95, name, snapshot.get95thPercentile(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.PERCENTILE_98, name, snapshot.get98thPercentile(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.PERCENTILE_99, name, snapshot.get99thPercentile(), requests, timestamp); checkAndAddDatum(MetricFilter.Stat.PERCENTILE_999, name, snapshot.get999thPercentile(), requests, timestamp); } }
From source file:org.libreplan.web.common.components.finders.ResourcesMultipleFiltersFinder.java
private List<FilterPair> fillWithFirstTenFiltersCriterions() { SortedMap<CriterionType, List<Criterion>> criterionsMap = getCriterionsMap(); Iterator<CriterionType> iteratorCriterionType = criterionsMap.keySet().iterator(); while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) { CriterionType type = iteratorCriterionType.next(); for (int i = 0; getListMatching().size() < 10 && i < criterionsMap.get(type).size(); i++) { Criterion criterion = criterionsMap.get(type).get(i); addCriterion(type, criterion); }/*from ww w. ja v a2 s . c om*/ } return getListMatching(); }
From source file:org.apache.hadoop.mapred.MockSimulatorJobTracker.java
@Override public HeartbeatResponse heartbeat(TaskTrackerStatus status, boolean restarted, boolean initialContact, boolean acceptNewTasks, short responseId) throws IOException { if (!(status instanceof SimulatorTaskTrackerStatus)) { throw new IllegalArgumentException( "Expecting SimulatorTaskTrackerStatus, actual status type " + status.getClass()); }// ww w.ja v a2 s. co m SimulatorTaskTrackerStatus trackerStatus = (SimulatorTaskTrackerStatus) status; long now = trackerStatus.getCurrentSimulationTime(); String trackerName = status.getTrackerName(); LOG.debug("Received heartbeat() from trackerName=" + trackerName + ", now=" + now); HeartbeatResponse response = new HeartbeatResponse(); response.setHeartbeatInterval(heartbeatInterval); response.setActions(new TaskTrackerAction[0]); if (checkHeartbeats) { Assert.assertFalse("No more heartbeats were expected ", heartbeats.isEmpty()); long nextToCheck = heartbeats.firstKey(); // Missing heartbeat check Assert.assertTrue(nextToCheck <= now); if (nextToCheck < now) { LOG.debug("Simulation time progressed, last checked heartbeat at=" + nextToCheck + ", now=" + now + ". Checking if no " + "required heartbeats were missed in the past"); SortedMap<String, HeartbeatHelper> previousHeartbeats = heartbeats.get(nextToCheck); Assert.assertNotNull(previousHeartbeats); Assert.assertTrue(previousHeartbeats.isEmpty()); heartbeats.remove(nextToCheck); nextToCheck = heartbeats.firstKey(); } Assert.assertEquals("Heartbeat at the wrong time", nextToCheck, now); SortedMap<String, HeartbeatHelper> currentHeartbeats = heartbeats.get(now); HeartbeatHelper currentHeartbeat = currentHeartbeats.get(trackerName); Assert.assertNotNull("Unknown task tracker name=" + trackerName, currentHeartbeat); currentHeartbeats.remove(trackerName); currentHeartbeat.checkHeartbeatParameters(status, acceptNewTasks); response.setActions(currentHeartbeat.getTaskTrackerActions()); } return response; }