List of usage examples for java.util SortedMap get
V get(Object key);
From source file:com.swisscom.safeconnect.backend.BackendConnector.java
private static String buildUrl(String path, String phoneNumber, String... params) { if (params.length % 2 != 0) return ""; StringBuilder sb = new StringBuilder("https://"); sb.append(Config.PLUMBER_ADDR).append("/"); sb.append(path).append("/"); Map<String, String> paramsMap = new HashMap<>(); for (int i = 0; i < params.length / 2; i++) { paramsMap.put(params[i * 2], params[i * 2 + 1]); }/* w w w .j ava 2 s.c o m*/ SortedMap<String, String> sortedParams = new TreeMap<>(paramsMap); StringBuilder tokenData = new StringBuilder(); for (String k : sortedParams.keySet()) { tokenData.append(sortedParams.get(k)); } String token = Token.generateToken(phoneNumber, tokenData.toString()); sb.append("?"); for (String k : paramsMap.keySet()) { sb.append(k).append("=").append(paramsMap.get(k)).append("&"); } sb.append("t=").append(token); sb.append("&id=").append(BackendConnector.getBase64EncodedString(phoneNumber)); return sb.toString(); }
From source file:org.opencms.module.CmsModuleXmlHandler.java
/** * Generates a detached XML element for a module.<p> * /*from w w w. j a va2s.c o m*/ * @param module the module to generate the XML element for * * @return the detached XML element for the module */ public static Element generateXml(CmsModule module) { Document doc = DocumentHelper.createDocument(); Element moduleElement = doc.addElement(N_MODULE); moduleElement.addElement(N_NAME).setText(module.getName()); if (!module.getName().equals(module.getNiceName())) { moduleElement.addElement(N_NICENAME).addCDATA(module.getNiceName()); } else { moduleElement.addElement(N_NICENAME); } if (CmsStringUtil.isNotEmpty(module.getGroup())) { moduleElement.addElement(N_GROUP).setText(module.getGroup()); } if (CmsStringUtil.isNotEmpty(module.getActionClass())) { moduleElement.addElement(N_CLASS).setText(module.getActionClass()); } else { moduleElement.addElement(N_CLASS); } if (CmsStringUtil.isNotEmpty(module.getDescription())) { moduleElement.addElement(N_DESCRIPTION).addCDATA(module.getDescription()); } else { moduleElement.addElement(N_DESCRIPTION); } moduleElement.addElement(N_VERSION).setText(module.getVersion().toString()); if (CmsStringUtil.isNotEmpty(module.getAuthorName())) { moduleElement.addElement(N_AUTHORNAME).addCDATA(module.getAuthorName()); } else { moduleElement.addElement(N_AUTHORNAME); } if (CmsStringUtil.isNotEmpty(module.getAuthorEmail())) { moduleElement.addElement(N_AUTHOREMAIL).addCDATA(module.getAuthorEmail()); } else { moduleElement.addElement(N_AUTHOREMAIL); } if (module.getDateCreated() != CmsModule.DEFAULT_DATE) { moduleElement.addElement(N_DATECREATED).setText(CmsDateUtil.getHeaderDate(module.getDateCreated())); } else { moduleElement.addElement(N_DATECREATED); } if (CmsStringUtil.isNotEmpty(module.getUserInstalled())) { moduleElement.addElement(N_USERINSTALLED).setText(module.getUserInstalled()); } else { moduleElement.addElement(N_USERINSTALLED); } if (module.getDateInstalled() != CmsModule.DEFAULT_DATE) { moduleElement.addElement(N_DATEINSTALLED).setText(CmsDateUtil.getHeaderDate(module.getDateInstalled())); } else { moduleElement.addElement(N_DATEINSTALLED); } Element dependenciesElement = moduleElement.addElement(N_DEPENDENCIES); for (int i = 0; i < module.getDependencies().size(); i++) { CmsModuleDependency dependency = module.getDependencies().get(i); dependenciesElement.addElement(N_DEPENDENCY) .addAttribute(I_CmsXmlConfiguration.A_NAME, dependency.getName()) .addAttribute(A_VERSION, dependency.getVersion().toString()); } Element exportpointsElement = moduleElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINTS); for (int i = 0; i < module.getExportPoints().size(); i++) { CmsExportPoint point = module.getExportPoints().get(i); exportpointsElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINT) .addAttribute(I_CmsXmlConfiguration.A_URI, point.getUri()) .addAttribute(I_CmsXmlConfiguration.A_DESTINATION, point.getConfiguredDestination()); } Element resourcesElement = moduleElement.addElement(N_RESOURCES); for (int i = 0; i < module.getResources().size(); i++) { String resource = module.getResources().get(i); resourcesElement.addElement(I_CmsXmlConfiguration.N_RESOURCE).addAttribute(I_CmsXmlConfiguration.A_URI, resource); } Element parametersElement = moduleElement.addElement(N_PARAMETERS); SortedMap<String, String> parameters = module.getParameters(); if (parameters != null) { List<String> names = new ArrayList<String>(parameters.keySet()); Collections.sort(names); for (String name : names) { String value = parameters.get(name).toString(); Element paramNode = parametersElement.addElement(I_CmsXmlConfiguration.N_PARAM); paramNode.addAttribute(I_CmsXmlConfiguration.A_NAME, name); paramNode.addText(value); } } // add resource types List<I_CmsResourceType> resourceTypes = module.getResourceTypes(); if (resourceTypes.size() > 0) { Element resourcetypesElement = moduleElement.addElement(CmsVfsConfiguration.N_RESOURCETYPES); CmsVfsConfiguration.generateResourceTypeXml(resourcetypesElement, resourceTypes, true); } List<CmsExplorerTypeSettings> explorerTypes = module.getExplorerTypes(); if (explorerTypes.size() > 0) { Element explorerTypesElement = moduleElement.addElement(CmsWorkplaceConfiguration.N_EXPLORERTYPES); CmsWorkplaceConfiguration.generateExplorerTypesXml(explorerTypesElement, explorerTypes, true); } // return the modules node moduleElement.detach(); return moduleElement; }
From source file:org.apache.accumulo.monitor.rest.tables.TablesResource.java
public static TableInformationList getTables(Monitor monitor) { TableInformationList tableList = new TableInformationList(); SortedMap<TableId, TableInfo> tableStats = new TreeMap<>(); if (monitor.getMmi() != null && monitor.getMmi().tableMap != null) { for (Map.Entry<String, TableInfo> te : monitor.getMmi().tableMap.entrySet()) { tableStats.put(TableId.of(te.getKey()), te.getValue()); }/* w ww . j av a 2 s .c o m*/ } Map<String, Double> compactingByTable = TableInfoUtil.summarizeTableStats(monitor.getMmi()); TableManager tableManager = monitor.getContext().getTableManager(); // Add tables to the list for (Map.Entry<String, TableId> entry : Tables.getNameToIdMap(monitor.getContext()).entrySet()) { String tableName = entry.getKey(); TableId tableId = entry.getValue(); TableInfo tableInfo = tableStats.get(tableId); TableState tableState = tableManager.getTableState(tableId); if (tableInfo != null && !tableState.equals(TableState.OFFLINE)) { Double holdTime = compactingByTable.get(tableId.canonical()); if (holdTime == null) { holdTime = 0.; } tableList .addTable(new TableInformation(tableName, tableId, tableInfo, holdTime, tableState.name())); } else { tableList.addTable(new TableInformation(tableName, tableId, tableState.name())); } } return tableList; }
From source file:org.eclipse.smila.search.FederatedQueryHandling.java
/** * This method creates a sorted map containing all indices and hits grouped by score. * //from w ww . ja v a 2 s .c o m * @param indexNames * Name of indices. * @param hitDistributions * Hit distributions. * @return Sorted set containing all hits grouped by score and index. */ @SuppressWarnings("unchecked") private static SortedMap<Integer, List<HitsPerIndex>> calculateIndicesPerHitLevel(String[] indexNames, HashMap<String, DHitDistribution> hitDistributions) { final SortedMap<Integer, List<HitsPerIndex>> indicesPerHitLevel = new TreeMap<Integer, List<HitsPerIndex>>( new ReverseComparator()); for (String indexName : indexNames) { if (!hitDistributions.containsKey(indexName)) { continue; } final DHitDistribution hitDistribution = hitDistributions.get(indexName); for (final Enumeration<DHit> hits = hitDistribution.getHits(); hits.hasMoreElements();) { final DHit hit = hits.nextElement(); if (!indicesPerHitLevel.containsKey(hit.getScore())) { indicesPerHitLevel.put(hit.getScore(), new ArrayList<HitsPerIndex>()); } indicesPerHitLevel.get(hit.getScore()) .add(new HitsPerIndex(indexName, hit.getScore(), hit.getHits())); } } return indicesPerHitLevel; }
From source file:org.apache.hadoop.hbase.client.TestClientNoCluster.java
static GetResponse doMetaGetResponse(final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta, final GetRequest request) { ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder(); ByteString row = request.getGet().getRow(); Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray()); if (p == null) { if (request.getGet().getClosestRowBefore()) { byte[] bytes = row.toByteArray(); SortedMap<byte[], Pair<HRegionInfo, ServerName>> head = bytes != null ? meta.headMap(bytes) : meta; p = head == null ? null : head.get(head.lastKey()); }/*from w ww . j av a 2s .c o m*/ } if (p != null) { resultBuilder.addCell(getRegionInfo(row, p.getFirst())); resultBuilder.addCell(getServer(row, p.getSecond())); } resultBuilder.addCell(getStartCode(row)); GetResponse.Builder builder = GetResponse.newBuilder(); builder.setResult(resultBuilder.build()); return builder.build(); }
From source file:co.cask.cdap.data.tools.ReplicationStatusTool.java
private static void checkHDFSReplicationComplete(SortedMap<String, String> masterChecksumMap) throws IOException { boolean complete; SortedMap<String, String> slaveChecksumMap = getClusterChecksumMap(); // Verify that all files on Master are present on Slave. Ignore any extra files on Slave. This could // happen when old snapshot files are pruned by CDAP on the Master cluster. complete = !checkDifferences(masterChecksumMap.keySet(), slaveChecksumMap.keySet(), "File"); for (Map.Entry<String, String> checksumEntry : masterChecksumMap.entrySet()) { String file = checksumEntry.getKey(); String masterChecksum = checksumEntry.getValue(); String slaveChecksum = slaveChecksumMap.get(file); if (slaveChecksum != null && !masterChecksum.equals(slaveChecksum)) { System.out.println("Master Checksum " + masterChecksum + " for File " + file + " does not match with" + " Slave Checksum " + slaveChecksum); complete = false;/*from ww w. j a v a 2s. c o m*/ } } if (complete) { // If checksums match for all files. System.out.println("Master and Slave Checksums match. HDFS Replication is complete."); } else { System.out.println("HDFS Replication is NOT Complete."); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.coreference.CoreferenceFeatures.java
/** * Returns a sorted map of [sentencePos, list[coreferenceLink]] for the given chain. * The keys are not continuous, only those that have coreference link to the given chain * are stored//from w w w. jav a 2 s . co m * * @param chain chain * @param jCas jcas * @return map */ private static SortedMap<Integer, List<CoreferenceLink>> extractSentencesAndLinksFromChain( List<CoreferenceLink> chain, JCas jCas) { SortedMap<Integer, List<CoreferenceLink>> result = new TreeMap<>(); // iterate over sentences List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class)); for (int sentenceNo = 0; sentenceNo < sentences.size(); sentenceNo++) { Sentence sentence = sentences.get(sentenceNo); for (CoreferenceLink link : chain) { // is there a link in a sentence? if (link.getBegin() >= sentence.getBegin() && link.getEnd() <= sentence.getEnd()) { // put it to the map if (!result.containsKey(sentenceNo)) { result.put(sentenceNo, new ArrayList<CoreferenceLink>()); } result.get(sentenceNo).add(link); } } } return result; }
From source file:FocusTraversalExample.java
public Component getFirstComponent(Container focusCycleRoot) { SortedMap buttons = getSortedButtons(focusCycleRoot); if (buttons.isEmpty()) { return null; }/* ww w . j av a2 s. c o m*/ return (Component) buttons.get(buttons.firstKey()); }
From source file:FocusTraversalExample.java
public Component getLastComponent(Container focusCycleRoot) { SortedMap buttons = getSortedButtons(focusCycleRoot); if (buttons.isEmpty()) { return null; }//from ww w .j a v a 2 s . c om return (Component) buttons.get(buttons.lastKey()); }
From source file:org.fede.util.Util.java
private static MoneyAmountSeries read(String name) { try (InputStream is = Util.class.getResourceAsStream("/" + name)) { final JSONSeries series = CONSULTATIO_SERIES.contains(name) ? readConsultatioSeries(is, OM) : OM.readValue(is, JSONSeries.class); final SortedMap<YearMonth, MoneyAmount> interpolatedData = new TreeMap<>(); final String currency = series.getCurrency(); for (JSONDataPoint dp : series.getData()) { if (interpolatedData.put(new YearMonth(dp.getYear(), dp.getMonth()), new MoneyAmount(dp.getValue(), currency)) != null) { throw new IllegalArgumentException("Series " + name + " has two values for year " + dp.getYear() + " and month " + dp.getMonth()); }/* w w w . j a v a 2 s.c o m*/ } final InterpolationStrategy strategy = InterpolationStrategy.valueOf(series.getInterpolation()); YearMonth ym = interpolatedData.firstKey(); final YearMonth last = interpolatedData.lastKey(); while (ym.monthsUntil(last) > 0) { YearMonth next = ym.next(); if (!interpolatedData.containsKey(next)) { interpolatedData.put(next, strategy.interpolate(interpolatedData.get(ym), ym, currency)); } ym = ym.next(); } return new SortedMapMoneyAmountSeries(currency, interpolatedData); } catch (IOException ioEx) { throw new IllegalArgumentException("Could not read series named " + name, ioEx); } }