Example usage for java.util SortedMap entrySet

List of usage examples for java.util SortedMap entrySet

Introduction

In this page you can find the example usage for java.util SortedMap entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:model.connection.amazon.SignedRequestsHelper.java

/**
 * Canonicalize the query string as required by Amazon.
 * /*from w w  w.  j  a  v a2s. c o m*/
 * @param sortedParamMap    Parameter name-value pairs in lexicographical order.
 * @return                  Canonical form of query string.
 */
private String canonicalize(SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap.isEmpty()) {
        return "";
    }

    StringBuffer buffer = new StringBuffer();
    Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<String, String> kvpair = iter.next();
        buffer.append(percentEncodeRfc3986(kvpair.getKey()));
        buffer.append("=");
        buffer.append(percentEncodeRfc3986(kvpair.getValue()));
        if (iter.hasNext()) {
            buffer.append("&");
        }
    }
    String cannonical = buffer.toString();
    return cannonical;
}

From source file:org.apache.giraph.comm.TestMessageStores.java

private void putNTimes(MessageStore<IntWritable, IntWritable> messageStore,
        Map<IntWritable, Collection<IntWritable>> messages, TestData testData) throws IOException {
    for (int n = 0; n < testData.numTimes; n++) {
        SortedMap<IntWritable, Collection<IntWritable>> batch = createRandomMessages(testData);
        messageStore.addMessages(new InputMessageStore(service, config, batch));
        for (Entry<IntWritable, Collection<IntWritable>> entry : batch.entrySet()) {
            if (messages.containsKey(entry.getKey())) {
                messages.get(entry.getKey()).addAll(entry.getValue());
            } else {
                messages.put(entry.getKey(), entry.getValue());
            }//from   w w w  .  j  ava 2  s.c o m
        }
    }
}

From source file:org.apache.metron.common.stellar.shell.StellarExecutor.java

public Iterable<String> autoComplete(String buffer, final OperationType opType) {
    indexLock.readLock().lock();/*from   w w  w .  j a  va2  s.  c o m*/
    try {
        SortedMap<String, AutoCompleteType> ret = autocompleteIndex.prefixMap(buffer);
        if (ret.isEmpty()) {
            return new ArrayList<>();
        }
        return Iterables.transform(ret.entrySet(), kv -> kv.getValue().transform(opType, kv.getKey()));
    } finally {
        indexLock.readLock().unlock();
    }
}

From source file:org.apache.fop.tools.fontlist.FontListMain.java

private void writeOutput(SortedMap fontFamilies)
        throws TransformerConfigurationException, SAXException, IOException {
    if (this.outputFile.isDirectory()) {
        System.out.println("Creating one file for each family...");
        Iterator iter = fontFamilies.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String familyName = (String) entry.getKey();
            System.out.println("Creating output file for " + familyName + "...");
            String filename;/*from   ww w. j  a  v a2s  .c  o m*/
            switch (this.mode) {
            case GENERATE_RENDERED:
                filename = familyName + ".pdf";
                break;
            case GENERATE_FO:
                filename = familyName + ".fo";
                break;
            case GENERATE_XML:
                filename = familyName + ".xml";
                break;
            default:
                throw new IllegalStateException("Unsupported mode");
            }
            File outFile = new File(this.outputFile, filename);
            generateXML(fontFamilies, outFile, familyName);
        }
    } else {
        System.out.println("Creating output file...");
        generateXML(fontFamilies, this.outputFile, this.singleFamilyFilter);
    }
    System.out.println(this.outputFile + " written.");
}

From source file:cz.hobrasoft.pdfmu.operation.OperationInspect.java

private SortedMap<String, String> get(PdfReader pdfReader) {
    Map<String, String> properties = pdfReader.getInfo();

    MetadataParameters mp = new MetadataParameters();
    mp.setFromInfo(properties);/*ww w  . j a v  a 2  s .co  m*/

    SortedMap<String, String> propertiesSorted = mp.getSorted();

    {
        to.indentMore("Properties:");
        for (Map.Entry<String, String> property : propertiesSorted.entrySet()) {
            String key = property.getKey();
            String value = property.getValue();
            to.println(String.format("%s: %s", key, value));
        }
        to.indentLess();
    }

    return propertiesSorted;
}

From source file:org.sakaiproject.tool.roster.RosterGroupMembership.java

private String getRoleCountMessage(SortedMap<String, Integer> roleCounts) {
    if (roleCounts.size() == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    for (Iterator<Entry<String, Integer>> iter = roleCounts.entrySet().iterator(); iter.hasNext();) {
        Entry<String, Integer> entry = iter.next();
        String[] params = new String[] { entry.getValue().toString(), entry.getKey() };
        sb.append(getFormattedMessage("role_breakdown_fragment", params));
        if (iter.hasNext()) {
            sb.append(", ");
        }/*from w  ww.j  av  a2s.c  om*/
    }
    sb.append(")");
    return sb.toString();
}

From source file:com.github.joshelser.accumulo.DelimitedIngestMiniClusterTest.java

@Test
public void testIngest() throws Exception {
    final File csvData = generateCsvData();
    FS.copyFromLocalFile(new Path(csvData.getAbsolutePath()), new Path(csvData.getName()));

    // Create a table
    final String tableName = testName.getMethodName();
    Connector conn = MAC.getConnector("root", new PasswordToken(ROOT_PASSWORD));
    conn.tableOperations().create(tableName);

    ARGS.setTableName(tableName);/*from ww w. j ava 2 s .c  om*/
    ARGS.setInput(Collections.singletonList(csvData.getName()));
    ARGS.setColumnMapping(DelimitedIngest.ROW_ID + ",f1:q1,f1:q2,f1:q3,f1:q4,f1:q5,f1:q6,f1:q7,f1:q8,f1:q9");

    DelimitedIngest ingester = new DelimitedIngest(ARGS);
    assertEquals(ReturnCodes.NORMAL, ingester.call().intValue());

    BatchScanner bs = conn.createBatchScanner(tableName, new Authorizations(), 4);
    bs.addScanIterator(new IteratorSetting(50, WholeRowIterator.class));
    bs.setRanges(Collections.singleton(new Range()));
    long numRows = 0;
    try {
        for (Entry<Key, Value> entry : bs) {
            SortedMap<Key, Value> row = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue());
            // One "column" is the rowId
            assertEquals("Unexpected columns in row: " + row, NUM_COLUMNS - 1, row.size());
            int csvColumns = 0;
            for (Entry<Key, Value> rowEntry : row.entrySet()) {
                Key k = rowEntry.getKey();
                Value v = rowEntry.getValue();
                if (csvColumns == 0) {
                    assertEquals("column" + String.format("%05d", numRows) + "_" + csvColumns,
                            k.getRow().toString());
                    csvColumns++;
                }
                assertEquals("f1", k.getColumnFamily().toString());
                assertEquals("q" + csvColumns, k.getColumnQualifier().toString());
                assertEquals("column" + String.format("%05d", numRows) + "_" + csvColumns, v.toString());
                csvColumns++;
            }
            numRows++;
        }
    } finally {
        if (null != bs) {
            bs.close();
        }
    }
    assertEquals(NUM_ROWS, numRows);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java

/**
 * Find all elementary cycles in graph (with hard limit 10k cycles to prevent overflow)
 *
 * @param graph graph/*from  w  ww.  jav  a  2s . c o  m*/
 * @return list of paths (path = list of node ID) of null, if self-loop found
 */
private static List<List<Object>> findCyclesInGraph(Graph graph) {
    // convert into adjacency matrix representation
    SortedMap<String, Integer> nodeToIndexMap = new TreeMap<>();

    ArrayList<Node> origNodes = new ArrayList<>(graph.getNodeSet());
    for (int i = 0; i < origNodes.size(); i++) {
        nodeToIndexMap.put(origNodes.get(i).getId(), i);
    }

    // convert to different format for the algorithm
    String[] nodeIds = new String[origNodes.size()];
    boolean adjMatrix[][] = new boolean[origNodes.size()][origNodes.size()];

    // fill node IDs to array
    for (Map.Entry<String, Integer> entry : nodeToIndexMap.entrySet()) {
        nodeIds[entry.getValue()] = entry.getKey();
    }

    // fill adjacency matrix
    for (Edge edge : graph.getEdgeSet()) {
        String sourceId = edge.getSourceNode().getId();
        String targetId = edge.getTargetNode().getId();

        int sourceIndex = nodeToIndexMap.get(sourceId);
        int targetIndex = nodeToIndexMap.get(targetId);

        adjMatrix[sourceIndex][targetIndex] = true;
    }

    // let's do the magic :)
    ElementaryCyclesSearch ecs = new ElementaryCyclesSearch(adjMatrix, nodeIds);

    List<List<Object>> cycles = ecs.getElementaryCycles();

    // since the algorithm doesn't reveal self-loops, find them by ourselves
    for (Edge edge : graph.getEdgeSet()) {
        if (edge.getTargetNode().getId().equals(edge.getSourceNode().getId())) {
            //                cycles.add(Arrays.asList((Object) edge.getSourceNode().getId(),
            //                        edge.getTargetNode().getId()));
            cycles.add(Collections.<Object>singletonList(edge.getSourceNode().getId()));
        }
    }

    //        System.out.println(cycles);

    return cycles;
}

From source file:com.hyperaware.conference.android.fragment.HomeFragment.java

private void populateTimeGroups(SortedMap<DateRange, List<AgendaItem>> groups, ViewGroup time_groups) {
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    for (Map.Entry<DateRange, List<AgendaItem>> entry : groups.entrySet()) {
        final ViewGroup sessions_group = (ViewGroup) inflater.inflate(R.layout.item_time_group_sessions,
                time_groups, false);// w  ww .  ja  va2  s  .  com
        time_groups.addView(sessions_group);

        final TextView tv_time = (TextView) sessions_group.findViewById(R.id.tv_time);
        final DateRange range = entry.getKey();
        sb.setLength(0);
        DateUtils.formatDateRange(tv_time.getContext(), formatter, range.start, range.end,
                DateUtils.FORMAT_SHOW_TIME, event.getTimezoneName());
        tv_time.setText(formatter.toString());

        final ViewGroup vg_sessions = (ViewGroup) sessions_group.findViewById(R.id.vg_sessions);
        vg_sessions.removeAllViews();
        for (final AgendaItem item : entry.getValue()) {
            final View session = inflater.inflate(R.layout.item_time_group_session, vg_sessions, false);
            vg_sessions.addView(session);
            final TextView tv_topic = (TextView) session.findViewById(R.id.tv_topic);
            tv_topic.setText(item.getTopic());
        }
    }
}

From source file:com.haulmont.cuba.web.sys.WebJarResourceResolver.java

protected void printNotFoundTraceInfo(SortedMap<String, String> pathIndex, String partialPath) {
    String fullPathIndexLog = fullPathIndex.entrySet().stream().map(p -> p.getKey() + " : " + p.getValue())
            .collect(Collectors.joining("\n"));
    String pathIndexLog = pathIndex.entrySet().stream().map(p -> p.getKey() + " : " + p.getValue())
            .collect(Collectors.joining("\n"));

    log.trace("Unable to find WebJar resource: {}\n " + "WebJar full path index:\n {}\n" + "Path index: \n{}",
            partialPath, fullPathIndexLog, pathIndexLog);
}