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.apache.storm.loadgen.CaptureLoad.java

static TopologyLoadConf captureTopology(Nimbus.Iface client, TopologySummary topologySummary) throws Exception {
    String topologyName = topologySummary.get_name();
    LOG.info("Capturing {}...", topologyName);
    String topologyId = topologySummary.get_id();
    TopologyInfo info = client.getTopologyInfo(topologyId);
    TopologyPageInfo tpinfo = client.getTopologyPageInfo(topologyId, ":all-time", false);
    @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
    StormTopology topo = client.getUserTopology(topologyId);
    //Done capturing topology information...

    Map<String, Object> savedTopoConf = new HashMap<>();
    Map<String, Object> topoConf = (Map<String, Object>) JSONValue.parse(client.getTopologyConf(topologyId));
    for (String key : TopologyLoadConf.IMPORTANT_CONF_KEYS) {
        Object o = topoConf.get(key);
        if (o != null) {
            savedTopoConf.put(key, o);//ww w  . j a  va2 s .  co m
            LOG.info("with config {}: {}", key, o);
        }
    }
    //Lets use the number of actually scheduled workers as a way to bridge RAS and non-RAS
    int numWorkers = tpinfo.get_num_workers();
    if (savedTopoConf.containsKey(Config.TOPOLOGY_WORKERS)) {
        numWorkers = Math.max(numWorkers, ((Number) savedTopoConf.get(Config.TOPOLOGY_WORKERS)).intValue());
    }
    savedTopoConf.put(Config.TOPOLOGY_WORKERS, numWorkers);

    Map<String, LoadCompConf.Builder> boltBuilders = new HashMap<>();
    Map<String, LoadCompConf.Builder> spoutBuilders = new HashMap<>();
    List<InputStream.Builder> inputStreams = new ArrayList<>();
    Map<GlobalStreamId, OutputStream.Builder> outStreams = new HashMap<>();

    //Bolts
    if (topo.get_bolts() != null) {
        for (Map.Entry<String, Bolt> boltSpec : topo.get_bolts().entrySet()) {
            String boltComp = boltSpec.getKey();
            LOG.info("Found bolt {}...", boltComp);
            Bolt bolt = boltSpec.getValue();
            ComponentCommon common = bolt.get_common();
            Map<GlobalStreamId, Grouping> inputs = common.get_inputs();
            if (inputs != null) {
                for (Map.Entry<GlobalStreamId, Grouping> input : inputs.entrySet()) {
                    GlobalStreamId id = input.getKey();
                    LOG.info("with input {}...", id);
                    Grouping grouping = input.getValue();
                    InputStream.Builder builder = new InputStream.Builder().withId(id.get_streamId())
                            .withFromComponent(id.get_componentId()).withToComponent(boltComp)
                            .withGroupingType(grouping);
                    inputStreams.add(builder);
                }
            }
            Map<String, StreamInfo> outputs = common.get_streams();
            if (outputs != null) {
                for (String name : outputs.keySet()) {
                    GlobalStreamId id = new GlobalStreamId(boltComp, name);
                    LOG.info("and output {}...", id);
                    OutputStream.Builder builder = new OutputStream.Builder().withId(name);
                    outStreams.put(id, builder);
                }
            }
            LoadCompConf.Builder builder = new LoadCompConf.Builder()
                    .withParallelism(common.get_parallelism_hint()).withId(boltComp);
            boltBuilders.put(boltComp, builder);
        }

        Map<String, Map<String, Double>> boltResources = getBoltsResources(topo, topoConf);
        for (Map.Entry<String, Map<String, Double>> entry : boltResources.entrySet()) {
            LoadCompConf.Builder bd = boltBuilders.get(entry.getKey());
            if (bd != null) {
                Map<String, Double> resources = entry.getValue();
                Double cpu = resources.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT);
                if (cpu != null) {
                    bd.withCpuLoad(cpu);
                }
                Double mem = resources.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB);
                if (mem != null) {
                    bd.withMemoryLoad(mem);
                }
            }
        }
    }

    //Spouts
    if (topo.get_spouts() != null) {
        for (Map.Entry<String, SpoutSpec> spoutSpec : topo.get_spouts().entrySet()) {
            String spoutComp = spoutSpec.getKey();
            LOG.info("Found Spout {}...", spoutComp);
            SpoutSpec spout = spoutSpec.getValue();
            ComponentCommon common = spout.get_common();

            Map<String, StreamInfo> outputs = common.get_streams();
            if (outputs != null) {
                for (String name : outputs.keySet()) {
                    GlobalStreamId id = new GlobalStreamId(spoutComp, name);
                    LOG.info("with output {}...", id);
                    OutputStream.Builder builder = new OutputStream.Builder().withId(name);
                    outStreams.put(id, builder);
                }
            }
            LoadCompConf.Builder builder = new LoadCompConf.Builder()
                    .withParallelism(common.get_parallelism_hint()).withId(spoutComp);
            spoutBuilders.put(spoutComp, builder);
        }

        Map<String, Map<String, Double>> spoutResources = getSpoutsResources(topo, topoConf);
        for (Map.Entry<String, Map<String, Double>> entry : spoutResources.entrySet()) {
            LoadCompConf.Builder sd = spoutBuilders.get(entry.getKey());
            if (sd != null) {
                Map<String, Double> resources = entry.getValue();
                Double cpu = resources.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT);
                if (cpu != null) {
                    sd.withCpuLoad(cpu);
                }
                Double mem = resources.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB);
                if (mem != null) {
                    sd.withMemoryLoad(mem);
                }
            }
        }
    }

    //Stats...
    Map<String, List<ExecutorSummary>> byComponent = new HashMap<>();
    for (ExecutorSummary executor : info.get_executors()) {
        String component = executor.get_component_id();
        List<ExecutorSummary> list = byComponent.get(component);
        if (list == null) {
            list = new ArrayList<>();
            byComponent.put(component, list);
        }
        list.add(executor);
    }

    List<InputStream> streams = new ArrayList<>(inputStreams.size());
    //Compute the stats for the different input streams
    for (InputStream.Builder builder : inputStreams) {
        GlobalStreamId streamId = new GlobalStreamId(builder.getFromComponent(), builder.getId());
        List<ExecutorSummary> summaries = byComponent.get(builder.getToComponent());
        //Execute and process latency...
        builder.withProcessTime(
                new NormalDistStats(extractBoltValues(summaries, streamId, BoltStats::get_process_ms_avg)));
        builder.withExecTime(
                new NormalDistStats(extractBoltValues(summaries, streamId, BoltStats::get_execute_ms_avg)));
        //InputStream is done
        streams.add(builder.build());
    }

    //There is a bug in some versions that returns 0 for the uptime.
    // To work around it we should get it an alternative (working) way.
    Map<String, Integer> workerToUptime = new HashMap<>();
    for (WorkerSummary ws : tpinfo.get_workers()) {
        workerToUptime.put(ws.get_supervisor_id() + ":" + ws.get_port(), ws.get_uptime_secs());
    }
    LOG.debug("WORKER TO UPTIME {}", workerToUptime);

    for (Map.Entry<GlobalStreamId, OutputStream.Builder> entry : outStreams.entrySet()) {
        OutputStream.Builder builder = entry.getValue();
        GlobalStreamId id = entry.getKey();
        List<Double> emittedRate = new ArrayList<>();
        List<ExecutorSummary> summaries = byComponent.get(id.get_componentId());
        if (summaries != null) {
            for (ExecutorSummary summary : summaries) {
                if (summary.is_set_stats()) {
                    int uptime = summary.get_uptime_secs();
                    LOG.debug("UPTIME {}", uptime);
                    if (uptime <= 0) {
                        //Likely it is because of a bug, so try to get it another way
                        String key = summary.get_host() + ":" + summary.get_port();
                        uptime = workerToUptime.getOrDefault(key, 1);
                        LOG.debug("Getting uptime for worker {}, {}", key, uptime);
                    }
                    for (Map.Entry<String, Map<String, Long>> statEntry : summary.get_stats().get_emitted()
                            .entrySet()) {
                        String timeWindow = statEntry.getKey();
                        long timeSecs = uptime;
                        try {
                            timeSecs = Long.valueOf(timeWindow);
                        } catch (NumberFormatException e) {
                            //Ignored...
                        }
                        timeSecs = Math.min(timeSecs, uptime);
                        Long count = statEntry.getValue().get(id.get_streamId());
                        if (count != null) {
                            LOG.debug("{} emitted {} for {} secs or {} tuples/sec", id, count, timeSecs,
                                    count.doubleValue() / timeSecs);
                            emittedRate.add(count.doubleValue() / timeSecs);
                        }
                    }
                }
            }
        }
        builder.withRate(new NormalDistStats(emittedRate));

        //The OutputStream is done
        LoadCompConf.Builder comp = boltBuilders.get(id.get_componentId());
        if (comp == null) {
            comp = spoutBuilders.get(id.get_componentId());
        }
        comp.withStream(builder.build());
    }

    List<LoadCompConf> spouts = spoutBuilders.values().stream().map((b) -> b.build())
            .collect(Collectors.toList());

    List<LoadCompConf> bolts = boltBuilders.values().stream().map((b) -> b.build())
            .collect(Collectors.toList());

    return new TopologyLoadConf(topologyName, savedTopoConf, spouts, bolts, streams);
}

From source file:com.github.fge.jsonschema.syntax.checkers.draftv3.DraftV3PropertiesSyntaxChecker.java

@Override
protected void extraChecks(final ProcessingReport report, final SchemaTree tree) throws ProcessingException {
    final SortedMap<String, JsonNode> map = Maps.newTreeMap();
    map.putAll(JacksonUtils.asMap(tree.getNode().get(keyword)));

    String member;//from ww  w . jav  a 2s . c o  m
    JsonNode required;
    NodeType type;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        member = entry.getKey();
        required = entry.getValue().get("required");
        if (required == null)
            continue;
        type = NodeType.getNodeType(required);
        if (type != NodeType.BOOLEAN) {
            report.error(newMsg(tree, "draftv3PropertiesRequired").put("property", member)
                    .put("expected", NodeType.BOOLEAN).put("found", type));
        }
    }
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.DraftV3PropertiesSyntaxChecker.java

@Override
protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree)
        throws ProcessingException {
    final SortedMap<String, JsonNode> map = Maps.newTreeMap();
    map.putAll(JacksonUtils.asMap(tree.getNode().get(keyword)));

    String member;//ww  w .j ava2 s.  c om
    JsonNode required;
    NodeType type;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        member = entry.getKey();
        required = entry.getValue().get("required");
        if (required == null)
            continue;
        type = NodeType.getNodeType(required);
        if (type != NodeType.BOOLEAN) {
            report.error(newMsg(tree, bundle, "draftv3.properties.required.incorrectType")
                    .putArgument("property", member).putArgument("found", type)
                    .put("expected", NodeType.BOOLEAN));
        }
    }
}

From source file:io.appform.nautilus.funnel.administration.TenancyManager.java

private Map<String, String> readMappings(GetMappingsResponse response, ObjectCursor<String> index,
        String typeName) throws Exception {
    ImmutableMap.Builder<String, String> type = ImmutableMap.builder();
    MappingMetaData mappingData = response.mappings().get(index.value).get(typeName);
    JsonNode typeMeta = mapper.readTree(mappingData.source().toString()).get(typeName).get("properties");
    if (typeMeta.has(Constants.ATTRIBUTE_FIELD_NAME)) {
        JsonNode attributeMeta = typeMeta.get(Constants.ATTRIBUTE_FIELD_NAME);
        Iterator<Map.Entry<String, JsonNode>> elements = attributeMeta.get("properties").fields();
        while (elements.hasNext()) {
            Map.Entry<String, JsonNode> attribute = elements.next();
            type.put(attribute.getKey(), attribute.getValue().get("type").asText());
        }/* w ww .j a  v  a2 s.c o  m*/
    }
    return type.build();
}

From source file:de.bund.bfr.math.VectorFunction.java

@Override
public double[] value(double[] point) throws IllegalArgumentException {
    List<Double> result = new ArrayList<>();

    for (int i = 0; i < parameters.size(); i++) {
        parser.setVarValue(parameters.get(i), point[i]);
    }//ww w  .j  ava 2  s .  co m

    int n = variableValues.values().stream().findAny().get().size();

    for (int i = 0; i < n; i++) {
        for (Map.Entry<String, List<Double>> entry : variableValues.entrySet()) {
            parser.setVarValue(entry.getKey(), entry.getValue().get(i));
        }

        try {
            double value = parser.evaluate(function);

            result.add(Double.isFinite(value) ? value : Double.NaN);
        } catch (ParseException e) {
            e.printStackTrace();
            result.add(Double.NaN);
        }
    }

    return Doubles.toArray(result);
}

From source file:com.liferay.mobile.android.http.Response.java

public Map<String, String> getHeaders() {
    Map<String, List<String>> headers = _response.headers().toMultimap();

    Map<String, String> map = new HashMap<String, String>();

    for (Map.Entry<String, List<String>> header : headers.entrySet()) {
        map.put(header.getKey(), header.getValue().get(0));
    }//from   w  w w .  j a v a 2s.  c  o  m

    return Collections.unmodifiableMap(map);
}

From source file:com.microsoft.rest.serializer.HeadersSerializer.java

@Override
public void serialize(Headers value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    Map<String, Object> headers = new HashMap<String, Object>();
    for (Map.Entry<String, List<String>> entry : value.toMultimap().entrySet()) {
        if (entry.getValue() != null && entry.getValue().size() == 1) {
            headers.put(entry.getKey(), entry.getValue().get(0));
        } else if (entry.getValue() != null && entry.getValue().size() > 1) {
            headers.put(entry.getKey(), entry.getValue());
        }/*from  w ww  .j a  v  a 2 s.co m*/
    }
    jgen.writeObject(headers);
}

From source file:de.bund.bfr.math.LodFunction.java

@Override
public double value(double[] point) {
    double sd = Double.NaN;

    for (int ip = 0; ip < nParams; ip++) {
        if (parameters.get(ip).equals(sdParam)) {
            sd = Math.abs(point[ip]);
        } else {/*from w  ww. j  ava2 s.  com*/
            parser.setVarValue(parameters.get(ip), point[ip]);
        }
    }

    if (sd == 0.0) {
        return Double.NaN;
    }

    double logLikelihood = 0.0;

    for (int iv = 0; iv < nValues; iv++) {
        for (Map.Entry<String, List<Double>> entry : variableValues.entrySet()) {
            parser.setVarValue(entry.getKey(), entry.getValue().get(iv));
        }

        try {
            double value = parser.evaluate(function);

            if (!Double.isFinite(value)) {
                return Double.NaN;
            }

            NormalDistribution normDist = new NormalDistribution(value, sd);

            logLikelihood += targetValues.get(iv) > levelOfDetection
                    ? Math.log(normDist.density(targetValues.get(iv)))
                    : Math.log(normDist.cumulativeProbability(levelOfDetection));
        } catch (ParseException e) {
            e.printStackTrace();
            return Double.NaN;
        }
    }

    return logLikelihood;
}

From source file:org.onosproject.teyang.utils.topology.NodeConverter.java

private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributesnotification.TeNodeAttributes teNode2YangTeNodeAttributes(
        TeNode teNode) {/*from  w  w w  .ja  v a 2 s.  c o m*/

    org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributesnotification.TeNodeAttributes.TeNodeAttributesBuilder attrBuilder = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributesnotification.DefaultTeNodeAttributes
            .builder();

    if (teNode.connectivityMatrices() != null) {

        org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs.DefaultConnectivityMatrix.ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs.DefaultConnectivityMatrix
                .builder();
        for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : teNode.connectivityMatrices().entrySet()) {
            connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder.id(teCmEntry.getKey())
                    .isAllowed(!teCmEntry.getValue().flags().get(ConnectivityMatrix.BIT_DISALLOWED))
                    .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom.FromBuilder() // TODO: for now, assuming that there is
                            // only one 'from', and mergingList is empty
                            .tpRef(teCmEntry.getValue().from()).build())
                    .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultTo.ToBuilder() // TODO: for now, assuming that there is only
                            // one item in constrainingElements list
                            .tpRef(teCmEntry.getValue().constrainingElements().get(0)).build());
            attrBuilder = attrBuilder.addToConnectivityMatrix(connectivityMatrixConfigBuilder.build());
        }
    }

    org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.tenodeconfigattributesnotification.TeNodeAttributes teNodeAttributes = attrBuilder
            .build();

    return teNodeAttributes;
}

From source file:net.cazzar.gradle.curseforge.CurseUpload.java

public void game_version(String version) {
    for (Map.Entry<Integer, LinkedTreeMap<String, String>> entry : VersionInformation.get().entrySet()) {
        if (entry.getValue().get("name").equalsIgnoreCase(version)) {
            gameVersion = String.valueOf(entry.getKey());
            return;
        }/*  w w w.jav a  2s.c  o m*/
    }

    gameVersion = version;
}