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.wso2.carbon.governance.metadata.provider.version.GenericVersionProviderV1.java

private void createPropertiesContent(GenericVersionV1 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   www  . java 2 s .c o  m
    }

}

From source file:org.springframework.springfaces.mvc.internal.ModelBuilder.java

/**
 * Add model elements from a JSF parameters map. Only entries with a single parameter will be added to the model.
 * Parameters may contain String EL expressions that will be resolved as the model is built. NOTE: JSF Parameters
 * are often constructed from {@link UIParameter}s. Whenever possible call {@link #addFromComponent(UIComponent)} to
 * add {@link UIParameter}s before calling this method.
 * @param parameters the parameters to add or <tt>null</tt>
 *//* w ww  .  j a  v a  2s.  co  m*/
public void addFromParameterList(Map<String, List<String>> parameters) {
    if (parameters != null) {
        for (Map.Entry<String, List<String>> parameter : parameters.entrySet()) {
            if (parameter.getValue().size() == 1) {
                addIfNotInModel(parameter.getKey(), parameter.getKey(), parameter.getValue().get(0), true,
                        false);
            } else {
                if (this.logger.isWarnEnabled()) {
                    this.logger.warn("Unable to expose multi-value parameter '" + parameter.getKey()
                            + "' to bookmark model");
                }
            }
        }
    }
}

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

private void createPropertiesContent(ServiceVersionV1 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  www  . ja v a  2 s  . c o m
    }

}

From source file:com.neusoft.mid.clwapi.interceptor.OauthTokenCheckInterceptor.java

/**
 * token?./*from  w ww.j ava 2  s . c om*/
 * 
 * @param message
 */
@Override
public void handleMessage(Message message) throws Fault {
    logger.info("???");
    String token = "";
    boolean isExistToken = false;
    Response response = null;
    Map<String, List<String>> reqHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    if (reqHeaders != null) {
        for (Map.Entry<String, List<String>> e : reqHeaders.entrySet()) {
            if (ACCESS_TOKEN.equalsIgnoreCase(e.getKey())) {
                token = e.getValue().get(0);
                isExistToken = true;
            }
        }
    } else {
        logger.info("HTTP???HEADER?");
        response = Response.status(Response.Status.BAD_REQUEST).entity(ErrorConstant.ERROR10001.toJson())
                .header("Content-Type", "application/json;charset=UTF-8").build();
    }
    if (!isExistToken || StringUtils.isEmpty(StringUtils.strip(token))) {
        logger.info("HTTP?HEADER??\"access_token\"?");
        response = Response.status(Response.Status.BAD_REQUEST).entity(ErrorConstant.ERROR20000.toJson())
                .header("Content-Type", "application/json;charset=UTF-8").build();
    } else {
        logger.info("?access_token=" + token);
        if (checkToken(token)) {
            try {
                MobileUsrAllInfo userInfo = usrOauthService.getMblUsrInfoByToken(token);

                if (null == userInfo) {
                    logger.info("access_token?");
                    response = Response.status(Response.Status.UNAUTHORIZED)
                            .entity(ErrorConstant.ERROR20001.toJson())
                            .header("Content-Type", "application/json;charset=UTF-8").build();
                } else {
                    if ("0".equals(userInfo.getIsMobileAllow())) {
                        logger.info("?ID[" + userInfo.getEnterpriseId()
                                + "]?");
                        response = Response.status(297).entity(ErrorConstant.ERROR10107.toJson()).build();
                        oauthMapper.logoutUsrOauth(userInfo.getAccessToken(), userInfo.getUsrId());
                        logger.info("??");
                    } else if (userInfo.getValidSeconds() > 0) {
                        // token??HTTPHeader.
                        addUserInfo2HttpHeaderInfo(reqHeaders, userInfo);
                        message.put(Message.PROTOCOL_HEADERS, reqHeaders);
                    } else {
                        logger.info(
                                "access_token?,?");
                        response = Response.status(298).build();
                    }
                }
            } catch (Exception e) {
                logger.error("?token??", e);
                response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                        .entity(ErrorConstant.ERROR90000.toJson())
                        .header("Content-Type", "application/json;charset=UTF-8").build();
            }
        } else {
            logger.info("HTTP?HEADER\"access_token\"???");
            response = Response.status(Response.Status.BAD_REQUEST).entity(ErrorConstant.ERROR10002.toJson())
                    .header("Content-Type", "application/json;charset=UTF-8").build();
        }
    }
    message.getExchange().put(Response.class, response);
}

From source file:cc.kave.episodes.mining.evaluation.Evaluation.java

private void logSynthesized() {
    for (int p = 0; p < PROPOSALS; p++) {
        append("\tTop%d", (p + 1));
    }/*from   w w w .  ja va2 s  .  c o m*/
    append("\n");
    for (Map.Entry<Double, List<Tuple<Double, Double>>> entry : categoryResults.entrySet()) {
        if (entry.getValue().get(0).getFirst() == 0.0 || entry.getValue().get(0).getSecond() == 0.0) {
            continue;
        }
        append("Removed %.2f\t", (entry.getKey()));
        for (Tuple<Double, Double> pairs : entry.getValue()) {
            append("<%.2f, %.2f>\t", pairs.getFirst(), pairs.getSecond());
        }
        append("\n");
    }
}

From source file:com.datatorrent.contrib.enrich.POJOEnricher.java

@Override
protected Object convert(Object in, Object cached) {
    Object o;//from   ww  w. j a v  a 2 s . c  om

    try {
        o = outputClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        logger.error("Failed to create new instance of output POJO", e);
        errorTupleCount++;
        error.emit(in);
        return null;
    }

    try {
        for (Map.Entry<PojoUtils.Getter, PojoUtils.Setter> entry : fieldMap.entrySet()) {
            entry.getValue().set(o, entry.getKey().get(in));
        }
    } catch (RuntimeException e) {
        logger.error("Failed to set the property. Continuing with default.", e);
        errorTupleCount++;
        error.emit(in);
        return null;
    }

    if (cached == null) {
        return o;
    }

    ArrayList<Object> includeObjects = (ArrayList<Object>) cached;
    for (int i = 0; i < includeSetters.size(); i++) {
        try {
            includeSetters.get(i).set(o, includeObjects.get(i));
        } catch (RuntimeException e) {
            logger.error("Failed to set the property. Continuing with default.", e);
            errorTupleCount++;
            error.emit(in);
            return null;
        }
    }

    return o;
}

From source file:org.apache.camel.component.cxf.cxfbean.DefaultCxfBeanBinding.java

public void propagateResponseHeadersToCamel(Message cxfMessage, Exchange exchange,
        HeaderFilterStrategy strategy) {

    if (LOG.isTraceEnabled()) {
        LOG.trace("Propagating response headers from CXF message " + cxfMessage);
    }//from  w  w  w .  j a  va 2 s  .c  o m

    if (strategy == null) {
        return;
    }

    Map<String, Object> camelHeaders = exchange.getOut().getHeaders();

    Map<String, List<String>> cxfHeaders = CastUtils.cast((Map) cxfMessage.get(Message.PROTOCOL_HEADERS));

    if (cxfHeaders != null) {
        for (Map.Entry<String, List<String>> entry : cxfHeaders.entrySet()) {
            if (!strategy.applyFilterToExternalHeaders(entry.getKey(), entry.getValue(), exchange)) {
                camelHeaders.put(entry.getKey(), entry.getValue().get(0));

                if (LOG.isTraceEnabled()) {
                    LOG.trace(
                            "Populate header from CXF header=" + entry.getKey() + " value=" + entry.getValue());
                }
            }
        }
    }

    // propagate HTTP RESPONSE_CODE
    String key = Message.RESPONSE_CODE;
    Object value = cxfMessage.get(key);
    if (value != null && !strategy.applyFilterToExternalHeaders(key, value, exchange)) {
        camelHeaders.put(Exchange.HTTP_RESPONSE_CODE, value);
        if (LOG.isTraceEnabled()) {
            LOG.trace("Populate header from CXF header=" + key + " value=" + value + " as "
                    + Exchange.HTTP_RESPONSE_CODE);
        }
    }

    // propagate HTTP CONTENT_TYPE
    if (cxfMessage.get(Message.CONTENT_TYPE) != null) {
        camelHeaders.put(Exchange.CONTENT_TYPE, cxfMessage.get(Message.CONTENT_TYPE));
    }
}

From source file:org.apache.carbondata.processing.util.CarbonLoaderUtilTest.java

@Test
public void testNodeBlockMappingByDataSize() throws Exception {
    List<Distributable> blockInfos = generateBlocks();
    List<String> activeNodes = generateExecutors();

    // the blocks are assigned by size, so the number of block for each node are different
    Map<String, List<Distributable>> nodeMappingBySize = CarbonLoaderUtil.nodeBlockMapping(blockInfos, -1,
            activeNodes, CarbonLoaderUtil.BlockAssignmentStrategy.BLOCK_SIZE_FIRST, null);
    LOGGER.info(convertMapListAsString(nodeMappingBySize));
    Assert.assertEquals(3, nodeMappingBySize.size());
    for (Map.Entry<String, List<Distributable>> entry : nodeMappingBySize.entrySet()) {
        if (entry.getValue().size() == 1) {
            // only contains the biggest block
            Assert.assertEquals(40 * 1024 * 1024L, ((TableBlockInfo) entry.getValue().get(0)).getBlockLength());
        } else {/*  w w w.j  a v a  2  s . c  om*/
            Assert.assertTrue(entry.getValue().size() > 1);
        }
    }

    // the blocks are assigned by number, so the number of blocks for each node are nearly the same
    Map<String, List<Distributable>> nodeMappingByNum = CarbonLoaderUtil.nodeBlockMapping(blockInfos, -1,
            activeNodes, CarbonLoaderUtil.BlockAssignmentStrategy.BLOCK_NUM_FIRST, null);
    LOGGER.info(convertMapListAsString(nodeMappingByNum));
    Assert.assertEquals(3, nodeMappingBySize.size());
    for (Map.Entry<String, List<Distributable>> entry : nodeMappingByNum.entrySet()) {
        Assert.assertTrue(entry.getValue().size() == blockInfos.size() / 3
                || entry.getValue().size() == blockInfos.size() / 3 + 1);
    }
}

From source file:com.mastfrog.acteur.server.EventImpl.java

@Override
public synchronized Map<String, String> getParametersAsMap() {
    if (paramsMap == null) {
        QueryStringDecoder queryStringDecoder = new QueryStringDecoder(req.getUri());
        Map<String, List<String>> params = queryStringDecoder.parameters();
        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, List<String>> e : params.entrySet()) {
            if (e.getValue().isEmpty()) {
                continue;
            }//ww  w .j  av a 2s .  c o  m
            result.put(e.getKey(), e.getValue().get(0));
        }
        paramsMap = ImmutableSortedMap.copyOf(result);
    }
    return paramsMap;
}

From source file:cn.cnic.bigdatalab.flume.sink.mongodb.MappingDefinition.java

private void populateMappedFromField(Map.Entry<String, JsonNode> entry, SimpleFieldDefinition fieldDefinition) {
    if (fieldDefinition.getType().equals(MongoDataType.BINARY) && entry.getValue().has(ENCODING)) {
        fieldDefinition.setEncoding(entry.getValue().get(ENCODING).asText());
    }/*w  w  w  . j  a v  a  2s . c  om*/
    if (entry.getValue().has(MAPPED_FROM)) {
        fieldDefinition.setFieldName(entry.getValue().get(MAPPED_FROM).asText());
        fieldDefinition.setMappedName(entry.getKey());
    }
}