Example usage for java.util Map entrySet

List of usage examples for java.util Map entrySet

Introduction

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

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:Main.java

public static Element newElementWithAttrs(String tagName, Map<String, String> attrs) {
    Document document = newDocument();
    Element element = newElement(document, tagName);

    for (Entry<String, String> entry : attrs.entrySet()) {
        element.setAttribute(entry.getKey(), entry.getValue());
    }//from  w w  w. j a va2 s  . c om

    return element;
}

From source file:Main.java

/**
 * Creates an Properties object initialized with the value from the given Map.
 * <p>/*from w w w  .  jav a  2 s .com*/
 * @param map the Map supply the keys and value for the Properties object.
 * @return a Properties object initialized with the key and value from the Map.
 * @see java.util.Map
 * @see java.util.Properties
 */
public static Properties createProperties(final Map<String, String> map) {
    Properties properties = new Properties();

    if (!(map == null || map.isEmpty())) {
        for (Entry<String, String> entry : map.entrySet()) {
            properties.setProperty(entry.getKey(), entry.getValue());
        }
    }

    return properties;
}

From source file:Main.java

/**
 * Calculates a value case insensitive hash code for a String v String map. Method placed here to
 * reduce .NET translation overhead//from   w ww.  j  ava 2 s .c  o m
 * @param map
 * @return
 */
public static int calculateCaseInsensitiveValueStringVsStringMapHash(Map<String, String> map) {
    if (map == null) {
        throw new NullPointerException();
    }

    int result = 0;
    Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<String, String> next = iter.next();
        int entryHash = (next.getKey() == null ? 0 : next.getKey().hashCode())
                ^ (next.getValue() == null ? 0 : next.getValue().toLowerCase().hashCode());
        result += entryHash;
    }
    return result;
}

From source file:com.net2plan.internal.CommandLineParser.java

/**
 * Gets the current parameters from the user-specified ones, taking default
 * values for unspecified parameters./*from   w w w. ja  v a  2s. c o  m*/
 * 
 * @param defaultParameters Default parameters (key, value, and description)
 * @param inputParameters User parameters (key, value)
 * @return Current parameters (key, value)
 * @since 0.3.0
 */
public static Map<String, String> getParameters(List<Triple<String, String, String>> defaultParameters,
        Map inputParameters) {
    return getParameters(defaultParameters, inputParameters == null ? null : inputParameters.entrySet());
}

From source file:Main.java

public static String encodeParamsToUrl(String originUrl, Map<String, String> params) {
    String paramsEncoding = "UTF-8";
    StringBuilder encodedParams = new StringBuilder();
    try {/*from w w w.  ja v  a 2 s .  c  o m*/
        for (Map.Entry<String, String> entry : params.entrySet()) {
            encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
            encodedParams.append('=');
            encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
            encodedParams.append('&');
        }
        return originUrl + "?" + encodedParams.toString();
    } catch (UnsupportedEncodingException uee) {
        throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
    }
}

From source file:Main.java

/**
 * Returns an unmodifiable view of the specified {@code mapSet}. This
 *  method allows modules to provide users with "read-only" access to
 * {@link Map}, but also to the value {@link Set}.
 *
 * @param <K>/* ww w. j av  a 2s. c om*/
 *            the class of the map keys
 * @param <V>
 *            the class of the set values
 * @param mapSet
 *            the {@link Map} of {@link Set} for which an unmodifiable view
 *            is to be returned
 * @return an unmodifiable view of the specified map.
 *
 * @see Collections#unmodifiableMap(Map)
 * @see Collections#unmodifiableSet(Set)
 * @since 4.2
 */
@Nonnull
public static <K, V> Map<K, Set<V>> unmodifiableMapSet(@Nullable final Map<K, Set<V>> mapSet) {
    if (mapSet == null) {
        return Collections.emptyMap();
    }

    for (final Map.Entry<K, Set<V>> entry : mapSet.entrySet()) {
        final K key = entry.getKey();
        final Set<V> value = entry.getValue();

        mapSet.replace(key, Collections.unmodifiableSet(value));
    }

    return Collections.unmodifiableMap(mapSet);
}

From source file:org.apache.metamodel.elasticsearch.rest.ElasticSearchRestClient.java

@SuppressWarnings("unchecked")
static Set<Entry<String, Object>> parseMappings(final XContentParser response, final String indexName)
        throws IOException {
    Map<String, Object> schema = (Map<String, Object>) response.map().get(indexName);
    Map<String, Object> tables = (Map<String, Object>) schema.get("mappings");

    return tables.entrySet();
}

From source file:Main.java

public static void writeStringStringMap(Map<String, String> map, OutputStream os) throws IOException {
    if (map != null) {
        writeInt(os, map.size());/*from  w  w  w . java  2  s  . c om*/
        for (Map.Entry<String, String> entry : map.entrySet()) {
            writeString(os, entry.getKey());
            writeString(os, entry.getValue());
        }
    } else {
        writeInt(os, 0);
    }
}

From source file:Main.java

/**
 * Qualification of every element in a DOM document. Previous namespaces are
 * ignored./*  www .j a  va 2 s .com*/
 * 
 * @param document
 *            The document to modify.
 * @param namespaces
 *            A map of prefix/URL where prefix are expected to match the
 *            local name of the elements they qualify (if an element has no
 *            corresponding prefix, it uses the namespace of its parent).
 */
public static void autoQualify(Document document, Map<String, String> namespaces) {
    Element root = document.getDocumentElement();
    for (Map.Entry<String, String> entry : namespaces.entrySet()) {
        String prefix = entry.getKey();
        String url = entry.getValue();
        StringBuilder attributName = new StringBuilder("xmlns");
        if (prefix != null) {
            attributName.append(':').append(prefix);
        }
        root.setAttribute(attributName.toString(), url);
    }
    autoQualify(document, root, namespaces, null);
}

From source file:Main.java

public static <K, V> Map<K, List<V>> copyNullSafeMultiHashMapReified(Class<V> valueType,
        Map<? extends K, List<?>> map) {
    if (valueType == null)
        throw new NullPointerException("valueType");
    if (map == null)
        throw new NullPointerException("map");

    @SuppressWarnings("unchecked")
    Map<K, List<V>> result = (Map<K, List<V>>) (Map<?, ?>) copyNullSafeMutableHashMap(map);
    for (Map.Entry<K, List<V>> entry : result.entrySet()) {
        List<V> value = entry.getValue();
        ArrayList<V> valueCopy = new ArrayList<V>(value);
        for (V element : valueCopy) {
            valueType.cast(element);/*ww  w  . j  a v a  2s  .c o  m*/
        }

        entry.setValue(Collections.unmodifiableList(valueCopy));
    }
    return result;
}