List of usage examples for java.util SortedMap keySet
Set<K> keySet();
From source file:lti.oauth.OAuthMessageSigner.java
/** * This method double encodes the parameter keys and values. * Thus, it expects the keys and values contained in the 'parameters' SortedMap * NOT to be encoded.// www .j av a 2 s. c o m * * @param secret * @param algorithm * @param method * @param url * @param parameters * @return oauth signature * @throws Exception */ public String sign(String secret, String algorithm, String method, String url, SortedMap<String, String> parameters) throws Exception { SecretKeySpec secretKeySpec = new SecretKeySpec((secret.concat(OAuthUtil.AMPERSAND)).getBytes(), algorithm); Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm()); mac.init(secretKeySpec); StringBuilder signatureBase = new StringBuilder(OAuthUtil.percentEncode(method)); signatureBase.append(OAuthUtil.AMPERSAND); signatureBase.append(OAuthUtil.percentEncode(url)); signatureBase.append(OAuthUtil.AMPERSAND); int count = 0; for (String key : parameters.keySet()) { count++; signatureBase.append(OAuthUtil.percentEncode(OAuthUtil.percentEncode(key))); signatureBase.append(URLEncoder.encode(OAuthUtil.EQUAL, OAuthUtil.ENCODING)); signatureBase.append(OAuthUtil.percentEncode(OAuthUtil.percentEncode(parameters.get(key)))); if (count < parameters.size()) { signatureBase.append(URLEncoder.encode(OAuthUtil.AMPERSAND, OAuthUtil.ENCODING)); } } if (log.isDebugEnabled()) { log.debug(signatureBase.toString()); } byte[] bytes = mac.doFinal(signatureBase.toString().getBytes()); byte[] encodedMacBytes = Base64.encodeBase64(bytes); return new String(encodedMacBytes); }
From source file:org.mitre.mpf.interop.JsonDetectionOutputObject.java
private int compareMap(SortedMap<String, String> map1, SortedMap<String, String> map2) { if (map1 == null && map2 == null) { return 0; } else if (map1 == null) { return -1; } else if (map2 == null) { return 1; } else {/*from w w w. ja va2s .co m*/ int result = 0; if ((result = Integer.compare(map1.size(), map2.size())) != 0) { return result; } StringBuilder map1Str = new StringBuilder(); for (String key : map1.keySet()) { map1Str.append(key).append(map1.get(key)); } StringBuilder map2Str = new StringBuilder(); for (String key : map2.keySet()) { map2Str.append(key).append(map2.get(key)); } if ((result = ObjectUtils.compare(map1Str.toString(), map2Str.toString())) != 0) { return result; } } return 0; }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistenceTest.java
@Test public void testGetExtensionsByAlias() throws Exception { Document doc = XMLUtils.documentFromString(XML_WITH_EXTENSIONS); Map<String, Class<?>> aliases = getAliases(); XStreamPersistence xp = new TestXStreamPersistence(); SortedMap<String, Element> extensions = xp.getExtensionsByAlias(doc, aliases); assertEquals(2, extensions.size());// ww w. j av a 2 s .c o m for (String alias : extensions.keySet()) { assertTrue(aliases.containsKey(alias)); assertEquals(alias, extensions.get(alias).getNodeName()); } //check that the content of ext1 is the expected one assertEquals("string", extensions.get("ext1").getFirstChild().getNodeName()); assertEquals("string", extensions.get("ext1").getFirstChild().getTextContent()); }
From source file:com.streamsets.pipeline.lib.jdbc.MultiRowInsertMap.java
public PreparedStatement getInsertFor(SortedMap<String, String> columns, int numRecords) throws SQLException { // The INSERT query we're going to perform (parameterized). if (cache.containsKey(columns)) { return cache.get(columns); } else {//from w w w.java 2 s. c o m String valuePlaceholder = String.format("(%s)", Joiner.on(", ").join(columns.values())); String valuePlaceholders = StringUtils.repeat(valuePlaceholder, ", ", numRecords); String query = String.format("INSERT INTO %s (%s) VALUES %s", tableName, // keySet and values will both return the same ordering, due to using a SortedMap Joiner.on(", ").join(columns.keySet()), valuePlaceholders); PreparedStatement statement = connection.prepareStatement(query); cache.put(columns, statement); return statement; } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.F1ScoreTableAggregator.java
public static void evaluatePredictionsFoldersDomain(File masterFolder, String folderContains) throws Exception { SortedMap<String, SortedMap<String, String>> featureSetsResults = new TreeMap<>(); File[] foldersFeatureSets = masterFolder.listFiles(EvalHelper.DIRECTORY_FILTER); for (File folderFeatureSet : foldersFeatureSets) { String[] split = folderFeatureSet.getName().split("_"); String featureSet = split[0]; String paramE = split[1]; String paramT = split[2]; if ("e0".equals(paramE) && "t1".equals(paramT)) { Map<String, File> foldersData = EvalHelper.listSubFoldersAndRemoveUUID(folderFeatureSet); for (Map.Entry<String, File> folderData : foldersData.entrySet()) { String data = folderData.getKey(); if (data.contains(folderContains)) { File resultSummary = new File(folderData.getValue(), "resultSummary.txt"); List<String> values = extractValues(resultSummary); String macroF1 = values.get(0); if (!featureSetsResults.containsKey(featureSet)) { featureSetsResults.put(featureSet, new TreeMap<String, String>()); }//from ww w . j a v a 2s. c o m String domainName = data.split("_")[2]; featureSetsResults.get(featureSet).put(domainName, macroF1); } } } } // print results int rows = featureSetsResults.values().iterator().next().size(); System.out.printf("\t"); for (String featureSet : featureSetsResults.keySet()) { System.out.printf("%s\t", featureSet); } System.out.println(); for (int i = 0; i < rows; i++) { // Set<String> keySet = featureSetsResults.values().iterator().next().keySet(); SortedMap<String, String> firstColumn = featureSetsResults.values().iterator().next(); List<String> keys = new ArrayList<>(firstColumn.keySet()); System.out.printf("%s\t", keys.get(i)); for (SortedMap<String, String> values : featureSetsResults.values()) { System.out.printf("%s\t", values.get(keys.get(i))); } System.out.println(); } }
From source file:business.ImageManager.java
private void doLoadFeaturesAll() { final SortedMap<String, String> featuresImage = localFacade.getTerrainLandmarksImage(); for (String cdFeature : featuresImage.keySet()) { //todo: link feature to image vector landmarks.put(cdFeature, new ImageIcon(getClass().getResource(featuresImage.get(cdFeature)))); }/* w w w .j a v a 2 s . co m*/ }
From source file:org.kuali.kra.budget.external.budget.impl.BudgetAdjustmentServiceHelperImpl.java
/** * This method returns the personnel calculated direct cost. * @return/*from w ww. j a v a 2s . c o m*/ */ public Map<RateClassRateType, ScaleTwoDecimal> getPersonnelCalculatedDirectCost(Budget currentBudget, AwardBudgetExt previousBudget) { SortedMap<RateType, List<ScaleTwoDecimal>> currentTotals = currentBudget .getPersonnelCalculatedExpenseTotals(); int period = currentBudget.getBudgetPeriods().size() - 1; Map<RateClassRateType, ScaleTwoDecimal> currentCost = new HashMap<RateClassRateType, ScaleTwoDecimal>(); Map<RateClassRateType, ScaleTwoDecimal> netCost = new HashMap<RateClassRateType, ScaleTwoDecimal>(); for (RateType rate : currentTotals.keySet()) { // For some reason indirect cost shows up in this, remove it. if (!StringUtils.equalsIgnoreCase(rate.getRateClass().getRateClassTypeCode(), "O")) { LOG.info("Rate Class: " + rate.getRateClassCode() + "RateType: " + rate.getRateTypeCode() + ""); currentCost.put(new RateClassRateType(rate.getRateClassCode(), rate.getRateTypeCode()), currentTotals.get(rate).get(period)); } } for (RateClassRateType rate : currentCost.keySet()) { netCost.put(rate, currentCost.get(rate)); } return netCost; }
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 w w w .jav 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:com.aurel.track.item.link.ItemLinkBL.java
/** * Saves the link in workItemContext//from w w w . jav a 2 s .c o m * @param workItemContext * @param workItemLinkBean */ static void saveLinkInContext(WorkItemContext workItemContext, TWorkItemLinkBean workItemLinkBean, Integer linkID) { if (workItemContext != null) { SortedMap<Integer, TWorkItemLinkBean> workItemsLinksMap = workItemContext.getWorkItemsLinksMap(); Integer localLinkID = null; if (workItemsLinksMap == null) { //first link to the new item workItemsLinksMap = new TreeMap<Integer, TWorkItemLinkBean>(); workItemContext.setWorkItemsLinksMap(workItemsLinksMap); localLinkID = Integer.valueOf(1); } else { if (linkID == null) { //get the highest generated linkID plus one for (Integer usedLinkID : workItemsLinksMap.keySet()) { if (localLinkID == null) { localLinkID = usedLinkID; } else { if (localLinkID < usedLinkID) { localLinkID = usedLinkID; } } } if (localLinkID == null) { localLinkID = Integer.valueOf(1); } else { localLinkID = Integer.valueOf(localLinkID.intValue() + 1); } } else { localLinkID = linkID; } } workItemsLinksMap.put(localLinkID, workItemLinkBean); } }
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 a 2s .c om @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()); }