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:com.intel.podm.allocation.strategy.matcher.MemoryMatcher.java

private static boolean areMatched(List<RequestedMemory> requestedMemoryModules,
        List<MemoryModule> availableMemoryModules) {
    MemoryModulesAllocationMapper mapper = new MemoryModulesAllocationMapper();
    Map<RequestedMemory, List<MemoryModule>> mappedMemoryModules = mapper.map(requestedMemoryModules,
            unmodifiableList(availableMemoryModules));
    return mappedMemoryModules.entrySet().stream().allMatch(entry -> !entry.getValue().isEmpty());
}

From source file:de.tynne.benchmarksuite.Main.java

private static void listSuites(Map<BenchmarkSuite, BenchmarkProducer> suites, PrintStream ps) {
    suites.entrySet().stream().sorted(
            (a, b) -> nameFor(a.getKey(), a.getValue()).compareToIgnoreCase(nameFor(b.getKey(), b.getValue())))
            .forEach((e) -> {//from   w w  w  .  ja v a2s  .  c  om
                ps.printf("%s: %s\n", nameFor(e.getKey(), e.getValue()), e.getKey().enabled());
            });
    ps.flush();
}

From source file:gobblin.compaction.conditions.RecompactionConditionBasedOnRatio.java

public static double getRatioThresholdByDatasetName(String datasetName,
        Map<String, Double> datasetRegexAndRecompactThreshold) {
    for (Map.Entry<String, Double> topicRegexEntry : datasetRegexAndRecompactThreshold.entrySet()) {
        if (DatasetFilterUtils.stringInPatterns(datasetName,
                DatasetFilterUtils/*  w w w  .  j  a va 2 s  . co  m*/
                        .getPatternsFromStrings(Splitter.on(DATASETS_WITH_SAME_RECOMPACT_THRESHOLDS_SEPARATOR)
                                .trimResults().omitEmptyStrings().splitToList(topicRegexEntry.getKey())))) {
            return topicRegexEntry.getValue();
        }
    }
    return MRCompactor.DEFAULT_COMPACTION_LATEDATA_THRESHOLD_FOR_RECOMPACT_PER_DATASET;
}

From source file:Main.java

static <K, V> Map<K, V> getMap(Map<K, V> orig) {
    if (orig == null || orig.size() == 0) {
        return Collections.emptyMap();
    } else if (orig.size() == 1) {
        final Map.Entry<K, V> entry = orig.entrySet().iterator().next();
        return Collections.singletonMap(entry.getKey(), entry.getValue());
    } else {//ww  w.j av  a  2  s  . com
        return Collections.unmodifiableMap(new TreeMap<>(orig));
    }
}

From source file:cn.imethan.common.repository.SearchFilter.java

/**
 * searchParamskey?OPERATOR_FIELDNAME//from   w  w w . j a  v  a 2 s .c  om
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:io.leishvl.core.data.mongodb.MapKeyConverters.java

/**
 * Recursively iterates over a map created from a JSON document, applying a conversion function to 
 * its keys. It guarantees that all possible inner maps are also converted.
 * @param map - a map created from a JSON document
 * @param keyConverter - a function that applies a conversion to the keys of the input map
 * @return a new map where the keys where transformed using the conversion function.
 *//*from ww  w.j a  v  a  2  s  .  c om*/
@SuppressWarnings("unchecked")
private static Map<String, Object> escapeMap(final Map<String, Object> map,
        final Function<String, String> keyConverter) {
    return map.entrySet().stream().collect(Collectors.toMap(e -> keyConverter.apply(e.getKey()), e -> {
        return (e.getValue() instanceof Map) ? escapeMap((Map<String, Object>) e.getValue(), keyConverter)
                : e.getValue();
    }));
}

From source file:org.apache.synapse.transport.passthru.util.SourceResponseFactory.java

private static void addResponseHeader(SourceResponse sourceResponse, Map transportHeaders) {
    for (Object entryObj : transportHeaders.entrySet()) {
        Map.Entry entry = (Map.Entry) entryObj;
        if (entry.getValue() != null && entry.getKey() instanceof String
                && entry.getValue() instanceof String) {
            sourceResponse.addHeader((String) entry.getKey(), (String) entry.getValue());
        }/* w  w  w  .  ja v  a2s .c  om*/
    }
}

From source file:cn.imethan.common.mongodb.SearchFilter.java

/**
 * ??/*from w  w  w  . java 2 s.com*/
 * searchParamskey?OPERATOR_FIELDNAME
 * 
 * @param searchParams
 * @return
 *
 * @author Ethan Wong
 * @datetime 2015101?1:24:57
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }
    return filters;
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.macros.GWikiHtmlTagMacro.java

public static void ensureHtmlAttrRight(MacroAttributes attrs, GWikiContext ctx)
        throws AuthorizationFailedException {
    if (ctx.isAllowTo(GWikiAuthorizationRights.GWIKI_EDITHTML.name()) == true) {
        return;/*from w  w w . j ava 2s .c  om*/
    }
    if (restrictedTags.contains(attrs.getCmd()) == true) {
        throw new AuthorizationFailedException("Usage of tag " + attrs.getCmd() + " is not allowed");
    }
    Map<String, String> args = attrs.getArgs().getMap();
    for (Map.Entry<String, String> me : args.entrySet()) {
        String k = me.getKey().toLowerCase();
        if (k.startsWith("on") == true) {
            throw new AuthorizationFailedException("Java Script methods in Macros are not allowed");
        }
        if (k.equals("href") == true || k.equals("src") == true) {
            String v = StringUtils.trim(me.getValue().toLowerCase());
            if (v.startsWith("javascript:") == true) {
                throw new AuthorizationFailedException("Java Script methods in Macros are not allowed");
            }
        }
    }
}

From source file:Main.java

public static <T> String print(Map<T, T> map) {
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Map.Entry<T, T> entry : map.entrySet()) {
        if (first)
            first = false;//from   ww w  .  j  a  v  a 2  s. com
        else
            sb.append(", ");
        sb.append(entry.getKey()).append("=").append(entry.getValue());
    }
    return sb.toString();
}