Example usage for java.util Map putAll

List of usage examples for java.util Map putAll

Introduction

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

Prototype

void putAll(Map<? extends K, ? extends V> m);

Source Link

Document

Copies all of the mappings from the specified map to this map (optional operation).

Usage

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter.java

public static CacheData mergeCacheData(CacheData current, CacheData added) {
    String id = current.getId();//from  w w  w  .  j av  a2 s. c  o  m
    Map<String, Object> attributes = new HashMap<>();
    attributes.putAll(added.getAttributes());
    attributes.putAll(current.getAttributes());
    // Behavior is: if no ttl is set on either, the merged key won't expire
    int ttl = Math.min(current.getTtlSeconds(), added.getTtlSeconds());

    Map<String, Collection<String>> relationships = new HashMap<>();
    relationships.putAll(current.getRelationships());
    added.getRelationships().entrySet()
            .forEach(entry -> relationships.merge(entry.getKey(), entry.getValue(), (a, b) -> {
                Set<String> result = new HashSet<>();
                result.addAll(a);
                result.addAll(b);
                return result;
            }));

    return new DefaultCacheData(id, ttl, attributes, relationships);
}

From source file:com.ctrip.infosec.rule.resource.DataProxyTest.java

private static Map parseProfileResult(Map result) {
    if (result != null) {
        if (result.get("tagName") != null) {
            return parseResult(result);
        } else if (result.get("tagNames") != null) {
            Object tagValues = result.get("tagNames");
            List oldResults = Utils.JSON.parseObject(Utils.JSON.toJSONString(tagValues), List.class);
            Map newResults = new HashMap();
            Iterator iterator = oldResults.iterator();
            while (iterator.hasNext()) {
                Map oneResult = (Map) iterator.next();
                newResults.putAll(parseResult(oneResult));
            }//  w w w. j  a  v a 2  s.  c o  m
            return newResults;
        } else {
            return result;
        }
    }
    return null;
}

From source file:com.ikanow.aleph2.logging.utils.LoggingUtils.java

/**
 * Copies the details from copyInto overtop of the details from copyFrom (merging them).  Adds in
 * key1, value1 after./*from  ww w. ja v  a  2  s.co m*/
 * @param copyFrom
 * @param copyInto
 * @param key1
 * @param value1
 * @return
 */
public static Map<String, Object> mergeDetailsAddValue(final BasicMessageBean copyFrom,
        final BasicMessageBean copyInto, final String key1, final Object value1) {
    final Map<String, Object> tempMap = new HashMap<String, Object>(
            Optional.ofNullable(copyFrom).map(c -> c.details()).orElse(ImmutableMap.of())); //copy current map into modifiable map
    tempMap.putAll(Optional.ofNullable(copyInto.details()).orElse(ImmutableMap.of())); //copy newer map over top of old map
    if (value1 != null)
        tempMap.put(key1, value1); //add in new value
    return ImmutableMap.copyOf(tempMap); //return an immutable map
}

From source file:main.java.utils.Utility.java

/**
 * Added from SO: http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java
 * /*from  w  w  w.  j a v  a 2s .c  om*/
 */
public static <K, V extends Comparable<V>> Map<K, V> sortByValues(final Map<K, V> map) {

    Comparator<K> valueComparator = new Comparator<K>() {
        public int compare(K k1, K k2) {
            int compare = map.get(k2).compareTo(map.get(k1));

            if (compare == 0)
                return 1;
            else
                return compare;
        }
    };

    Map<K, V> sortedByValues = new TreeMap<K, V>(valueComparator);
    sortedByValues.putAll(map);

    return sortedByValues;
}

From source file:com.ikanow.aleph2.logging.utils.LoggingUtils.java

/**
 * Copies the details from copyInto overtop of the details from copyFrom (merging them).  Adds in
 * key1=value1 and key2=value2 after./*from www .j a v  a  2s.  c  om*/
 * @param copyFrom
 * @param copyInto
 * @param key1
 * @param value1
 * @param key2
 * @param value2
 * @return
 */
public static Map<String, Object> mergeDetailsAddValue(final BasicMessageBean copyFrom,
        final BasicMessageBean copyInto, final String key1, final Object value1, final String key2,
        final Object value2) {
    final Map<String, Object> tempMap = new HashMap<String, Object>(
            Optional.ofNullable(copyFrom).map(c -> c.details()).orElse(ImmutableMap.of())); //copy current map into modifiable map
    tempMap.putAll(Optional.ofNullable(copyInto.details()).orElse(ImmutableMap.of())); //copy newer map over top of old map
    if (value1 != null)
        tempMap.put(key1, value1); //add in new value
    if (value2 != null)
        tempMap.put(key2, value2);
    return ImmutableMap.copyOf(tempMap); //return an immutable map
}

From source file:io.cloudslang.worker.execution.services.ExecutionServiceImpl.java

private static void addContextData(Map<String, Object> data, Execution execution) {
    data.putAll(execution.getContexts());
    data.put(ExecutionParametersConsts.SYSTEM_CONTEXT, execution.getSystemContext());
    data.put(ExecutionParametersConsts.EXECUTION_RUNTIME_SERVICES, execution.getSystemContext());
    data.put(ExecutionParametersConsts.EXECUTION, execution);
    data.put(ExecutionParametersConsts.EXECUTION_CONTEXT, execution.getContexts());
    data.put(ExecutionParametersConsts.RUNNING_EXECUTION_PLAN_ID, execution.getRunningExecutionPlanId());
}

From source file:org.brutusin.rpc.client.http.HttpEndpoint.java

private static Map<String, InputStream> sortFiles(final Map<String, InputStream> files) {
    if (files == null) {
        return null;
    }//w w w .j  av  a2s.c om

    Comparator<String> comparator = new Comparator<String>() {
        public int compare(String s1, String s2) {
            if (s1.equals(s2)) {
                return 0;
            }
            InputStream f1 = files.get(s1);
            InputStream f2 = files.get(s2);
            if (f1 == null || !(f1 instanceof MetaDataInputStream)
                    || ((MetaDataInputStream) f1).getLength() == null) {
                return -1;
            }
            if (f2 == null || !(f2 instanceof MetaDataInputStream)
                    || ((MetaDataInputStream) f2).getLength() == null) {
                return 1;
            }
            return Long.compare(((MetaDataInputStream) f1).getLength(), ((MetaDataInputStream) f2).getLength());
        }
    };
    Map<String, InputStream> ret = new TreeMap<String, InputStream>(comparator);
    ret.putAll(files);
    return ret;
}

From source file:au.com.jwatmuff.eventmanager.util.GUIUtils.java

public static Map<String, Object> getComponentValues(Container parent) {
    Map<String, Object> values = new HashMap<String, Object>();

    for (int i = 0; i < parent.getComponentCount(); i++) {
        Component child = parent.getComponent(i);

        if (child instanceof Container)
            values.putAll(getComponentValues((Container) child));

        if (child.getName() != null) {
            String name = child.getName();

            if (child instanceof JTextField)
                values.put(name, ((JTextField) child).getText());
        }/*from ww w  . j a va  2 s .c  o m*/

    }

    return values;
}

From source file:com.tech.utils.CustomCollectionUtil.java

/**
 * Method used to sort map by values//from   ww w  .j  a  v  a 2  s .c  om
 * 
 * @param <K>
 *            Map Key
 * @param <V>
 *            Map Value
 * @param map
 *            Map
 * @return sorted Map
 */
public static <K, V extends Comparable<V>> Map<K, V> sortByValues(final Map<K, V> map) {
    Comparator<K> valueComparator = new Comparator<K>() {
        public int compare(final K k1, final K k2) {
            int compare = map.get(k1).compareTo(map.get(k2));

            if (compare == 0) {
                return 1;
            } else {
                return compare;
            }
        }
    };

    Map<K, V> sortedByValues = new TreeMap<K, V>(valueComparator);
    sortedByValues.putAll(map);

    return sortedByValues;
}

From source file:hydrograph.ui.expression.editor.util.ExpressionEditorUtil.java

/**
 * This method validates the given expression and updates the expression-editor's datasturcture accordingly
 * //  w w  w .jav a2  s.com
 * @param expressionText
 * @param inputFields
 * @param expressionEditorData
 */
public static void validateExpression(String expressionText, Map<String, Class<?>> inputFields,
        ExpressionEditorData expressionEditorData) {
    if (BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject() != null) {
        DiagnosticCollector<JavaFileObject> diagnosticCollector = null;
        try {
            inputFields.putAll(expressionEditorData.getExtraFieldDatatypeMap());
            diagnosticCollector = ValidateExpressionToolButton.compileExpresion(expressionText, inputFields,
                    expressionEditorData.getComponentName());
            if (diagnosticCollector != null && !diagnosticCollector.getDiagnostics().isEmpty()) {
                for (Diagnostic<?> diagnostic : diagnosticCollector.getDiagnostics()) {
                    if (StringUtils.equals(diagnostic.getKind().name(), Diagnostic.Kind.ERROR.name())) {
                        expressionEditorData.setValid(false);
                        return;
                    }
                }
            }
        } catch (JavaModelException | InvocationTargetException | ClassNotFoundException | MalformedURLException
                | IllegalAccessException | IllegalArgumentException e) {
            expressionEditorData.setValid(false);
            return;
        }
        expressionEditorData.setValid(true);
    }
}