org.codehaus.mojo.versions.utils.MiscUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of versions-common Show documentation
Show all versions of versions-common Show documentation
Common components for the Versions Maven Plugin
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