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:ch.entwine.weblounge.common.impl.site.ActionPoolFactory.java

/**
 * {@inheritDoc}/* w  w  w .jav a2 s .co  m*/
 * 
 * @see org.apache.commons.pool.BasePoolableObjectFactory#makeObject()
 */
@Override
public Action makeObject() throws Exception {
    logger.debug("Creating new action '{}'", blueprint.getIdentifier());

    Action action = blueprint.getClass().newInstance();

    // Module
    action.setModule(blueprint.getModule());

    // Site
    action.setSite(blueprint.getSite());

    // Identifier
    action.setIdentifier(blueprint.getIdentifier());

    // Path
    action.setPath(blueprint.getPath());

    // Includes
    for (HTMLHeadElement header : blueprint.getHTMLHeaders()) {
        action.addHTMLHeader(header);
    }

    // Options
    for (Map.Entry<String, Map<Environment, List<String>>> option : blueprint.getOptions().entrySet()) {
        for (Environment environment : option.getValue().keySet()) {
            List<String> values = option.getValue().get(environment);
            for (String value : values) {
                action.setOption(option.getKey(), value, environment);
            }
        }
    }

    // Recheck time
    action.setClientRevalidationTime(blueprint.getClientRevalidationTime());

    // Valid time
    action.setCacheExpirationTime(blueprint.getCacheExpirationTime());

    // Are we looking at an html action?
    if (blueprint instanceof HTMLAction) {
        HTMLAction htmlBlueprint = (HTMLAction) blueprint;
        HTMLAction htmlAction = (HTMLAction) action;

        // Page URI
        if (htmlBlueprint.getPageURI() != null) {
            ResourceURI uri = htmlBlueprint.getPageURI();
            htmlAction.setPageURI(new PageURIImpl(uri.getSite(), uri.getPath()));
        }

        // Default page template
        htmlAction.setDefaultTemplate(htmlBlueprint.getDefaultTemplate());
    }

    // Name
    action.setName(blueprint.getName());

    return action;
}

From source file:org.wso2.carbon.governance.metadata.provider.GenericMetadataProviderV1.java

private void createPropertiesContent(GenericMetadata serviceV1, OMElement element) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    for (Map.Entry<String, List<String>> entry : serviceV1.getPropertyBag().entrySet()) {
        if (entry.getValue() == null)
            continue;
        OMElement attribute = factory.createOMElement(new QName(entry.getKey()));
        attribute.setText(entry.getValue().get(0));
        element.addChild(attribute);/*from  ww w  . ja v  a  2 s . c  om*/
    }

}

From source file:org.wisdom.framework.mustache.MustacheTemplate.java

/**
 * Renders the template./* ww w  .  j av  a  2 s  .  c om*/
 *
 * @param controller the controller having requested the rendering.
 * @param variables  the parameters
 * @return the rendered object.
 */
@Override
public Renderable render(Controller controller, Map<String, Object> variables) {

    // Check whether we already have compiled the template.
    // To support partials, we do that at the last minute.
    if (compiled == null) {
        compile();
    }

    Map<String, Object> context = new HashMap<>();

    // If we have a HTTP context, extract data.
    Context ctx = org.wisdom.api.http.Context.CONTEXT.get();
    if (ctx != null) {
        // The order is important:
        // 1) session
        context.putAll(ctx.session().getData());

        // 2) current flash and then ongoing flash
        context.putAll(ctx.flash().getCurrentFlashCookieData());
        context.putAll(ctx.flash().getOutgoingFlashCookieData());

        // 3) the parameters.
        for (Map.Entry<String, List<String>> entry : ctx.parameters().entrySet()) {
            if (entry.getValue().size() == 1) {
                context.put(entry.getKey(), entry.getValue().get(0));
            } else {
                context.put(entry.getKey(), entry.getValue());
            }
        }

        // 4) request scope
        for (Map.Entry<String, Object> entry : ctx.request().data().entrySet()) {
            context.put(entry.getKey(), entry.getValue());
        }
    }

    // 4) the variables given by the controller.
    context.putAll(variables);

    StringWriter writer = new StringWriter();
    compiled.execute(writer, context);
    return new RenderableString(writer.toString(), mimetype());
}

From source file:org.wso2.carbon.governance.metadata.provider.HTTPServiceProviderV1.java

private void createPropertiesContent(HTTPServiceV1 serviceV1, OMElement element) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    for (Map.Entry<String, List<String>> entry : serviceV1.getPropertyBag().entrySet()) {
        if (entry.getValue() == null)
            continue;
        OMElement attribute = factory.createOMElement(new QName(entry.getKey()));
        attribute.setText(entry.getValue().get(0));
        element.addChild(attribute);//from w w  w.  j  a  va2 s .  c om
    }

}

From source file:org.apache.marmotta.client.clients.ConfigurationClient.java

/**
 * Return a list of all configurations (keys and values) that are currently set in the Marmotta configuration.
 * @return/*  w  w w.j a va2  s.co  m*/
 * @throws IOException
 * @throws MarmottaClientException
 */
public Set<Configuration> listConfigurations(String prefix) throws IOException, MarmottaClientException {
    HttpClient httpClient = HTTPUtil.createClient(config);

    String serviceUrl = config.getMarmottaUri() + URL_CONFIG_SERVICE + "/list"
            + (prefix != null ? "?prefix=" + URLEncoder.encode(prefix, "utf-8") : "");

    HttpGet get = new HttpGet(serviceUrl);
    get.setHeader("Accept", "application/json");

    try {

        HttpResponse response = httpClient.execute(get);

        switch (response.getStatusLine().getStatusCode()) {
        case 200:
            log.debug("configurations listed successfully");
            ObjectMapper mapper = new ObjectMapper();
            Map<String, Map<String, Object>> resultMap = mapper.readValue(response.getEntity().getContent(),
                    new TypeReference<Map<String, Map<String, Object>>>() {
                    });

            Set<Configuration> result = new HashSet<Configuration>();
            for (Map.Entry<String, Map<String, Object>> entry : resultMap.entrySet()) {
                result.add(new Configuration(entry.getKey(), entry.getValue().get("value")));
            }
            return result;
        default:
            log.error("error retrieving list of configuration keys: {} {}", new Object[] {
                    response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase() });
            throw new MarmottaClientException(
                    "error retrieving list of configuration keys: " + response.getStatusLine().getStatusCode()
                            + " " + response.getStatusLine().getReasonPhrase());
        }

    } finally {
        get.releaseConnection();
    }
}

From source file:org.wso2.carbon.governance.metadata.provider.HTTPEndpointProviderV1.java

private void createPropertiesContent(HTTPEndpointV1 httpEndpointV1, OMElement element) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    for (Map.Entry<String, List<String>> entry : httpEndpointV1.getPropertyBag().entrySet()) {
        if (entry.getValue() == null)
            continue;
        OMElement attribute = factory.createOMElement(new QName(entry.getKey()));
        attribute.setText(entry.getValue().get(0));
        element.addChild(attribute);/*from w w w .j  a v a2 s  . c  om*/
    }

}

From source file:com.thoughtworks.go.server.service.dd.reporting.ReportingDependencyFanInNode.java

private void addToRevisionQueue(PipelineTimelineEntry entry,
        Queue<PipelineTimelineEntry.Revision> revisionQueue, List<ReportingFaninScmMaterial> scmMaterials,
        ReportingFanInGraphContext context) {
    printPipelineTimelineEntry(entry, context);

    for (Map.Entry<String, List<PipelineTimelineEntry.Revision>> revisionList : entry.revisions().entrySet()) {
        String fingerprint = revisionList.getKey();
        PipelineTimelineEntry.Revision revision = revisionList.getValue().get(0);
        if (isScmMaterial(fingerprint, context)) {
            scmMaterials.add(new ReportingFaninScmMaterial(fingerprint, revision));
            continue;
        }/*from  ww  w . j a v  a 2 s  . c o  m*/

        if (isDependencyMaterial(fingerprint, context)) {
            revisionQueue.add(revision);
        }
    }
}

From source file:org.springframework.integration.stomp.support.StompHeaderMapper.java

@Override
@SuppressWarnings("unchecked")
public void fromHeaders(MessageHeaders headers, StompHeaders target) {
    for (Map.Entry<String, Object> entry : headers.entrySet()) {
        String name = entry.getKey();
        if (shouldMapHeader(name, this.outboundHeaderNames)) {
            Object value = entry.getValue();
            if (value != null) {
                setStompHeader(target, name, value);
            }//w  ww . j av  a 2  s.co  m
        } else if (StompHeaderAccessor.NATIVE_HEADERS.equals(name)) {
            MultiValueMap<String, String> multiValueMap = headers.get(StompHeaderAccessor.NATIVE_HEADERS,
                    MultiValueMap.class);
            for (Map.Entry<String, List<String>> entry1 : multiValueMap.entrySet()) {
                name = entry1.getKey();
                if (shouldMapHeader(name, this.outboundHeaderNames)) {
                    String value = entry1.getValue().get(0);
                    if (StringUtils.hasText(value)) {
                        setStompHeader(target, name, value);
                    }
                }
            }
        }
    }
}

From source file:org.apache.ambari.view.slider.rest.client.AmbariHttpClient.java

public AmbariCluster getCluster(AmbariClusterInfo clusterInfo) {
    if (clusterInfo != null) {
        try {//w  w w . ja v  a  2  s  . co  m
            JsonElement jsonElement = doGetJson("/api/v1/clusters/" + clusterInfo.getName()
                    + "?fields=services/ServiceInfo,hosts,Clusters");
            if (jsonElement != null) {
                AmbariCluster cluster = new AmbariCluster();
                // desired configs
                Map<String, String> desiredConfigs = new HashMap<String, String>();
                JsonObject jsonObject = jsonElement.getAsJsonObject();
                JsonObject clustersJsonObject = jsonObject.get("Clusters").getAsJsonObject();
                JsonObject desiredConfigsObj = clustersJsonObject.get("desired_configs").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : desiredConfigsObj.entrySet()) {
                    desiredConfigs.put(entry.getKey(),
                            entry.getValue().getAsJsonObject().get("tag").getAsString());
                }
                cluster.setDesiredConfigs(desiredConfigs);
                cluster.setName(clustersJsonObject.get("cluster_name").getAsString());
                cluster.setVersion(clustersJsonObject.get("version").getAsString());
                // services
                List<AmbariServiceInfo> services = new ArrayList<AmbariServiceInfo>();
                for (JsonElement svcJson : jsonObject.get("services").getAsJsonArray()) {
                    AmbariServiceInfo si = new AmbariServiceInfo();
                    si.setId(svcJson.getAsJsonObject().get("ServiceInfo").getAsJsonObject().get("service_name")
                            .getAsString());
                    si.setStarted("STARTED".equals(svcJson.getAsJsonObject().get("ServiceInfo")
                            .getAsJsonObject().get("state").getAsString()));
                    services.add(si);
                }
                cluster.setServices(services);
                // hosts
                List<AmbariHostInfo> hosts = new ArrayList<AmbariHostInfo>();
                for (JsonElement hostJson : jsonObject.get("hosts").getAsJsonArray()) {
                    AmbariHostInfo hi = new AmbariHostInfo();
                    hi.setHostName(hostJson.getAsJsonObject().get("Hosts").getAsJsonObject().get("host_name")
                            .getAsString());
                    hosts.add(hi);
                }
                cluster.setHosts(hosts);
                return cluster;
            }
        } catch (IllegalStateException e) {
            logger.warn("Unable to determine Ambari cluster details - " + clusterInfo.getName(), e);
            throw new RuntimeException(e.getMessage(), e);
        } catch (HttpException e) {
            logger.warn("Unable to determine Ambari cluster details - " + clusterInfo.getName(), e);
            throw createRuntimeException(e);
        } catch (IOException e) {
            logger.warn("Unable to determine Ambari cluster details - " + clusterInfo.getName(), e);
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.granitemc.granite.utils.Mappings.java

public static void load() {
    try {/*from   w  ww  .  jav a2  s  .  c  om*/
        File mappingsFile = new File(Granite.getServerConfig().getMappingsFile().getAbsolutePath());

        String url = "https://raw.githubusercontent.com/GraniteTeam/GraniteMappings/master/1.8.1.json";

        if (Granite.getServerConfig().getAutomaticMappingsUpdating()) {
            Granite.getLogger().info("Querying " + url + " for updates");
            HttpRequest req = HttpRequest.get(url);
            if (!mappingsFile.exists()
                    || !Objects.equals(req.eTag(), Granite.getServerConfig().getLatestMappingsEtag())) {
                Granite.getLogger().info("Could not find mappings.json (or etag didn't match)");
                Granite.getLogger().info("Downloading from " + url);

                if (req.code() == 404) {
                    throw new RuntimeException(
                            "Cannot find mappings file on either the local system or on GitHub. Try placing a mappings.json file in the root server directory.");
                } else if (req.code() == 200) {
                    req.receive(mappingsFile);
                    ((GraniteServerConfig) Granite.getServerConfig()).file.put("latest-mappings-etag",
                            req.eTag());
                    ((GraniteServerConfig) Granite.getServerConfig()).file.save();
                }
            }
        }

        file = ConfigFactory.parseReader(new InputStreamReader(new FileInputStream(mappingsFile)),
                ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON));
    } catch (java.io.IOException e) {
        e.printStackTrace();
    }

    classes = HashBiMap.create();
    ctClasses = HashBiMap.create();

    methods = new HashMap<>();
    ctMethods = new HashMap<>();

    fields = new HashMap<>();
    ctFields = new HashMap<>();

    pool = new ClassPool(true);

    try {
        for (Map.Entry<String, ConfigValue> classObject : file.getObject("classes").entrySet()) {
            String className = (String) ((ConfigObject) classObject.getValue()).get("name").unwrapped();
            ctClasses.put(classObject.getKey(), pool.get(className));
            ctClasses.put(classObject.getKey() + "[]", pool.get(className + "[]"));
        }

        for (Map.Entry<String, CtClass> entry : ctClasses.entrySet()) {
            CtClass ctClass = entry.getValue();
            if (!entry.getKey().endsWith("[]")) {
                ConfigObject classObject = file
                        .getObject("classes." + entry.getKey().replaceAll("\\$", "\"\\$\""));

                methods.put(ctClass, HashBiMap.<String, MethodHandle>create());
                ctMethods.put(ctClass, HashBiMap.<String, CtMethod>create());

                if (classObject.containsKey("methods")) {
                    for (Map.Entry<String, ConfigValue> methodEntry : ((ConfigObject) classObject
                            .get("methods")).entrySet()) {
                        String methodSignature = methodEntry.getKey();
                        String methodName = (String) methodEntry.getValue().unwrapped();

                        SignatureParser.MethodSignature obfSig = SignatureParser.parseJvm(methodSignature);

                        /*MethodHandle mh = null;
                        try {
                        mh = MethodHandles.lookup().findVirtual(clazz.getValue(), methodSignature.split("\\(")[0], MethodType.methodType(obfSig.getReturnType(), obfSig.getParamTypes()));
                        } catch (NoSuchMethodException | IllegalAccessException e) {
                        if (e.getMessage().startsWith("no such method")) {
                            try {
                                Method m = clazz.getValue().getDeclaredMethod(methodSignature.split("\\(")[0], obfSig.getParamTypes());
                                m.setAccessible(true);
                                mh = MethodHandles.lookup().unreflect(m);
                            } catch (NoSuchMethodException | IllegalAccessException e1) {
                                e1.printStackTrace();
                            }
                        }
                        }
                                
                        if (mh == null) {
                        mh = mh;
                        }*/

                        CtMethod method = ctClass.getMethod(methodSignature.split("\\(")[0],
                                "(" + methodSignature.split("\\(")[1]);
                        ctMethods.get(method.getDeclaringClass()).put(methodName, method);
                    }
                }

                fields.put(ctClass, HashBiMap.<String, Field>create());
                ctFields.put(ctClass, HashBiMap.<String, CtField>create());

                if (classObject.containsKey("fields")) {
                    for (Map.Entry<String, ConfigValue> fieldEntry : ((ConfigObject) classObject.get("fields"))
                            .entrySet()) {
                        String obfuscatedFieldName = fieldEntry.getKey();
                        String fieldName = (String) fieldEntry.getValue().unwrapped();

                        ctFields.get(ctClass).put(fieldName, ctClass.getDeclaredField(obfuscatedFieldName));
                    }
                }
            }
        }
    } catch (NotFoundException e) {
        e.printStackTrace();
    }
}