All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.mojo.versions.utils.MiscUtils Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
package org.codehaus.mojo.versions.utils;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Miscellaneous utility class.
 */
public class MiscUtils {
    /**
     * Filters a given map leaving only elements fulfilling a predicate. Does not change the input map,
     * the filtered map is returned as output.
     *
     * @param map       input map to be filtered
     * @param predicate predicate for element comparison
     * @param        key type
     * @param        value type
     * @return map such that every element comforms with the predicate
     */
    public static  Map filter(Map map, Function predicate) {
        return map.entrySet().stream()
                .filter(e -> predicate.apply(e.getValue()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy