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.opendaylight.controller.topology.web.Topology.java

/**
 * Re-position nodes in circular layout/*from w  ww.j a v a  2 s.c o m*/
 */
private void repositionTopology(String containerName) {
    Graph<String, String> graph = new SparseMultigraph<String, String>();

    metaCache.get(containerName).clear();
    metaCache.get(containerName).putAll(stagedNodes);
    metaCache.get(containerName).putAll(newNodes);

    for (Map<String, Object> on : metaCache.get(containerName).values()) {
        graph.addVertex(on.toString());

        List<Map<String, Object>> adjacencies = (List<Map<String, Object>>) on.get("adjacencies");

        for (Map<String, Object> adj : adjacencies) {
            graph.addEdge(adj.toString(), adj.get("nodeFrom").toString(), adj.get("nodeTo").toString());
        }
    }

    CircleLayout<String, String> layout = new CircleLayout<String, String>(graph);
    layout.setSize(new Dimension(1200, 365));
    for (Map.Entry<String, Map<String, Object>> v : newNodes.entrySet()) {
        Double x = layout.transform(v.getKey()).getX();
        Double y = layout.transform(v.getKey()).getY();

        Map<String, String> nodeData = (HashMap<String, String>) v.getValue().get("data");
        nodeData.put("$x", (x - 600) + "");
        nodeData.put("$y", (y - 225) + "");

        newNodes.get(v.getKey()).put("data", nodeData);
    }
}

From source file:org.openecomp.sdc.validation.impl.validators.EcompGuideLineValidator.java

private void checkIfNovaNameByGuidelines(String fileName, String envFileName,
        Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
    if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
        return;//from w  w w . ja  v  a2s  .  c o  m
    }

    Object novaServerName = resourceEntry.getValue().getProperties().get("name");
    Map novaNameMap;
    String novaName;
    if (Objects.nonNull(novaServerName)) {
        if (novaServerName instanceof Map) {
            novaNameMap = (Map) novaServerName;
            Object novaNameGetParam = novaNameMap
                    .get(ResourceReferenceFunctions.GET_PARAM.getFunction()) == null ? null
                            : novaNameMap.get(ResourceReferenceFunctions.GET_PARAM.getFunction());
            if (Objects.nonNull(novaNameGetParam)) {
                checkNovaNameGetParamValueMap(fileName, novaNameGetParam, resourceEntry, globalContext);
                novaName = novaNameGetParam instanceof List ? (String) ((List) novaNameGetParam).get(0)
                        : (String) novaNameGetParam;
                checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, resourceEntry, novaName,
                        globalContext);
            }
        } else {
            globalContext.addMessage(fileName, ErrorLevel.WARNING,
                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                            Messages.MISSING_GET_PARAM.getErrorMessage(), "nova server name",
                            resourceEntry.getKey()));
        }
    }

}

From source file:org.sleuthkit.autopsy.casemodule.Case.java

static Map<Long, String> getImagePaths(SleuthkitCase db) { //TODO: clean this up
    Map<Long, String> imgPaths = new HashMap<>();
    try {/*from  www  .java2 s  .  com*/
        Map<Long, List<String>> imgPathsList = db.getImagePaths();
        for (Map.Entry<Long, List<String>> entry : imgPathsList.entrySet()) {
            if (entry.getValue().size() > 0) {
                imgPaths.put(entry.getKey(), entry.getValue().get(0));
            }
        }
    } catch (TskException ex) {
        logger.log(Level.WARNING, "Error getting image paths", ex); //NON-NLS
    }
    return imgPaths;
}

From source file:org.openanzo.datasource.nodecentric.internal.NodeCentricDatasourceFactory.java

@Override
public String getExtraStatus(boolean html) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    if (html) {/*from w w  w  .j  a  v  a  2  s .  c  o  m*/
        if (datasources.size() > 0) {
            pw.println("<h4><font color='#00cc00'>NodeCentric Datasources:</font></h4>");
            for (NodeCentricDatasource ds : datasources.values()) {
                try {
                    pw.println("<li>" + URLDecoder.decode(ds.getName(), "UTF-8") + "</li>");
                } catch (UnsupportedEncodingException e) {
                    log.error(LogUtils.INTERNAL_MARKER,
                            "Should never happen since UTF-8 must be supported by all JVMs on all platforms.",
                            e);
                }
                pw.println("<br/>Configuration Properties: ");
                pw.println("<table border='1'>");
                for (Enumeration<? extends Object> keys = ds.getConfigurationParameters().keys(); keys
                        .hasMoreElements();) {
                    Object key = keys.nextElement();
                    Object value = ds.getConfigurationParameters().get(key);
                    if (key.toString().toLowerCase().contains("password")
                            && value.toString().startsWith("encrypted:")) {
                        value = "********";
                    }
                    pw.println("<tr><td>" + key.toString() + "</td><td>" + value.toString() + "</td></tr>");
                }
                pw.println("</table>");
            }
        }
        if (initializingDatasource.size() > 0) {
            pw.println("<h4><font color='#FFFF00'>NodeCentric Datasources Starting:</font></h4>");
            for (Map.Entry<String, Dictionary<? extends Object, ? extends Object>> entry : initializingDatasource
                    .entrySet()) {
                pw.println("<li>" + entry.getKey() + "</li>");
                pw.println("<br/>Configuration Properties: ");
                pw.println("<table border='1'>");
                for (Enumeration<? extends Object> keys = entry.getValue().keys(); keys.hasMoreElements();) {
                    Object key = keys.nextElement();
                    Object value = entry.getValue().get(key);
                    pw.println("<tr><td>" + key.toString() + "</td><td>" + value.toString() + "</td></tr>");
                }
                pw.println("</table>");
            }

        }
    } else {
        if (datasources.size() > 0) {
            pw.println("NodeCentric Datasources:");
            for (NodeCentricDatasource ds : datasources.values()) {
                try {
                    pw.println(URLDecoder.decode(ds.getName(), "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    log.error(LogUtils.INTERNAL_MARKER,
                            "Should never happen since UTF-8 must be supported by all JVMs on all platforms.",
                            e);
                }
            }
        }
        if (initializingDatasource.size() > 0) {
            pw.println("NodeCentric Datasources Starting:");
            for (Map.Entry<String, Dictionary<? extends Object, ? extends Object>> entry : initializingDatasource
                    .entrySet()) {
                pw.println(entry.getKey());
            }
        }
    }
    pw.flush();
    sw.flush();
    return sw.toString();
}

From source file:org.apache.cxf.jaxrs.swagger.Swagger2Serializers.java

@Override
public void writeTo(final Swagger data, final Class<?> type, final Type genericType,
        final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> headers,
        final OutputStream out) throws IOException {

    if (dynamicBasePath) {
        MessageContext ctx = JAXRSUtils.createContextValue(JAXRSUtils.getCurrentMessage(), null,
                MessageContext.class);
        data.setBasePath(StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/"));
    }/*from w  w w.  j  a  va2 s. c om*/

    if (replaceTags || javadocProvider != null) {
        Map<String, ClassResourceInfo> operations = new HashMap<>();
        Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
        for (ClassResourceInfo cri : cris) {
            for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
                String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(),
                        ori.getURITemplate().getValue());

                operations.put(normalizedPath, cri);
                methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori);
            }
        }

        if (replaceTags && data.getTags() != null) {
            data.getTags().clear();
        }
        for (final Map.Entry<String, Path> entry : data.getPaths().entrySet()) {
            Tag tag = null;
            if (replaceTags && operations.containsKey(entry.getKey())) {
                ClassResourceInfo cri = operations.get(entry.getKey());

                tag = new Tag();
                tag.setName(cri.getURITemplate().getValue());
                if (javadocProvider != null) {
                    tag.setDescription(javadocProvider.getClassDoc(cri));
                }

                data.addTag(tag);
            }

            for (Map.Entry<HttpMethod, Operation> subentry : entry.getValue().getOperationMap().entrySet()) {
                if (replaceTags && tag != null) {
                    subentry.getValue().setTags(Collections.singletonList(tag.getName()));
                }

                Pair<String, String> key = ImmutablePair.of(subentry.getKey().name(), entry.getKey());
                if (methods.containsKey(key) && javadocProvider != null) {
                    OperationResourceInfo ori = methods.get(key);

                    subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
                    for (int i = 0; i < subentry.getValue().getParameters().size(); i++) {
                        subentry.getValue().getParameters().get(i)
                                .setDescription(javadocProvider.getMethodParameterDoc(ori, i));
                    }

                    if (subentry.getValue().getResponses() != null
                            && !subentry.getValue().getResponses().isEmpty()) {

                        subentry.getValue().getResponses().entrySet().iterator().next().getValue()
                                .setDescription(javadocProvider.getMethodResponseDoc(ori));
                    }
                }
            }
        }
    }

    super.writeTo(data, type, genericType, annotations, mediaType, headers, out);
}

From source file:org.apache.camel.component.cxf.DefaultCxfBinding.java

/**
 * @param cxfMessage//from w  w w  .  j  a  va2  s.  co  m
 * @param camelMessage
 * @param exchange provides context for filtering
 */
@SuppressWarnings("unchecked")
protected void propagateHeadersFromCxfToCamel(Message cxfMessage, org.apache.camel.Message camelMessage,
        Exchange exchange) {
    Map<String, List<String>> cxfHeaders = (Map) cxfMessage.get(Message.PROTOCOL_HEADERS);
    Map<String, Object> camelHeaders = camelMessage.getHeaders();
    camelHeaders.put(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage);

    if (cxfHeaders != null) {
        for (Map.Entry<String, List<String>> entry : cxfHeaders.entrySet()) {
            if (!headerFilterStrategy.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 SOAP/protocol header list
    String key = Header.HEADER_LIST;
    Object value = cxfMessage.get(key);
    if (value != null) {
        if (!headerFilterStrategy.applyFilterToExternalHeaders(key, value, exchange)) {
            camelHeaders.put(key, value);
            if (LOG.isTraceEnabled()) {
                LOG.trace("Populate header from CXF header=" + key + " value=" + value);
            }
        } else {
            ((List<?>) value).clear();
        }
    }
}

From source file:org.apache.hadoop.hbase.client.coprocessor.AggregationClient.java

/**
 * This is the client side interface/handler for calling the median method for a
 * given cf-cq combination. This method collects the necessary parameters
 * to compute the median and returns the median.
 * @param table//from  ww  w.  java 2  s  . c  o  m
 * @param ci
 * @param scan
 * @return R the median
 * @throws Throwable
 */
public <R, S, P extends Message, Q extends Message, T extends Message> R median(final HTable table,
        ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) throws Throwable {
    Pair<NavigableMap<byte[], List<S>>, List<S>> p = getMedianArgs(table, ci, scan);
    byte[] startRow = null;
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> quals = scan.getFamilyMap().get(colFamily);
    NavigableMap<byte[], List<S>> map = p.getFirst();
    S sumVal = p.getSecond().get(0);
    S sumWeights = p.getSecond().get(1);
    double halfSumVal = ci.divideForAvg(sumVal, 2L);
    double movingSumVal = 0;
    boolean weighted = false;
    if (quals.size() > 1) {
        weighted = true;
        halfSumVal = ci.divideForAvg(sumWeights, 2L);
    }

    for (Map.Entry<byte[], List<S>> entry : map.entrySet()) {
        S s = weighted ? entry.getValue().get(1) : entry.getValue().get(0);
        double newSumVal = movingSumVal + ci.divideForAvg(s, 1L);
        if (newSumVal > halfSumVal)
            break; // we found the region with the median
        movingSumVal = newSumVal;
        startRow = entry.getKey();
    }
    // scan the region with median and find it
    Scan scan2 = new Scan(scan);
    // inherit stop row from method parameter
    if (startRow != null)
        scan2.setStartRow(startRow);
    ResultScanner scanner = null;
    try {
        int cacheSize = scan2.getCaching();
        if (!scan2.getCacheBlocks() || scan2.getCaching() < 2) {
            scan2.setCacheBlocks(true);
            cacheSize = 5;
            scan2.setCaching(cacheSize);
        }
        scanner = table.getScanner(scan2);
        Result[] results = null;
        byte[] qualifier = quals.pollFirst();
        // qualifier for the weight column
        byte[] weightQualifier = weighted ? quals.pollLast() : qualifier;
        R value = null;
        do {
            results = scanner.next(cacheSize);
            if (results != null && results.length > 0) {
                for (int i = 0; i < results.length; i++) {
                    Result r = results[i];
                    // retrieve weight
                    Cell kv = r.getColumnLatest(colFamily, weightQualifier);
                    R newValue = ci.getValue(colFamily, weightQualifier, kv);
                    S s = ci.castToReturnType(newValue);
                    double newSumVal = movingSumVal + ci.divideForAvg(s, 1L);
                    // see if we have moved past the median
                    if (newSumVal > halfSumVal) {
                        return value;
                    }
                    movingSumVal = newSumVal;
                    kv = r.getColumnLatest(colFamily, qualifier);
                    value = ci.getValue(colFamily, qualifier, kv);
                }
            }
        } while (results != null && results.length > 0);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
    return null;
}

From source file:org.wso2.carbon.governance.rest.api.Asset.java

private String createQuery(UriInfo uriInfo) {
    StringBuilder builder = new StringBuilder("");
    MultivaluedMap<String, String> queryParam = uriInfo.getQueryParameters();
    Util.excludePaginationParameters(queryParam);
    Iterator<Map.Entry<String, List<String>>> iterator = queryParam.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, List<String>> entry = iterator.next();
        String value = entry.getValue().get(0);
        if (value != null && !"tenant".equals(entry.getKey())) {
            builder.append(entry.getKey() + "=" + value);
        }/* ww  w.  j  a v a 2 s  . c o m*/
        if (iterator.hasNext()) {
            builder.append("&");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Query : " + builder.toString());
    }
    return builder.toString();
}

From source file:it.unibas.spicy.persistence.csv.DAOCsv.java

@SuppressWarnings("unchecked")
public void loadInstanceSample(IDataSourceProxy dataSource, HashMap<String, ArrayList<Object>> strfullPath,
        String catalog) throws DAOException {
    INode root = null;//from   www.  jav a 2  s  .  c om
    try {
        HashMap<String, ArrayList<Object>> instanceInfoList = (HashMap<String, ArrayList<Object>>) dataSource
                .getAnnotation(SpicyEngineConstants.CSV_INSTANCES_INFO_LIST);
        root = new TupleNode(getNode(catalog).getLabel(), getOID());
        root.setRoot(true);
        for (Map.Entry<String, ArrayList<Object>> entry : strfullPath.entrySet()) {
            String filePath = entry.getKey();
            //the list entry.getValue() contains a)the table name 
            //b)a boolean that contains the info if the instance file includes column names             
            String tableName = (String) entry.getValue().get(0);
            boolean colNames = (Boolean) entry.getValue().get(1);

            SetNode setTable = new SetNode(getNode(tableName).getLabel(), getOID());
            if (logger.isDebugEnabled())
                logger.debug("extracting value for table " + tableName + " ....");

            getInstanceByTable(tableName, setTable, filePath, colNames);
            root.addChild(setTable);
            if (instanceInfoList == null) {
                instanceInfoList = new HashMap<String, ArrayList<Object>>();
                dataSource.addAnnotation(SpicyEngineConstants.CSV_INSTANCES_INFO_LIST, instanceInfoList);
            }
            instanceInfoList.putAll(strfullPath);
        }
        dataSource.addInstanceWithCheck(root);
    } catch (Throwable ex) {
        logger.error(ex);
        throw new DAOException(ex.getMessage());
    }
}

From source file:io.github.lucaseasedup.logit.config.PredefinedConfiguration.java

public void load() throws IOException, InvalidPropertyValueException {
    reopen();/*from  w w  w.j av a 2 s. com*/

    File backupFile = new File(file.getCanonicalPath() + ".bak");
    Files.copy(file, backupFile);

    String packageDefString = readPackageDefString();
    String userDefString;

    Map<String, Map<String, String>> packageDef = IniUtils.unserialize(packageDefString);
    Map<String, Map<String, String>> userDef;

    File userDefFile = getDataFile(userDefPathname);
    boolean userDefChanged = false;

    if (!userDefFile.exists()) {
        userDefFile.getParentFile().mkdirs();
        userDefString = packageDefString;
        userDef = IoUtils.deepCopy(packageDef);

        for (Map<String, String> userDefSection : userDef.values()) {
            registerProperty(userDefSection);
        }

        userDefChanged = true;
    } else {
        userDefString = readUserDefString();
        userDef = IniUtils.unserialize(userDefString);

        // Backup all user-specified values
        YamlConfiguration backup = YamlConfiguration.loadConfiguration(file);

        // Clear the config
        for (String path : configuration.getKeys(true)) {
            removePath(configuration, path);
        }

        /* Remove all unused sections from the user def */
        Iterator<Map.Entry<String, Map<String, String>>> it = userDef.entrySet().iterator();

        while (it.hasNext()) {
            Map.Entry<String, Map<String, String>> section = it.next();

            if (!packageDef.containsKey(section.getKey())) {
                removePath(backup, section.getValue().get("path"));

                it.remove();

                userDefChanged = true;
            }
        }

        /* Iterate through the package def to update the user def and config file */
        for (Map.Entry<String, Map<String, String>> section : packageDef.entrySet()) {
            String guid = section.getKey();
            Map<String, String> packageDefSection = section.getValue();
            Map<String, String> userDefSection = userDef.get(guid);

            String newPath = packageDefSection.get("path");
            String oldPath;

            if (userDefSection == null) {
                oldPath = newPath;

                userDefSection = new LinkedHashMap<>(packageDefSection);
                userDef.put(guid, userDefSection);
                userDefChanged = true;
            } else {
                oldPath = userDefSection.get("path");

                for (Map.Entry<String, String> property : packageDefSection.entrySet()) {
                    String key = property.getKey();

                    if (!property.getValue().equals(userDefSection.get(key))) {
                        userDefSection.put(key, property.getValue());
                        userDefChanged = true;
                    }
                }
            }

            registerProperty(userDefSection);

            /* Restore user-specified value */
            if (backup.contains(oldPath)) {
                Object backupValue = backup.get(oldPath);

                configuration.set(newPath, backupValue);
                properties.get(newPath).setSilently(backupValue);

                removePath(backup, oldPath);
            }
        }

        userDefString = IniUtils.serialize(userDef);
    }

    if (userDefChanged) {
        try (OutputStream userDefOutputStream = new FileOutputStream(userDefFile)) {
            userDefOutputStream.write(encodeUserDef(userDefString).getBytes());
        }
    }

    save();
    backupFile.delete();

    loaded = true;
}