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:de.alpharogroup.collections.MapExtensions.java

/**
 * The Method printMap prints the HashMap to the console.
 *
 * @param <K>//from   w  w  w .  j a v a  2s.com
 *            the generic type of the key
 * @param <V>
 *            the generic type of the value
 * @param msg
 *            The map to print.
 */
public static <K, V> void printMap(final Map<K, V> msg) {
    for (final Entry<K, V> entry : msg.entrySet()) {
        final K key = entry.getKey();
        final V value = entry.getValue();
        System.out.println("[" + key.toString() + "=" + value.toString() + "]");
    }
}

From source file:Main.java

/**
 * Converts <code>params</code> into an application/x-www-form-urlencoded encoded string.
 *///from  w w w.  j  a  v  a 2 s .c o m
public static String encodeParamsToStr(Map<String, String> params, String paramsEncoding) {
    StringBuilder encodedParams = new StringBuilder();
    try {
        int i = 0;
        for (Map.Entry<String, String> entry : params.entrySet()) {
            encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
            encodedParams.append('=');
            encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
            if (i != params.size() - 1) {
                encodedParams.append('&');
            }
            i++;
        }
        return encodedParams.toString();
    } catch (UnsupportedEncodingException uee) {
        throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
    }
}

From source file:Main.java

public static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> sortByValues(Map<K, V> map) {
    SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<>((e1, e2) -> {
        int res = e1.getValue().compareTo(e2.getValue());
        return res != 0 ? res : 1;
    });//from   w  w  w  .j a v a  2  s  . c  o m
    sortedEntries.addAll(map.entrySet());
    return sortedEntries;
}

From source file:de.metas.ui.web.window.datatypes.json.JSONLookupValue.java

public static final StringLookupValue stringLookupValueFromJsonMap(final Map<String, String> map) {
    final Set<Map.Entry<String, String>> entrySet = map.entrySet();
    if (entrySet.size() != 1) {
        throw new IllegalArgumentException("Invalid JSON lookup value: map=" + map);
    }/*from ww w. j  a  v a 2  s  .c  o  m*/
    final Map.Entry<String, String> e = entrySet.iterator().next();

    final String id = e.getKey();
    final String name = e.getValue();

    return StringLookupValue.of(id, name);
}

From source file:cc.sion.core.persistence.SearchFilter.java

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

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

        if (log.isDebugEnabled()) {
            //EQ_userId    10086
            log.debug("searchParams>>>key:{},value:{}", key, value);
        }

        // 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:com.github.horrorho.liquiddonkey.settings.commandline.CommandLineOptions.java

static Map<String, Property> optToProperty(Map<Property, Option> options) {
    return options.entrySet().stream()
            .map(set -> Arrays.asList(new SimpleEntry<>(set.getValue().getOpt(), set.getKey()),
                    new SimpleEntry<>(set.getValue().getLongOpt(), set.getKey())))
            .flatMap(List::stream).filter(set -> set.getKey() != null)
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

From source file:edu.usf.cutr.obascs.io.ConfigFileGenerator.java

public static String generateSampleRealTimeConfigFile(String configXml, Map<String, String> agencyMap) {
    StringBuilder bundleNamesBuilder = new StringBuilder();
    for (Map.Entry<String, String> agency : agencyMap.entrySet()) {
        bundleNamesBuilder.append(/*from w w  w. j a v  a2s.  c om*/
                "<bean class=\"org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeSource\">");
        bundleNamesBuilder.append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<property name=\"tripUpdatesUrl\" value=\"")
                .append(GeneralConstants.SAMPLE_REALTIME_CONFIG_TRIP_UPDATES_URL);
        bundleNamesBuilder.append("\" />").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<property name=\"vehiclePositionsUrl\" value=\"")
                .append(GeneralConstants.SAMPLE_REALTIME_CONFIG_VEHICLE_POS_URL);
        bundleNamesBuilder.append("\" />").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<property name=\"alertsUrl\" value=\"")
                .append(GeneralConstants.SAMPLE_REALTIME_CONFIG_ALERTS_URL);
        bundleNamesBuilder.append("\" />").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<property name=\"refreshInterval\" value=\"15\" />")
                .append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<property name=\"agencyIds\">").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<list>").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("<value>").append(agency.getKey()).append("</value>")
                .append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("</list>").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("</property>").append(SystemUtils.LINE_SEPARATOR);
        bundleNamesBuilder.append("</bean>").append(SystemUtils.LINE_SEPARATOR);
    }

    configXml = StringUtils.replace(configXml, "${beanNames}", bundleNamesBuilder.toString());
    return configXml;
}

From source file:gool.executor.ExecutorHelper.java

public static List<File> compile(Map<Platform, List<File>> files) throws FileNotFoundException {
    List<File> result = new ArrayList<File>();
    for (Entry<Platform, List<File>> item : files.entrySet()) {
        SpecificCompiler compiler = item.getKey().getCompiler();
        File outputFile = compiler.compileToExecutable(item.getValue(), null, null, null);
        result.add(outputFile);/*w w  w  .  ja  va  2 s.  c o  m*/
    }

    return result;
}

From source file:me.st28.flexseries.flexcore.util.MapUtils.java

/**
 * Retrieves an entry from a map with a given index. Intended for maps that preserve ordering (ex. LinkedHashMap)
 *
 * @param map The map to retrieve the entry from.
 * @param index The index of the entry in the map.
 * @return The entry at the given index in the given map.
 *//*  ww  w  .  j a v a  2s .c  o m*/
public static <K, V> Entry<K, V> getEntryByIndex(Map<K, V> map, int index) {
    Validate.notNull(map, "Map cannot be null.");
    int mapSize = map.size();

    int curIndex = 0;
    Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    while (iterator.hasNext() && curIndex < mapSize) {
        if (curIndex++ == index) {
            return iterator.next();
        }
    }
    throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + mapSize);
}

From source file:com.iisigroup.cap.log.LogContext.java

/**
 * Only used if jdk logging is used./*from   w  ww  .j a v  a 2s  .c o m*/
 * 
 * @return String
 */
public static String toLogPrefixString() {
    Map m = getContext();
    Iterator i = m.entrySet().iterator();

    StringBuilder sb = new StringBuilder("[");
    while (i.hasNext()) {
        Map.Entry e = (Map.Entry) i.next();
        sb.append((String) e.getKey()).append("=").append(e.getValue().toString());
        if (i.hasNext()) {
            sb.append("&");
        }
    }
    sb.append("]");
    return sb.toString();
}