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:org.opencms.workplace.tools.content.CmsTagReplaceSettings.java

/**
 * Sets the replacements to perform in form of a comma-separated List of "key=value" tokens.
 * <p>/*from  ww  w .j av  a  2 s. co m*/
 * 
 * @param replacements the replacements to perform in form of a comma-separated List of
 *            "key=value" tokens.
 * 
 * @throws CmsIllegalArgumentException if the argument is not valid.
 */
public void setReplacements(SortedMap replacements) throws CmsIllegalArgumentException {

    Iterator itMappings = replacements.entrySet().iterator();
    Map.Entry entry;
    String key, value;
    while (itMappings.hasNext()) {
        entry = (Map.Entry) itMappings.next();
        key = (String) entry.getKey();
        value = (String) entry.getValue();
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) {
            // removal
            Tag deleteTag;
            String tagName = (key).toLowerCase().trim();
            try {
                Vector attributeList = new Vector(1);
                Attribute tagNameAttribute = new Attribute();
                tagNameAttribute.setName(tagName);
                attributeList.add(tagNameAttribute);
                deleteTag = m_nodeFactory.createTagNode(null, 0, 0, attributeList);
                m_deleteTags.add(deleteTag);
                itMappings.remove();
            } catch (ParserException e) {
                CmsMessageContainer container = Messages.get()
                        .container(Messages.GUI_ERR_TAGREPLACE_TAGNAME_INVALID_1, tagName);
                throw new CmsIllegalArgumentException(container, e);
            }
        } else {
            // nop
        }
        m_tags2replacementTags = replacements;
    }
    // if setPropertyValueTagReplaceID has been invoked earlier with empty value
    // due to missing user input:
    if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_propertyValueTagReplaceID)) {
        // trigger computation of default ID by empty value:
        setPropertyValueTagReplaceID(null);
    }
}

From source file:org.zenoss.metrics.reporter.ZenossMetricsReporter.java

private void collectMetrics(MetricBatch batchContext) {
    final Collection<SortedMap<MetricName, Metric>> values = getMetricsRegistry().groupedMetrics(this.filter)
            .values();/*from ww w.  j ava  2s  .c  o m*/
    for (SortedMap<MetricName, Metric> map : values) {
        for (Entry<MetricName, Metric> entry : map.entrySet()) {
            final Metric metric = entry.getValue();
            if (metric != null) {
                try {
                    metric.processWith(this, entry.getKey(), batchContext);
                } catch (Exception e) {
                    LOG.error("Error processing metric " + entry.getKey().getName(), e);
                }
            }
        }
    }
}

From source file:org.apache.falcon.unit.LocalExtensionManager.java

APIResult submitExtensionJob(String extensionName, String jobName, InputStream configStream,
        SortedMap<EntityType, List<Entity>> entityMap) throws FalconException, IOException {
    checkIfExtensionIsEnabled(extensionName);
    checkIfExtensionJobNameExists(jobName, extensionName);
    for (Map.Entry<EntityType, List<Entity>> entry : entityMap.entrySet()) {
        for (Entity entity : entry.getValue()) {
            submitInternal(entity, "falconUser");
        }//from w  ww. j  a  v  a  2  s . c  o m
    }
    storeExtension(extensionName, jobName, configStream, entityMap);
    return new APIResult(APIResult.Status.SUCCEEDED, "Extension job submitted successfully" + jobName);
}

From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.model.TasksNavigationModel.java

/**
 * Computes the sets of tags suggestions that matches a given prefix.
 * @param query the prefix to be matched.
 * @return the set of available tags suggestions that matches a prefix.
 *///  w  w  w.  j  ava  2s.com
public Collection<TagSuggestion> getAvailableTags(String query) {
    SortedMap<String, String> mapSuggestions = this.availableTags.prefixMap(query);
    int size = SchedulerConfig.get().getTagSuggestionSize();
    ArrayList<TagSuggestion> suggestions = new ArrayList<TagSuggestion>(size);
    Iterator<Map.Entry<String, String>> it = mapSuggestions.entrySet().iterator();
    for (int i = 0; i < size && it.hasNext(); i++) {
        Map.Entry<String, String> current = it.next();
        TagSuggestion suggestion = new TagSuggestion(current.getValue(), current.getKey());
        suggestions.add(suggestion);
    }

    return suggestions;
}

From source file:org.apache.falcon.unit.LocalExtensionManager.java

APIResult submitAndSchedulableExtensionJob(String extensionName, String jobName, InputStream configStream,
        SortedMap<EntityType, List<Entity>> entityMap) throws FalconException, IOException {
    checkIfExtensionIsEnabled(extensionName);
    checkIfExtensionJobNameExists(jobName, extensionName);
    for (Map.Entry<EntityType, List<Entity>> entry : entityMap.entrySet()) {
        for (Entity entity : entry.getValue()) {
            submitInternal(entity, "falconUser");
        }//from w  w  w. j  a  v a  2  s.  c  o m
    }

    storeExtension(extensionName, jobName, configStream, entityMap);

    for (Map.Entry<EntityType, List<Entity>> entry : entityMap.entrySet()) {
        for (Entity entity : entry.getValue()) {
            scheduleInternal(entry.getKey().name(), entity.getName(), null, null);
        }
    }
    return new APIResult(APIResult.Status.SUCCEEDED,
            "Extension job submitted and scheduled successfully" + jobName);
}

From source file:com.facebook.presto.accumulo.examples.TpcHClerkSearch.java

@Override
public int run(AccumuloConfig config, CommandLine cmd) throws Exception {
    String[] searchTerms = cmd.getOptionValues(CLERK_ID);

    ZooKeeperInstance inst = new ZooKeeperInstance(config.getInstance(), config.getZooKeepers());
    Connector conn = inst.getConnector(config.getUsername(), new PasswordToken(config.getPassword()));

    // Ensure both tables exists
    validateExists(conn, DATA_TABLE);/*from  w  ww.j av a  2 s. c  o m*/
    validateExists(conn, INDEX_TABLE);

    long start = System.currentTimeMillis();

    // Create a scanner against the index table
    BatchScanner idxScanner = conn.createBatchScanner(INDEX_TABLE, new Authorizations(), 10);
    LinkedList<Range> searchRanges = new LinkedList<Range>();

    // Create a search Range from the command line args
    for (String searchTerm : searchTerms) {
        if (clerkRegex.matcher(searchTerm).matches()) {
            searchRanges.add(new Range(searchTerm));
        } else {
            throw new InvalidParameterException(
                    format("Search term %s does not match regex Clerk#[0-9]{9}", searchTerm));
        }
    }

    // Set the search ranges for our scanner
    idxScanner.setRanges(searchRanges);

    // A list to hold all of the order IDs
    LinkedList<Range> orderIds = new LinkedList<Range>();
    String orderId;

    // Process all of the records returned by the batch scanner
    for (Map.Entry<Key, Value> record : idxScanner) {
        // Get the order ID and add it to the list of order IDs
        orderIds.add(new Range(record.getKey().getColumnQualifier()));
    }

    // Close the batch scanner
    idxScanner.close();

    // If clerkIDs is empty, log a message and return 0
    if (orderIds.isEmpty()) {
        System.out.println("Found no orders with the given Clerk ID(s)");
        return 0;
    } else {
        System.out.println(format("Searching data table for %d orders", orderIds.size()));
    }

    // Initialize the batch scanner to scan the data table with
    // the previously found order IDs as the ranges
    BatchScanner dataScanner = conn.createBatchScanner(DATA_TABLE, new Authorizations(), 10);
    dataScanner.setRanges(orderIds);
    dataScanner.addScanIterator(new IteratorSetting(1, WholeRowIterator.class));

    Text row = new Text(); // The row ID
    Text colQual = new Text(); // The column qualifier of the current record

    Long orderkey = null;
    Long custkey = null;
    String orderstatus = null;
    Double totalprice = null;
    Date orderdate = null;
    String orderpriority = null;
    String clerk = null;
    Long shippriority = null;
    String comment = null;

    int numTweets = 0;
    // Process all of the records returned by the batch scanner
    for (Map.Entry<Key, Value> entry : dataScanner) {
        entry.getKey().getRow(row);
        orderkey = decode(Long.class, row.getBytes(), row.getLength());
        SortedMap<Key, Value> rowMap = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue());
        for (Map.Entry<Key, Value> record : rowMap.entrySet()) {
            // Get the column qualifier from the record's key
            record.getKey().getColumnQualifier(colQual);

            switch (colQual.toString()) {
            case CUSTKEY_STR:
                custkey = decode(Long.class, record.getValue().get());
                break;
            case ORDERSTATUS_STR:
                orderstatus = decode(String.class, record.getValue().get());
                break;
            case TOTALPRICE_STR:
                totalprice = decode(Double.class, record.getValue().get());
                break;
            case ORDERDATE_STR:
                orderdate = decode(Date.class, record.getValue().get());
                break;
            case ORDERPRIORITY_STR:
                orderpriority = decode(String.class, record.getValue().get());
                break;
            case CLERK_STR:
                clerk = decode(String.class, record.getValue().get());
                break;
            case SHIPPRIORITY_STR:
                shippriority = decode(Long.class, record.getValue().get());
                break;
            case COMMENT_STR:
                comment = decode(String.class, record.getValue().get());
                break;
            default:
                throw new RuntimeException("Unknown column qualifier " + colQual);
            }
        }

        ++numTweets;
        // Write the screen name and text to stdout
        System.out.println(format("%d|%d|%s|%f|%s|%s|%s|%d|%s", orderkey, custkey, orderstatus, totalprice,
                orderdate, orderpriority, clerk, shippriority, comment));

        custkey = null;
        shippriority = null;
        orderstatus = null;
        orderpriority = null;
        clerk = null;
        comment = null;
        totalprice = null;
        orderdate = null;
    }

    // Close the batch scanner
    dataScanner.close();

    long finish = System.currentTimeMillis();

    System.out.format("Found %d orders in %s ms\n", numTweets, (finish - start));
    return 0;
}

From source file:fr.gael.dhus.util.functional.collect.SortedMapTest.java

/** Constructor: Empty map param. */
@Test//from  w  ww  . j ava  2s.co m
public void emptyMapTest() {
    SortedMap sorted_map = new SortedMap(Collections.emptyMap(), cmp);
    Assert.assertTrue(sorted_map.isEmpty());
    Assert.assertEquals(sorted_map.size(), 0);
    Assert.assertFalse(sorted_map.keySet().iterator().hasNext());
    Assert.assertFalse(sorted_map.values().iterator().hasNext());
    Assert.assertFalse(sorted_map.entrySet().iterator().hasNext());
}

From source file:jenkins.metrics.util.NameRewriterMetricRegistry.java

private <T> SortedMap<String, T> rewrite(SortedMap<String, T> original) {
    if (StringUtils.isBlank(prefix) && StringUtils.isBlank(postfix)) {
        return original;
    }/*from   www  . j a v  a2s.  co m*/
    SortedMap<String, T> result = new TreeMap<String, T>(original.comparator());
    for (Map.Entry<String, T> entry : original.entrySet()) {
        result.put(name(prefix, entry.getKey(), postfix), entry.getValue());
    }
    return result;
}

From source file:amazon.SignedRequestsHelper.java

/**
 * Canonicalize the query string as required by Amazon.
 * /*w w  w .  j  a v a2 s . co  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 cannoical = buffer.toString();
    return cannoical;
}

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

/**
 * The returned map is ordered by keys by {@link dnTypeSorter}.
 *//*from  w w  w  .  j  a v a 2 s . c o m*/
private SortedMap<String, List<String>> showX500Name(X500Name name) {
    Map<String, ArrayList<String>> fields = name.getFields();

    // Convert to Map<String, List<String>>
    Map<String, List<String>> fieldsLists = new LinkedHashMap<>();
    fieldsLists.putAll(fields);

    // Sort by dnTypeSorter
    SortedMap<String, List<String>> fieldsSorted = dnTypeSorter.sort(fieldsLists);

    // Print
    for (Entry<String, List<String>> field : fieldsSorted.entrySet()) {
        String type = field.getKey();
        type = niceX500AttributeType(type);
        List<String> values = field.getValue();
        String valuesString = StringUtils.join(values, ", ");
        to.println(String.format("%s: %s", type, valuesString));
    }

    return fieldsSorted;
}