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:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java

private static String getKeyOfNonSerializableStringMapEntry(Map<String, ?> data) {
    for (Map.Entry<String, ?> entry : data.entrySet()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {//w ww  .  j  a v  a2  s.  c o  m
            ObjectOutputStream out = new ObjectOutputStream(baos);
            out.writeObject(entry.getValue());
            out.flush();
        } catch (IOException e) {
            return entry.getKey();
        }
    }
    return null;
}

From source file:edu.ucsb.cs.eager.sa.cerebro.ProfessorX.java

private static void analyzeRepo(String root, String name, String classPath, Collection<String> classes) {

    System.out.println("----------------- PROJECT: " + name + " -----------------\n");
    File repoDir = new File(root, name);
    File classPathDir = new File(repoDir, classPath);
    Set<String> analyzedMethods = new HashSet<String>();
    for (String className : classes) {
        Cerebro cerebro = new Cerebro(classPathDir.getAbsolutePath(), className);
        //cerebro.setVerbose(true);
        cerebro.setWholeProgramMode(true);
        Map<SootMethod, CFGAnalyzer> results = cerebro.analyze();
        for (Map.Entry<SootMethod, CFGAnalyzer> entry : results.entrySet()) {
            String method = toString(entry.getKey());
            if (analyzedMethods.contains(method)) {
                continue;
            }//from   ww  w.  j av a2 s .  c om
            analyzedMethods.add(method);
            cerebro.setVerbose(true);
            cerebro.printResult(entry.getKey(), entry.getValue());
        }
        cerebro.cleanup();
    }
    System.out.println();
}

From source file:io.appform.nautilus.funnel.utils.AttributeUtils.java

public static boolean isValid(Map<String, Object> attributes) {
    if (null == attributes) {
        return true;
    }//from  w  w  w.  j ava 2s . co m
    final boolean[] valid = { true };
    attributes.entrySet().forEach(entry -> {
        if (!entry.getKey().equals("location")) {
            Object value = entry.getValue();
            final Class<?> clazz = value.getClass();
            valid[0] &= (!entry.getKey().matches(Constants.FIELD_REPLACEMENT_VALUE)
                    && !ClassUtils.isPrimitiveOrWrapper(clazz) && !(value instanceof String));
        }

    });
    return valid[0];
}

From source file:Main.java

public static String urlWithParameters(String url, Map<String, Object> params) {
    StringBuilder builder = new StringBuilder();

    if (params != null) {
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            if (builder.length() == 0) {
                if (url.contains("?")) {
                    builder.append("&");
                } else {
                    builder.append("?");
                }//from  www .ja v  a2  s. c o  m
            } else {
                builder.append("&");
            }
            builder.append(entry.getKey()).append("=").append(entry.getValue());
        }
    }

    return url + builder.toString();
}

From source file:Main.java

/**
 * Typecheck as above, performing on map values
 * @param <K>    Key type// ww  w  . ja  v  a2  s.c  om
 * @param <V>    Designated value type
 * @param m      the map to check
 * @param vClass the value type's class
 * @return m, accordingly cast, if no classCastException is thrown
 * 
 * @deprecated In the most common use case this is unnecessary. In the second
 *       common use case this is a sign that you have not understood generics.
 */
public static <K, V> Map<K, V> typecheck(Map<K, ?> m, Class<V> vClass) {
    if (m == null)
        return null;
    for (Map.Entry<K, ?> e : m.entrySet()) {
        Object o = e.getValue();
        if (o != null && !vClass.isInstance(o))
            throw new ClassCastException("ClassCast from " + o.getClass() + " to " + vClass);
    }
    return (Map<K, V>) m;
}

From source file:com.khartec.waltz.service.authoritative_source.AuthoritativeSourceCalculator.java

public static void prettyPrint(Map<String, Map<Long, AuthoritativeSource>> cumulativeRules) {
    cumulativeRules.entrySet().stream().forEach(e -> {
        System.out.println(e.getKey() + " ==> ");
        e.getValue().values().forEach(v -> System.out.println("\t" + v.applicationReference().id() + " - "
                + v.applicationReference().name() + " ( " + v.parentReference().id() + ")"));
    });//  w ww .  j a v a  2 s .  c  o m
}

From source file:Main.java

/**
 * Clones a map and prefixes the keys in the clone, e.g.
 * for mapping "JAVA_HOME" to "env.JAVA_HOME" to simulate
 * the behaviour of ANT.//from ww w.  ja va2 s . co  m
 *
 * @param source the source map
 * @param prefix the prefix used for all names
 * @return the clone of the source map
 */
public static Map prefix(Map source, String prefix) {

    if (source == null) {
        return null;
    }

    Map result = new HashMap();

    Iterator iter = source.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        result.put(prefix + '.' + key.toString(), value);
    }

    return result;
}

From source file:io.gravitee.common.util.EnvironmentUtils.java

public static Map<String, Object> getPropertiesStartingWith(ConfigurableEnvironment aEnv, String aKeyPrefix) {
    Map<String, Object> result = new HashMap<>();
    Map<String, Object> map = getAllProperties(aEnv);

    for (Map.Entry<String, Object> entry : map.entrySet()) {
        String key = entry.getKey();

        if (encodedKey(key).startsWith(encodedKey(aKeyPrefix))) {
            result.put(key, entry.getValue());
        }/*from   w w w . ja  v a  2 s.  co  m*/
    }

    return result;
}

From source file:nu.yona.server.goals.service.ActivityCategoryDto.java

private static Map<String, String> mapToStringMap(Map<Locale, String> localeMap) {
    return localeMap.entrySet().stream()
            .collect(Collectors.toMap(e -> e.getKey().toLanguageTag(), Map.Entry::getValue));
}

From source file:at.gv.egovernment.moa.id.protocols.oauth20.OAuth20Util.java

public static void addProperytiesToJsonObject(JsonObject jsonObject, Map<String, Object> params) {
    for (Map.Entry<String, Object> param : params.entrySet()) {

        if (!StringUtils.isEmpty(param.getKey()) && param.getValue() != null) {

            // check for integer
            try {
                int i = Integer.parseInt(String.valueOf(param.getValue()));
                jsonObject.addProperty(param.getKey(), i);
                continue;
            } catch (NumberFormatException e) {
            }/*from   w  ww.  j  a va 2 s . c  om*/

            // check for long
            try {
                long l = Long.parseLong(String.valueOf(param.getValue()));
                jsonObject.addProperty(param.getKey(), l);
                continue;
            } catch (NumberFormatException e) {
            }

            // string
            if (param.getValue() instanceof String) {
                jsonObject.addProperty(param.getKey(), String.valueOf(param.getValue()));
            }
        }
    }
}