List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.accumulo.fate.zookeeper.DistributedReadWriteLock.java
static public Lock recoverLock(QueueLock qlock, byte[] data) { SortedMap<Long, byte[]> entries = qlock.getEarlierEntries(Long.MAX_VALUE); for (Entry<Long, byte[]> entry : entries.entrySet()) { ParsedLock parsed = new ParsedLock(entry.getValue()); if (Arrays.equals(data, parsed.getUserData())) { switch (parsed.getType()) { case READ: return new ReadLock(qlock, parsed.getUserData(), entry.getKey()); case WRITE: return new WriteLock(qlock, parsed.getUserData(), entry.getKey()); }// w w w.ja va 2 s .c o m } } return null; }
From source file:co.rsk.peg.BridgeSerializationUtils.java
public static byte[] serializeMap(SortedMap<Sha3Hash, BtcTransaction> map) { int ntxs = map.size(); byte[][] bytes = new byte[ntxs * 2][]; int n = 0;// w w w . j av a 2 s . co m for (Map.Entry<Sha3Hash, BtcTransaction> entry : map.entrySet()) { bytes[n++] = RLP.encodeElement(entry.getKey().getBytes()); bytes[n++] = RLP.encodeElement(entry.getValue().bitcoinSerialize()); } return RLP.encodeList(bytes); }
From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java
private static <K, V> SortedMap<K, Set<V>> listSortedMapToSetSortedMap(SortedMap<K, List<V>> map) { SortedMap<K, Set<V>> result = Maps.newTreeMap(map.comparator()); for (Entry<K, List<V>> e : map.entrySet()) { result.put(e.getKey(), Sets.<V>newHashSet(e.getValue())); }//from w ww .j av a 2 s. c om return result; }
From source file:com.github.tteofili.p2h.Par2HierUtils.java
/** * base case: on a leaf hv = pv/*from www .ja va 2s .co m*/ * on a non-leaf node with n children: hv = pv + k centroids of the n hv */ private static INDArray getPar2HierVector(WeightLookupTable<VocabWord> lookupTable, PatriciaTrie<String> trie, String node, int k, Map<String, INDArray> hvs, Method method) { if (hvs.containsKey(node)) { return hvs.get(node); } INDArray hv = lookupTable.vector(node); String[] split = node.split(REGEX); Collection<String> descendants = new HashSet<>(); if (split.length == 2) { String separator = "."; String prefix = node.substring(0, node.indexOf(split[1])) + separator; SortedMap<String, String> sortedMap = trie.prefixMap(prefix); for (Map.Entry<String, String> entry : sortedMap.entrySet()) { if (prefix.lastIndexOf(separator) == entry.getKey().lastIndexOf(separator)) { descendants.add(entry.getValue()); } } } else { descendants = Collections.emptyList(); } if (descendants.size() == 0) { // just the pv hvs.put(node, hv); return hv; } else { INDArray chvs = Nd4j.zeros(descendants.size(), hv.columns()); int i = 0; for (String desc : descendants) { // child hierarchical vector INDArray chv = getPar2HierVector(lookupTable, trie, desc, k, hvs, method); chvs.putRow(i, chv); i++; } double[][] centroids; if (chvs.rows() > k) { centroids = Par2HierUtils.getTruncatedVT(chvs, k); } else if (chvs.rows() == 1) { centroids = Par2HierUtils.getDoubles(chvs.getRow(0)); } else { centroids = Par2HierUtils.getTruncatedVT(chvs, 1); } switch (method) { case CLUSTER: INDArray matrix = Nd4j.zeros(centroids.length + 1, hv.columns()); matrix.putRow(0, hv); for (int c = 0; c < centroids.length; c++) { matrix.putRow(c + 1, Nd4j.create(centroids[c])); } hv = Nd4j.create(Par2HierUtils.getTruncatedVT(matrix, 1)); break; case SUM: for (double[] centroid : centroids) { hv.addi(Nd4j.create(centroid)); } break; } hvs.put(node, hv); return hv; } }
From source file:org.bibsonomy.rest.RESTUtils.java
private static List<RenderingFormat> getSupportedAcceptHeaderMediaTypes(final String acceptHeader) { final List<RenderingFormat> formats = new LinkedList<RenderingFormat>(); // parse the accept header final SortedMap<Double, Vector<String>> preferredTypes = HeaderUtils.getPreferredTypes(acceptHeader); for (final Entry<Double, Vector<String>> preferredType : preferredTypes.entrySet()) { /*//from w ww.j av a2 s . c om * which media type do we accept? */ for (final String mediaTypeString : preferredType.getValue()) { try { final RenderingFormat renderingFormat = RenderingFormat.getMediaType(mediaTypeString); for (final RenderingFormat supportedMediaType : SUPPORTED_RENDERING_FORMAT) { if (supportedMediaType.isCompatible(renderingFormat)) { formats.add(supportedMediaType); } } } catch (final IllegalArgumentException e) { // don't care } } } return formats; }
From source file:co.rsk.peg.BridgeSerializationUtils.java
public static byte[] serializePairMap(SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> map) { int ntxs = map.size(); byte[][] bytes = new byte[ntxs * 3][]; int n = 0;// w ww . j a v a2 s .c o m for (Map.Entry<Sha3Hash, Pair<BtcTransaction, Long>> entry : map.entrySet()) { bytes[n++] = RLP.encodeElement(entry.getKey().getBytes()); bytes[n++] = RLP.encodeElement(entry.getValue().getLeft().bitcoinSerialize()); bytes[n++] = RLP.encodeBigInteger(BigInteger.valueOf(entry.getValue().getRight())); } return RLP.encodeList(bytes); }
From source file:edu.uci.ics.crawler4j.url.URLCanonicalizer.java
/** * Canonicalize the query string./* www . j a v a2s.co m*/ * * @param sortedParamMap * Parameter name-value pairs in lexicographical order. * @return Canonical form of query string. */ private static String canonicalize(final SortedMap<String, String> sortedParamMap) { if (sortedParamMap == null || sortedParamMap.isEmpty()) { return ""; } final StringBuilder sb = new StringBuilder(100); for (Map.Entry<String, String> pair : sortedParamMap.entrySet()) { final String key = pair.getKey().toLowerCase(); if (key.equals("jsessionid") || key.equals("phpsessid") || key.equals("aspsessionid")) { continue; } if (sb.length() > 0) { sb.append('&'); } sb.append(percentEncodeRfc3986(pair.getKey())); if (!pair.getValue().isEmpty()) { sb.append('='); sb.append(percentEncodeRfc3986(pair.getValue())); } } return sb.toString(); }
From source file:playground.johannes.sna.util.TXTWriter.java
public static void writeStatistics(Map<String, DescriptiveStatistics> statsMap, String filename) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(filename)); writer.write("property"); writer.write(TAB);//from w ww .j a va 2s .c o m writer.write("mean"); writer.write(TAB); writer.write("median"); writer.write(TAB); writer.write("min"); writer.write(TAB); writer.write("max"); writer.write(TAB); writer.write("n"); writer.newLine(); writer.newLine(); SortedMap<String, DescriptiveStatistics> sortedMap = new TreeMap<String, DescriptiveStatistics>(statsMap); for (Entry<String, DescriptiveStatistics> entry : sortedMap.entrySet()) { writer.write(entry.getKey()); writer.write("\t"); writer.write(String.valueOf(entry.getValue().getMean())); writer.write("\t"); writer.write(String.valueOf(entry.getValue().getPercentile(50))); writer.write("\t"); writer.write(String.valueOf(entry.getValue().getMin())); writer.write("\t"); writer.write(String.valueOf(entry.getValue().getMax())); writer.write("\t"); writer.write(String.valueOf(entry.getValue().getN())); writer.write("\t"); writer.write(String.valueOf(entry.getValue().getVariance())); writer.newLine(); } writer.close(); }
From source file:Main.java
public static String getBuildInformationAsString() { SortedMap<String, String> keysToValues = new TreeMap<String, String>(); for (String buildField : BUILD_FIELDS) { putKeyValue(Build.class, buildField, keysToValues); }//w w w .ja va 2 s.co m for (String buildVersionField : BUILD_VERSION_FIELDS) { putKeyValue(Build.VERSION.class, buildVersionField, keysToValues); } StringBuilder stringBuilder = new StringBuilder(); for (Entry<String, String> entry : keysToValues.entrySet()) { stringBuilder.append(entry.getKey()).append(": ").append(entry.getValue()).append('\n'); } return stringBuilder.toString(); }
From source file:bigbluej.Client.java
static String toQuery(SortedMap<String, Object> sortedParameterMap) throws UnsupportedEncodingException { Validate.notNull(sortedParameterMap); StringBuilder s = new StringBuilder(); for (Iterator<Map.Entry<String, Object>> iterator = sortedParameterMap.entrySet().iterator(); iterator .hasNext();) {//from w w w . j ava 2 s .c o m Map.Entry<String, Object> entry = iterator.next(); s.append(String.format("%s=%s", entry.getKey(), URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8"))); if (iterator.hasNext()) { s.append("&"); } } return s.toString(); }