List of usage examples for java.util SortedMap put
V put(K key, V value);
From source file:helpers.database.DBStatisticsManager.java
private static SortedMap<Integer, Integer> getUserHistogram(String query) { SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>(); DBContext c = new DBContext(); try {/*from w w w .j a v a2s .co m*/ if (c.initSlave()) { // initialize slave database c.stmt = c.conn.prepareStatement(query); c.rst = c.stmt.executeQuery(); while (c.rst.next()) { map.put(c.rst.getInt("ctr"), c.rst.getInt("uCtr")); } } } catch (SQLException e) { log.fatal("could not get statistics: " + e); } finally { c.close(); // close database connection } return map; }
From source file:de.tudarmstadt.ukp.dkpro.tc.svmhmm.util.SVMHMMUtils.java
public static List<SortedMap<String, String>> extractMetaDataFeatures(File featureVectorsFile) throws IOException { InputStream inputStream = new FileInputStream(featureVectorsFile); List<SortedMap<String, String>> result = new ArrayList<>(); List<List<String>> allComments = extractComments(inputStream); for (List<String> instanceComments : allComments) { SortedMap<String, String> instanceResult = new TreeMap<>(); for (String comment : instanceComments) { if (comment.startsWith(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX)) { String[] split = comment.split(":"); String key = split[0]; String value = split[1]; instanceResult.put(key, value); }//from w w w. jav a 2 s . c o m } result.add(instanceResult); } IOUtils.closeQuietly(inputStream); return result; }
From source file:gov.nih.nci.cabig.ctms.web.WebTools.java
public static SortedMap<String, Object> requestPropertiesToMap(HttpServletRequest request) { BeanWrapper wrapped = new BeanWrapperImpl(request); SortedMap<String, Object> map = new TreeMap<String, Object>(); for (PropertyDescriptor descriptor : wrapped.getPropertyDescriptors()) { String name = descriptor.getName(); if (!EXCLUDED_REQUEST_PROPERTIES.contains(name) && descriptor.getReadMethod() != null) { Object propertyValue; try { propertyValue = wrapped.getPropertyValue(name); } catch (InvalidPropertyException e) { log.debug("Exception reading request property " + name, e); propertyValue = e.getMostSpecificCause(); }/* ww w . j a va2s . c o m*/ map.put(name, propertyValue); } } return map; }
From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java
/** * Returns the first row of a sheet where there is the fields name * @return Map<ColumnNumber, FieldLabelName> *///from ww w . j a v a2 s. co m static SortedMap<Integer, String> getFirstRowNumericToLetter(Workbook hSSFWorkbook, Integer sheetID) { SortedMap<Integer, String> firstRowMap = new TreeMap<Integer, String>(); if (hSSFWorkbook == null || sheetID == null) { return firstRowMap; } Sheet sheet = hSSFWorkbook.getSheetAt(sheetID.intValue()); Row firstRow = sheet.getRow(0); if (firstRow != null) { for (Cell cell : firstRow) { firstRowMap.put(Integer.valueOf(cell.getColumnIndex()), colNumericToLetter(cell.getColumnIndex())); } } return firstRowMap; }
From source file:com.facebook.buck.util.unarchive.Unzip.java
/** * Get a listing of all files in a zip file that start with a prefix, ignore others * * @param zip The zip file to scan/*from w w w . ja v a 2 s . c o m*/ * @param relativePath The relative path where the extraction will be rooted * @param prefix The prefix that will be stripped off. * @return The list of paths in {@code zip} sorted by path so dirs come before contents. Prefixes * are stripped from paths in the zip file, such that foo/bar/baz.txt with a prefix of foo/ * will be in the map at {@code relativePath}/bar/baz.txt */ private static SortedMap<Path, ZipArchiveEntry> getZipFilePathsStrippingPrefix(ZipFile zip, Path relativePath, Path prefix, PatternsMatcher entriesToExclude) { SortedMap<Path, ZipArchiveEntry> pathMap = new TreeMap<>(); for (ZipArchiveEntry entry : Collections.list(zip.getEntries())) { String entryName = entry.getName(); if (entriesToExclude.matchesAny(entryName)) { continue; } Path entryPath = Paths.get(entryName); if (entryPath.startsWith(prefix)) { Path target = relativePath.resolve(prefix.relativize(entryPath)).normalize(); pathMap.put(target, entry); } } return pathMap; }
From source file:co.rsk.peg.BridgeSerializationUtils.java
public static SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> deserializePairMap(byte[] data, NetworkParameters networkParameters) { SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> map = new TreeMap<>(); if (data == null || data.length == 0) return map; RLPList rlpList = (RLPList) RLP.decode2(data).get(0); int ntxs = rlpList.size() / 3; for (int k = 0; k < ntxs; k++) { Sha3Hash hash = new Sha3Hash(rlpList.get(k * 3).getRLPData()); BtcTransaction tx = new BtcTransaction(networkParameters, rlpList.get(k * 3 + 1).getRLPData()); byte[] lkeyBytes = rlpList.get(k * 3 + 2).getRLPData(); Long lkey = lkeyBytes == null ? 0 : (new BigInteger(1, lkeyBytes)).longValue(); map.put(hash, Pair.of(tx, lkey)); }//from www .ja v a2 s . c o m return map; }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java
/** * @param node/* ww w .j av a 2 s . co m*/ * @param opts * @param out * @throws RepositoryException * @throws JSONException * @throws ValueFormatException * @throws IOException */ private static void outputProperties(Node node, ChecksumGeneratorOptions opts, JsonWriter out) throws RepositoryException, ValueFormatException, IOException { Set<String> excludes = opts.getExcludedProperties(); SortedMap<String, Property> props = new TreeMap<String, Property>(); PropertyIterator propertyIterator = node.getProperties(); // sort the properties by name as the JCR makes no guarantees on property order while (propertyIterator.hasNext()) { Property property = propertyIterator.nextProperty(); //skip the property if it is in the excludes list if (excludes.contains(property.getName())) { continue; } else { props.put(property.getName(), property); } } for (Property property : props.values()) { outputProperty(property, opts, out); } }
From source file:models.ModuleVersion.java
public static SortedMap<String, SortedSet<ModuleVersion>> findDependants(String moduleName, String version) { String query = "SELECT d.version, v FROM ModuleVersion v JOIN v.dependencies d LEFT JOIN FETCH v.module WHERE d.name=:name"; if (version != null && !version.isEmpty()) { query += " AND d.version=:version"; }//from ww w.j a v a 2s . c om Query jpa = JPA.em().createQuery(query).setParameter("name", moduleName); if (version != null && !version.isEmpty()) { jpa.setParameter("version", version); } List<Object[]> results = jpa.getResultList(); Comparator<String> versionComparator = new Comparator<String>() { @Override public int compare(String v1, String v2) { return Util.compareVersions(v1, v2); } }; Comparator<ModuleVersion> dependantComparator = new Comparator<ModuleVersion>() { @Override public int compare(ModuleVersion v1, ModuleVersion v2) { int result = v1.module.name.compareTo(v2.module.name); if (result == 0) { result = Util.compareVersions(v1.version, v2.version); } return result; } }; SortedMap<String, SortedSet<ModuleVersion>> dependantsMap = new TreeMap<String, SortedSet<ModuleVersion>>( versionComparator); for (Object[] result : results) { String ver = (String) result[0]; ModuleVersion dependant = (ModuleVersion) result[1]; SortedSet<ModuleVersion> dependants = dependantsMap.get(ver); if (dependants == null) { dependants = new TreeSet<ModuleVersion>(dependantComparator); dependantsMap.put(ver, dependants); } dependants.add(dependant); } return dependantsMap; }
From source file:knowledgeMiner.mining.SentenceParserHeuristic.java
/** * Locates the anchors in a string and forms a replacement map for them. * /*from ww w . j a v a 2s .co m*/ * @param sentence * The sentence to search for anchors. * @param anchorWeights * An optional map to record any weight information for the * anchors. If no weights in the text, all weights are assumed to * be 1.0. * @return A SortedMap of anchors, ordered in largest text size to smallest. */ public static SortedMap<String, String> locateAnchors(String sentence, Map<String, Double> anchorWeights) { SortedMap<String, String> anchorMap = new TreeMap<>(new Comparator<String>() { @Override public int compare(String o1, String o2) { int result = Double.compare(o1.length(), o2.length()); if (result != 0) return -result; return o1.compareTo(o2); } }); Matcher m = WikiParser.ANCHOR_PARSER.matcher(sentence); while (m.find()) { String replString = (m.group(2) != null) ? m.group(2) : m.group(1); anchorMap.put(replString, m.group()); } return anchorMap; }
From source file:gov.nasa.arc.spife.ui.lifecycle.SpifeProjectUtils.java
public static SortedMap<String, String> getIdMap(EPlan schedule, URI uri, Comparator<String> comparator) { SortedMap<String, String> idMap = new TreeMap<String, String>(comparator); EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(schedule); if (domain != null) { ResourceSet resourceSet = domain.getResourceSet(); try {// www .ja va2s .c o m Resource resource = resourceSet.getResource(uri, true); EList<EObject> crewMembers = resource.getContents(); for (EObject crewmember : crewMembers) { IItemLabelProvider adapter = EMFUtils.adapt(crewmember, IItemLabelProvider.class); String name = adapter.getText(crewmember); String id = EcoreUtil.getID(crewmember); idMap.put(name, id); } } catch (WrappedException e) { LogUtil.error(e.getCause().getMessage()); } } else { LogUtil.warn("getIdMap(): The IDs were not populated. Domain was null."); } return idMap; }