Example usage for java.util Map.Entry get

List of usage examples for java.util Map.Entry get

Introduction

In this page you can find the example usage for java.util Map.Entry get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.paxle.parser.impl.SubParserManager.java

public Map<String, Set<String>> getParsers() {
    final HashMap<String, Set<String>> r = new HashMap<String, Set<String>>();
    for (final Map.Entry<String, ServiceReference> entry : this.services.entrySet()) {
        final String bundleName = (String) entry.getValue().getBundle().getHeaders().get(Constants.BUNDLE_NAME);
        Set<String> keys = r.get(bundleName);
        if (keys == null)
            r.put(bundleName, keys = new HashSet<String>());
        keys.add(entry.getKey());//ww w .  j  a va2s. c o  m
    }
    return Collections.unmodifiableMap(r);
}

From source file:org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding.java

@SuppressWarnings("unchecked")
protected void copyProtocolHeader(org.apache.cxf.message.Message cxfMessage, Message camelMessage,
        Exchange camelExchange) {//from   w w  w. j  ava 2  s .co  m
    Map<String, List<String>> headers = (Map<String, List<String>>) cxfMessage
            .get(org.apache.cxf.message.Message.PROTOCOL_HEADERS);
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        if (headerFilterStrategy.applyFilterToCamelHeaders(entry.getKey(), entry.getValue(), camelExchange)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Drop CXF message protocol header: " + entry.getKey() + "=" + entry.getValue());
            }
        } else {
            // just put the first String element, as the complex one is filtered
            camelMessage.setHeader(entry.getKey(), entry.getValue().get(0));
        }
        continue;
    }
}

From source file:org.openspaces.rest.space.ReplicationRESTController.java

private String addressesToNat(Map<String, List<String>> gwaddresses) {
    StringBuilder sb = new StringBuilder("[");
    for (Map.Entry<String, List<String>> entry : gwaddresses.entrySet()) {
        sb.append(entry.getValue().get(1)).append(":").append(entry.getValue().get(0)).append(",");
    }/* w w w  .j  ava 2  s  .co m*/
    sb.deleteCharAt(sb.length() - 1);
    sb.append("]");
    log.info("addressesToNat returning:" + sb.toString());
    return sb.toString();
}

From source file:com.alibaba.jstorm.ui.utils.UIUtils.java

private static void fillValue2Node(List<MetricInfo> componentMetrics, Map<String, TopologyNode> nodes) {
    String NODE_DIM = MetricDef.EMMITTED_NUM;
    List<String> FILTER = Arrays.asList(MetricDef.EMMITTED_NUM, MetricDef.SEND_TPS, MetricDef.RECV_TPS);
    for (MetricInfo info : componentMetrics) {
        if (info == null)
            continue;
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : info.get_metrics().entrySet()) {
            String name = metric.getKey();
            String[] split_name = name.split("@");
            String metricName = UIMetricUtils.extractMetricName(split_name);
            String compName = UIMetricUtils.extractComponentName(split_name);

            TopologyNode node = nodes.get(compName);
            if (node != null && FILTER.contains(metricName)) {
                for (Map.Entry<Integer, MetricSnapshot> winData : metric.getValue().entrySet()) {
                    node.putMapValue(metricName, winData.getKey(),
                            UIMetricUtils.getMetricValue(winData.getValue()));
                }//from  ww  w . j  a  v a2 s  .co  m
            }

            if (metricName == null || !metricName.equals(NODE_DIM)) {
                continue;
            }

            //get 60 window metric
            MetricSnapshot snapshot = metric.getValue().get(AsmWindow.M1_WINDOW);

            if (node != null) {
                node.setValue(snapshot.get_longValue());
                nodes.get(compName).setTitle("Emitted: " + UIMetricUtils.getMetricValue(snapshot));
            }
        }
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.admin.BaseUserProvisioningCommand.java

public void apply() throws Exception {
    Map<PscUser, Map<String, List<SubmittedChange>>> changesByUserAndType = classifyAndFilterChanges();
    for (Map.Entry<PscUser, Map<String, List<SubmittedChange>>> entry : changesByUserAndType.entrySet()) {
        PscUser user = entry.getKey();/*from  w  w  w  . j a  v  a 2 s.com*/
        ProvisioningSession session = provisioningSessionFactory.createSession(user.getCsmUser().getUserId());
        applyAddAndRemoveScopes(session, entry.getValue().get("specificScope"));
        applyAddAndRemoveAllScope(session, entry.getValue().get("allScope"));
        applyAddAndRemoveGroupOnly(session, entry.getValue().get("groupOnly"));
    }
    // apply separately since non-role changes may have occurred
    for (PscUser user : getUsers()) {
        applyStaleFlag(user);
    }
}

From source file:org.opennms.features.newts.converter.NewtsConverter.java

private void injectSamplesToNewts(final ResourcePath resourcePath, final String group,
        final List<? extends AbstractDS> dataSources, final SortedMap<Long, List<Double>> samples) {
    final ResourcePath groupPath = ResourcePath.get(resourcePath, group);

    // Create a resource ID from the resource path
    final String groupId = NewtsUtils.toResourceId(groupPath);

    // Build indexing attributes
    final Map<String, String> attributes = Maps.newHashMap();
    NewtsUtils.addIndicesToAttributes(groupPath, attributes);

    // Create the NewTS resource to insert
    final Resource resource = new Resource(groupId, Optional.of(attributes));

    // Transform the RRD samples into NewTS samples
    List<Sample> batch = new ArrayList<>(this.batchSize);
    for (final Map.Entry<Long, List<Double>> s : samples.entrySet()) {
        for (int i = 0; i < dataSources.size(); i++) {
            final double value = s.getValue().get(i);
            if (Double.isNaN(value)) {
                continue;
            }/*w  w w. ja  va2  s. c  o  m*/
            final AbstractDS ds = dataSources.get(i);
            final Timestamp timestamp = Timestamp.fromEpochSeconds(s.getKey());

            try {
                batch.add(toSample(ds, resource, timestamp, value));
            } catch (IllegalArgumentException e) {
                // This can happen when the value is outside of the range for the expected
                // type i.e. negative for a counter, so we silently skip these
                continue;
            }

            if (batch.size() >= this.batchSize) {
                this.repository.insert(batch, true);
                this.processedSamples.getAndAdd(batch.size());

                batch = new ArrayList<>(this.batchSize);
            }
        }
    }

    if (!batch.isEmpty()) {
        this.repository.insert(batch, true);
        this.processedSamples.getAndAdd(batch.size());
    }

    this.processedMetrics.getAndAdd(dataSources.size());

    LOG.trace("Stats: {} / {}", this.processedMetrics, this.processedSamples);
}

From source file:org.apache.lens.cube.metadata.Storage.java

/**
 * Add given partitions in the underlying hive table and update latest partition links
 *
 * @param client                hive client instance
 * @param factOrDimTable        fact or dim name
 * @param updatePeriod          update period of partitions.
 * @param storagePartitionDescs all partitions to be added
 * @param latestInfos           new latest info. atleast one partition for the latest value exists for each part
 *                              column//from   www . j  a v  a2 s.c o m
 * @throws HiveException
 */
public List<Partition> addPartitions(Hive client, String factOrDimTable, UpdatePeriod updatePeriod,
        List<StoragePartitionDesc> storagePartitionDescs, Map<Map<String, String>, LatestInfo> latestInfos,
        String tableName) throws HiveException {
    preAddPartitions(storagePartitionDescs);
    Map<Map<String, String>, Map<String, Integer>> latestPartIndexForPartCols = Maps.newHashMap();
    boolean success = false;
    try {
        String dbName = SessionState.get().getCurrentDatabase();
        AddPartitionDesc addParts = new AddPartitionDesc(dbName, tableName, true);
        Table storageTbl = client.getTable(dbName, tableName);
        for (StoragePartitionDesc addPartitionDesc : storagePartitionDescs) {
            String location = null;
            if (addPartitionDesc.getLocation() != null) {
                Path partLocation = new Path(addPartitionDesc.getLocation());
                if (partLocation.isAbsolute()) {
                    location = addPartitionDesc.getLocation();
                } else {
                    location = new Path(storageTbl.getPath(), partLocation).toString();
                }
            }
            Map<String, String> partParams = addPartitionDesc.getPartParams();
            if (partParams == null) {
                partParams = new HashMap<String, String>();
            }
            partParams.put(MetastoreConstants.PARTITION_UPDATE_PERIOD,
                    addPartitionDesc.getUpdatePeriod().name());
            addParts.addPartition(addPartitionDesc.getStoragePartSpec(), location);
            int curIndex = addParts.getPartitionCount() - 1;
            addParts.getPartition(curIndex).setPartParams(partParams);
            addParts.getPartition(curIndex).setInputFormat(addPartitionDesc.getInputFormat());
            addParts.getPartition(curIndex).setOutputFormat(addPartitionDesc.getOutputFormat());
            addParts.getPartition(curIndex).setNumBuckets(addPartitionDesc.getNumBuckets());
            addParts.getPartition(curIndex).setCols(addPartitionDesc.getCols());
            addParts.getPartition(curIndex).setSerializationLib(addPartitionDesc.getSerializationLib());
            addParts.getPartition(curIndex).setSerdeParams(addPartitionDesc.getSerdeParams());
            addParts.getPartition(curIndex).setBucketCols(addPartitionDesc.getBucketCols());
            addParts.getPartition(curIndex).setSortCols(addPartitionDesc.getSortCols());
            if (latestInfos != null && latestInfos.get(addPartitionDesc.getNonTimePartSpec()) != null) {
                for (Map.Entry<String, LatestPartColumnInfo> entry : latestInfos
                        .get(addPartitionDesc.getNonTimePartSpec()).latestParts.entrySet()) {
                    if (addPartitionDesc.getTimePartSpec().containsKey(entry.getKey()) && entry.getValue()
                            .get(MetastoreUtil.getLatestPartTimestampKey(entry.getKey())).equals(updatePeriod
                                    .format(addPartitionDesc.getTimePartSpec().get(entry.getKey())))) {
                        if (latestPartIndexForPartCols.get(addPartitionDesc.getNonTimePartSpec()) == null) {
                            latestPartIndexForPartCols.put(addPartitionDesc.getNonTimePartSpec(),
                                    Maps.<String, Integer>newHashMap());
                        }
                        latestPartIndexForPartCols.get(addPartitionDesc.getNonTimePartSpec())
                                .put(entry.getKey(), curIndex);
                    }
                }
            }
        }
        if (latestInfos != null) {
            for (Map.Entry<Map<String, String>, LatestInfo> entry1 : latestInfos.entrySet()) {
                Map<String, String> nonTimeParts = entry1.getKey();
                LatestInfo latestInfo = entry1.getValue();
                for (Map.Entry<String, LatestPartColumnInfo> entry : latestInfo.latestParts.entrySet()) {
                    // symlink this partition to latest
                    List<Partition> latest;
                    String latestPartCol = entry.getKey();
                    try {
                        latest = client.getPartitionsByFilter(storageTbl,
                                StorageConstants.getLatestPartFilter(latestPartCol, nonTimeParts));
                    } catch (Exception e) {
                        throw new HiveException("Could not get latest partition", e);
                    }
                    if (!latest.isEmpty()) {
                        client.dropPartition(storageTbl.getTableName(), latest.get(0).getValues(), false);
                    }
                    if (latestPartIndexForPartCols.get(nonTimeParts).containsKey(latestPartCol)) {
                        AddPartitionDesc.OnePartitionDesc latestPartWithFullTimestamp = addParts
                                .getPartition(latestPartIndexForPartCols.get(nonTimeParts).get(latestPartCol));
                        addParts.addPartition(StorageConstants
                                .getLatestPartSpec(latestPartWithFullTimestamp.getPartSpec(), latestPartCol),
                                latestPartWithFullTimestamp.getLocation());
                        int curIndex = addParts.getPartitionCount() - 1;
                        addParts.getPartition(curIndex).setPartParams(
                                entry.getValue().getPartParams(latestPartWithFullTimestamp.getPartParams()));
                        addParts.getPartition(curIndex)
                                .setInputFormat(latestPartWithFullTimestamp.getInputFormat());
                        addParts.getPartition(curIndex)
                                .setOutputFormat(latestPartWithFullTimestamp.getOutputFormat());
                        addParts.getPartition(curIndex)
                                .setNumBuckets(latestPartWithFullTimestamp.getNumBuckets());
                        addParts.getPartition(curIndex).setCols(latestPartWithFullTimestamp.getCols());
                        addParts.getPartition(curIndex)
                                .setSerializationLib(latestPartWithFullTimestamp.getSerializationLib());
                        addParts.getPartition(curIndex)
                                .setSerdeParams(latestPartWithFullTimestamp.getSerdeParams());
                        addParts.getPartition(curIndex)
                                .setBucketCols(latestPartWithFullTimestamp.getBucketCols());
                        addParts.getPartition(curIndex).setSortCols(latestPartWithFullTimestamp.getSortCols());
                    }
                }
            }
        }
        client = Hive.get();

        List<Partition> partitionsAdded = client.createPartitions(addParts);
        success = true;
        return partitionsAdded;
    } finally {
        if (success) {
            commitAddPartitions(storagePartitionDescs);
        } else {
            rollbackAddPartitions(storagePartitionDescs);
        }
    }
}

From source file:com.microsoft.azure.storage.core.Utility.java

/**
 * Logs the HttpURLConnection response. If an exception is encountered, logs nothing.
 * //from   w  w  w  .j  a  v a 2  s  .c om
 * @param conn
 *            The HttpURLConnection to serialize.
 * @param opContext 
 *            The operation context which provides the logger.
 */
public static void logHttpResponse(HttpURLConnection conn, OperationContext opContext) throws IOException {
    if (Logger.shouldLog(opContext)) {
        try {
            StringBuilder bld = new StringBuilder();

            // This map's null key will contain the response code and message
            for (Map.Entry<String, List<String>> header : conn.getHeaderFields().entrySet()) {
                if (header.getKey() != null) {
                    bld.append(header.getKey());
                    bld.append(": ");
                }

                for (int i = 0; i < header.getValue().size(); i++) {
                    bld.append(header.getValue().get(i));
                    if (i < header.getValue().size() - 1) {
                        bld.append(",");
                    }
                }
                bld.append('\n');
            }

            Logger.trace(opContext, bld.toString());
        } catch (Exception e) {
            // Do nothing
        }
    }
}

From source file:net.sourceforge.pmd.lang.java.ast.ParserCornersTest.java

@Test
public void testMethodReferenceConfused() throws Exception {
    String code = readAsString("MethodReferenceConfused.java");
    ASTCompilationUnit compilationUnit = ParserTstUtil.parseAndTypeResolveJava("10", code);
    Assert.assertNotNull(compilationUnit);
    ASTBlock firstBlock = compilationUnit.getFirstDescendantOfType(ASTBlock.class);
    Map<NameDeclaration, List<NameOccurrence>> declarations = firstBlock.getScope().getDeclarations();
    boolean foundVariable = false;
    for (Map.Entry<NameDeclaration, List<NameOccurrence>> declaration : declarations.entrySet()) {
        String varName = declaration.getKey().getImage();
        if ("someVarNameSameAsMethodReference".equals(varName)) {
            foundVariable = true;//from  w w  w  . j a v  a2  s.c  o m
            Assert.assertTrue("no usages expected", declaration.getValue().isEmpty());
        } else if ("someObject".equals(varName)) {
            Assert.assertEquals("1 usage expected", 1, declaration.getValue().size());
            Assert.assertEquals(6, declaration.getValue().get(0).getLocation().getBeginLine());
        }
    }
    Assert.assertTrue("Test setup wrong - variable 'someVarNameSameAsMethodReference' not found anymore!",
            foundVariable);
}

From source file:com.spotify.reaper.cassandra.JmxProxy.java

/**
 * @return all hosts owning a range of tokens
 *//*from   w w w .  j  av a2 s.  c o  m*/
@NotNull
public List<String> tokenRangeToEndpoint(String keyspace, RingRange tokenRange) {
    checkNotNull(ssProxy, "Looks like the proxy is not connected");
    Set<Map.Entry<List<String>, List<String>>> entries = ((StorageServiceMBean) ssProxy)
            .getRangeToEndpointMap(keyspace).entrySet();
    for (Map.Entry<List<String>, List<String>> entry : entries) {
        BigInteger rangeStart = new BigInteger(entry.getKey().get(0));
        BigInteger rangeEnd = new BigInteger(entry.getKey().get(1));
        if (new RingRange(rangeStart, rangeEnd).encloses(tokenRange)) {
            return entry.getValue();
        }
    }
    return Lists.newArrayList();
}