List of usage examples for java.util SortedMap get
V get(Object key);
From source file:com.cafbit.netlib.dns.DNSMessage.java
public String toString() { StringBuilder sb = new StringBuilder(); // questions// www. jav a2s. c om for (DNSQuestion q : questions) { sb.append("\nQuestion: " + q.toString() + "\n"); } // group answers by name SortedMap<String, List<DNSAnswer>> answersByName = new TreeMap<String, List<DNSAnswer>>(); for (DNSAnswer a : answers) { List<DNSAnswer> list; if (answersByName.containsKey(a.name)) { list = answersByName.get(a.name); } else { list = new LinkedList<DNSAnswer>(); answersByName.put(a.name, list); } list.add(a); } for (DNSAnswer a : authorities) { List<DNSAnswer> list; if (answersByName.containsKey(a.name)) { list = answersByName.get(a.name); } else { list = new LinkedList<DNSAnswer>(); answersByName.put(a.name, list); } list.add(a); } for (DNSAnswer a : addrecords) { List<DNSAnswer> list; if (answersByName.containsKey(a.name)) { list = answersByName.get(a.name); } else { list = new LinkedList<DNSAnswer>(); answersByName.put(a.name, list); } list.add(a); } for (Map.Entry<String, List<DNSAnswer>> entry : answersByName.entrySet()) { sb.append(entry.getKey() + "\n"); for (DNSAnswer a : entry.getValue()) { sb.append(" " + a.type.toString() + " " + a.getRdataString() + "\n"); } } return sb.toString(); }
From source file:com.redhat.rhn.frontend.action.kickstart.PowerManagementAction.java
/** * Sets the page attributes.//from w w w. jav a 2s. c o m * * @param request the request * @param context the context * @param server the server * @param user the user * @param strutsDelegate the Struts delegate * @param errors ActionErrors that might have already been raised */ private void setAttributes(HttpServletRequest request, RequestContext context, Server server, User user, StrutsDelegate strutsDelegate, ActionErrors errors) { request.setAttribute(RequestContext.SID, server.getId()); request.setAttribute(RequestContext.SYSTEM, server); SortedMap<String, String> types = setUpPowerTypes(request, strutsDelegate, errors); ensureAgentInstalled(request, strutsDelegate, errors); if (types.size() > 0) { SystemRecord record = getSystemRecord(user, server); if (record == null) { request.setAttribute(POWER_TYPE, types.get(types.firstKey())); } else { request.setAttribute(POWER_TYPE, record.getPowerType()); request.setAttribute(POWER_ADDRESS, record.getPowerAddress()); request.setAttribute(POWER_USERNAME, record.getPowerUsername()); request.setAttribute(POWER_PASSWORD, record.getPowerPassword()); request.setAttribute(POWER_ID, record.getPowerId()); } } }
From source file:gov.nih.nci.caarray.magetab.splitter.SdrfSplitterTest.java
/** * linesToAdd are added in sequential order. This <em>modifies</em> the lines * in place. So to add 2 lines before the header and 1 after, the keys should be * (0, 1, 3), because that will add two lines (moving the header down), then add after * the header./*from ww w.j av a2s . c o m*/ */ private Function<File, File> getTransform(final SortedMap<Integer, String> linesToAdd) { Function<File, File> transform = new Function<File, File>() { @Override public File apply(File input) { try { @SuppressWarnings("unchecked") List<String> lines = FileUtils.readLines(input); for (Integer i : linesToAdd.keySet()) { lines.add(i, linesToAdd.get(i)); } File revisedSdrf = File.createTempFile("test", ".sdrf"); FileUtils.writeLines(revisedSdrf, lines); return revisedSdrf; } catch (IOException ioe) { throw new RuntimeException(ioe); } } }; return transform; }
From source file:com.streamsets.pipeline.stage.processor.statsaggregation.TestMetricAggregationProcessor.java
@Test public void testEvaluateDataRuleRecord() throws StageException, InterruptedException { Record dataRuleChangeRecord = AggregatorUtil.createDataRuleChangeRecord( TestHelper.createTestDataRuleDefinition("a < b", true, System.currentTimeMillis())); Thread.sleep(2); // Sleep for 2 seconds that the data rule records get a later timestamp List<Record> testDataRuleRecords = TestHelper.createTestDataRuleRecords(); List<Record> batch = new ArrayList<>(); batch.add(dataRuleChangeRecord);//w w w .jav a2 s. c o m batch.addAll(testDataRuleRecords); runner.runProcess(batch); MetricRegistry metrics = metricAggregationProcessor.getMetrics(); SortedMap<String, Counter> counters = metrics.getCounters(); Assert.assertTrue(counters.containsKey("user.x.matched.counter")); Assert.assertEquals(400, counters.get("user.x.matched.counter").getCount()); Assert.assertTrue(counters.containsKey("user.x.evaluated.counter")); Assert.assertEquals(2000, counters.get("user.x.evaluated.counter").getCount()); // Alert expected as threshold type is count and threshold value is 100 SortedMap<String, Gauge> gauges = metrics.getGauges(); Assert.assertTrue(gauges.containsKey("alert.x.gauge")); Map<String, Object> gaugeValue = (Map<String, Object>) gauges.get("alert.x.gauge").getValue(); Assert.assertEquals(400L, gaugeValue.get("currentValue")); List<String> alertTexts = (List<String>) gaugeValue.get("alertTexts"); Assert.assertEquals(1, alertTexts.size()); Assert.assertEquals("Alert!!", alertTexts.get(0)); }
From source file:knowledgeMiner.mining.SentenceParserHeuristic.java
/** * Cleans the indices off the end of strings. * /* ww w. jav a 2 s. c om*/ * @param str * A string with indices on the end of each word. * @param anchors * The anchor map to apply. * @return A string without index suffixes. */ private String reAnchorString(String str, SortedMap<String, String> anchors) { if (anchors == null) return str; String result = str.replaceAll("(\\S+)-\\d+(?= |$)", "$1"); for (String anchor : anchors.keySet()) { if (anchors.get(anchor) != null) result = WikiParser.replaceAll(result, anchor, anchors.get(anchor)); } return result; }
From source file:uk.org.sappho.applications.transcript.service.registry.WorkingCopy.java
public void putProperties(String environment, String application, SortedMap<String, Object> properties, boolean isMerge) throws TranscriptException { Gson gson = new Gson(); synchronized (getLock()) { SortedMap<String, Object> oldProperties = getJsonProperties(environment, application); SortedMap<String, Object> newProperties; if (isMerge && !oldProperties.isEmpty()) { newProperties = new TreeMap<String, Object>(); for (String key : oldProperties.keySet()) { newProperties.put(key, oldProperties.get(key)); }//www . j av a 2 s .co m for (String key : properties.keySet()) { Object newValue = properties.get(key); if (transcriptParameters.isFailOnValueChange() && oldProperties.containsKey(key) && !gson.toJson(newValue).equals(gson.toJson(oldProperties.get(key)))) { throw new TranscriptException("Value of property " + environment + ":" + application + ":" + key + " would change"); } newProperties.put(key, newValue); } } else { newProperties = properties; } String oldJson = gson.toJson(oldProperties); String newJson = gson.toJson(newProperties); if (!newJson.equals(oldJson)) { putProperties(environment, application, newProperties); } } }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistence.java
void postProcessXML(Document newDoc, Document oldDoc, Map<String, Class<?>> aliases, String userId, int modelVersion) throws MigrationException { Element newDocElement = newDoc.getDocumentElement(); Element oldDocElement = oldDoc != null ? oldDoc.getDocumentElement() : null; boolean identical = XMLDiff.identical(newDocElement, oldDocElement); setLastModifiedAttributes(newDocElement, identical ? oldDocElement : null, userId); SortedMap<String, Element> newExts = getExtensionsByAlias(newDoc, aliases); SortedMap<String, Element> oldExts = oldDoc != null ? getExtensionsByAlias(oldDoc, aliases) : null; for (String alias : newExts.keySet()) { Element newExt = newExts.get(alias); Element oldExt = oldExts != null ? oldExts.get(alias) : null; setLastModifiedAttributes(newExt, (identical || XMLDiff.identical(newExt, oldExt)) ? oldExt : null, userId);//ww w . j ava2 s. co m } setVersionAttribute(newDoc, modelVersion); }
From source file:org.ambraproject.article.service.BrowseServiceSolrTest.java
@Test(dataProvider = "articleCategoryCount") public void testGetArticleCountsByCategory(String journalKey, Map<String, Long> expectedCounts) { SortedMap<String, Long> results = browseService.getSubjectsForJournal(journalKey); assertNotNull(results, "returned null results"); assertEquals(results.size(), expectedCounts.size(), "returned incorrect number of categories"); for (String category : expectedCounts.keySet()) { assertTrue(results.containsKey(category), "didn't return expected category " + category); assertEquals(results.get(category), expectedCounts.get(category), "Returned incorrect count for category " + category); }// www . j ava 2 s.c o m }
From source file:org.libreplan.web.common.components.finders.ResourceAllocationMultipleFiltersFinder.java
private List<FilterPair> fillWithFirstTenFiltersCriterions() { SortedMap<CriterionType, List<Criterion>> mapCriterions = getCriterionsMap(); Iterator<CriterionType> iteratorCriterionType = mapCriterions.keySet().iterator(); while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) { CriterionType type = iteratorCriterionType.next(); for (int i = 0; getListMatching().size() < 10 && i < mapCriterions.get(type).size(); i++) { Criterion criterion = mapCriterions.get(type).get(i); addCriterion(type, criterion); }/* w ww .ja v a 2s. c om*/ } return getListMatching(); }
From source file:com.precioustech.fxtrading.tradingbot.strategies.FadeTheMoveStrategy.java
public void analysePrices() { for (Map.Entry<TradeableInstrument<T>, Cache<DateTime, MarketDataPayLoad<T>>> entry : instrumentRecentPricesCache .entrySet()) {//from w w w.jav a2s . co m SortedMap<DateTime, MarketDataPayLoad<T>> sortedByDate = ImmutableSortedMap .copyOf(entry.getValue().asMap()); if (sortedByDate.isEmpty()) { continue; } Double pipJump = calculatePipJump(sortedByDate.values(), entry.getKey()); Double absPipJump = Math.abs(pipJump); if (absPipJump >= this.pipJumpCutOffCalculator.calculatePipJumpCutOff(entry.getKey())) { MarketDataPayLoad<T> lastPayLoad = sortedByDate.get(sortedByDate.lastKey()); Double pip = this.instrumentService.getPipForInstrument(entry.getKey()); double takeProfitPrice; double limitPrice; TradingSignal signal = null; if (Math.signum(pipJump) > 0) {// Short signal = TradingSignal.SHORT; limitPrice = lastPayLoad.getBidPrice() + tradingConfig.getFadeTheMoveDistanceToTrade() * pip; takeProfitPrice = limitPrice - tradingConfig.getFadeTheMovePipsDesired() * pip; } else { signal = TradingSignal.LONG; limitPrice = lastPayLoad.getAskPrice() - tradingConfig.getFadeTheMoveDistanceToTrade() * pip; takeProfitPrice = limitPrice + tradingConfig.getFadeTheMovePipsDesired() * pip; } this.orderQueue.offer(new TradingDecision<T>(entry.getKey(), signal, takeProfitPrice, 0.0, limitPrice, TradingDecision.SRCDECISION.FADE_THE_MOVE)); entry.getValue().asMap().clear();/* * clear the prices so that we do not keep * working on old decision */ } } }