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

org.aksw.commons.collections.SetUtils Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
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