org.aksw.commons.collections.SetUtils Maven / Gradle / Ivy
package org.aksw.commons.collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.Sets;
public class SetUtils {
public static Set asSet(Iterable c) {
return (c instanceof Set) ? (Set) c : Sets.newHashSet(c);
}
/**
* Short hand for
* Set result = source.stream().map(fn).collect(Collectors.toSet())
*
* Maps a set of keys to a corresponding set of values via a given map
* TODO Probably this method can be replaced by something from guava
*
* @param set
* @param map
* @return
*/
public static Set mapSet(Set set, Map map) {
Set result = new HashSet();
for(K item : set) {
V v = map.get(item);
result.add(v);
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy