Example usage for com.google.common.collect Sets intersection

List of usage examples for com.google.common.collect Sets intersection

Introduction

In this page you can find the example usage for com.google.common.collect Sets intersection.

Prototype

public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2) 

Source Link

Document

Returns an unmodifiable view of the intersection of two sets.

Usage

From source file:com.facebook.buck.apple.Flavors.java

public static Predicate<BuildTarget> containsFlavors(FlavorDomain<?> domain) {
    return input -> {
        ImmutableSet<Flavor> flavorSet = Sets.intersection(domain.getFlavors(), input.getFlavors())
                .immutableCopy();//from   w  w w. j a v  a 2  s .  com
        return !flavorSet.isEmpty();
    };
}

From source file:th.algorithms.propinquitydynamics.utils.CalculationTable.java

public static Set<Integer> CalculateCii(Set<Integer> Nr, Set<Integer> Ni, Set<Integer> nnNr,
        Set<Integer> nnNi) {
    // (Nr + Ni) ^ (nnNr + nnNi)
    return Sets.intersection(Sets.union(Nr, Ni), Sets.union(nnNr, nnNi)).copyInto(new HashSet<Integer>(20));
}

From source file:org.bigwave.similarity.Shingle.java

public static float jaccard_similarity_coeff(Set<String> shinglesA, Set<String> shinglesB) {
    float neumerator = Sets.intersection(shinglesA, shinglesB).size();
    float denominator = Sets.union(shinglesA, shinglesB).size();
    return neumerator / denominator;
}

From source file:com.palantir.docker.compose.configuration.AdditionalEnvironmentValidator.java

public static Map<String, String> validate(Map<String, String> additionalEnvironment) {
    Set<String> invalidVariables = Sets.intersection(additionalEnvironment.keySet(), ILLEGAL_VARIABLES);
    String errorMessage = invalidVariables.stream().collect(Collectors.joining(", ",
            "The following variables: ",
            " cannot exist in your additional environment variable block as they will interfere with Docker."));
    checkState(invalidVariables.isEmpty(), errorMessage);
    return additionalEnvironment;
}

From source file:eu.lp0.cursus.scoring.scorer.FleetFilter.java

public static Predicate<Pilot> from(final Set<Class> classes) {
    if (classes.isEmpty()) {
        return Predicates.alwaysTrue();
    }//from w  ww.  j  a  va  2s . c o m

    return new Predicate<Pilot>() {
        @Override
        public boolean apply(@Nonnull Pilot pilot) {
            return !Sets.intersection(pilot.getClasses(), classes).isEmpty();
        }
    };
}

From source file:mtsar.api.csv.WorkerCSV.java

public static Iterator<Worker> parse(Stage stage, CSVParser csv) {
    final Set<String> header = csv.getHeaderMap().keySet();
    checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s",
            String.join(",", header));

    return StreamSupport.stream(csv.spliterator(), false).map(row -> {
        final String id = row.isSet("id") ? row.get("id") : null;
        final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags"))
                ? row.get("tags").split("\\|")
                : new String[0];
        final String datetime = row.isSet("datetime") ? row.get("datetime") : null;

        return new Worker.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id))
                .setStage(stage.getId()).addAllTags(Arrays.asList(tags))
                .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis()
                        : Long.parseLong(datetime) * 1000L))
                .build();//from  w w  w . j  a  v  a  2  s.  c o  m
    }).iterator();
}

From source file:com.handson.tools.InterSeptionTool.java

/**
 * Guava Library from : https://code.google.com/p/guava-libraries/
 * @param set// ww  w . jav  a2s.c o  m
 * @param set2
 * @return 
 */
public Set<String> beginInterception(Set<String> set, Set<String> set2) {

    Set<String> intersection = Sets.intersection(set, set2);

    return intersection;

}

From source file:de.flapdoodle.logparser.collections.Collections.java

public static <K, V> Map<K, V> join(Map<K, V> a, Map<K, V> b) {
    Map<K, V> ret = Maps.newHashMap(a);
    ret.putAll(b);//from  w  ww .j  a v  a2  s .co m
    if (ret.size() != a.size() + b.size()) {
        throw new IllegalArgumentException(
                "Map contains same keys: " + Sets.intersection(a.keySet(), b.keySet()));
    }
    return ret;
}

From source file:grakn.core.server.kb.concept.ConceptUtils.java

/**
 * @param schemaConcepts entry {@link SchemaConcept} set
 * @return top (most general) non-meta {@link SchemaConcept}s from within the provided set
 *///from  w  ww  .j  a  v a 2 s  .c  o  m
public static <T extends SchemaConcept> Set<T> top(Set<T> schemaConcepts) {
    return schemaConcepts.stream().filter(t -> Sets.intersection(nonMetaSups(t), schemaConcepts).isEmpty())
            .collect(toSet());
}

From source file:mtsar.api.csv.TaskCSV.java

public static Iterator<Task> parse(Stage stage, CSVParser csv) {
    final Set<String> header = csv.getHeaderMap().keySet();
    checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s",
            String.join(",", header));

    return StreamSupport.stream(csv.spliterator(), false).map(row -> {
        final String id = row.isSet("id") ? row.get("id") : null;
        final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags"))
                ? row.get("tags").split("\\|")
                : new String[0];
        final String type = row.get("type");
        final String description = row.isSet("description") ? row.get("description") : null;
        final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers"))
                ? row.get("answers").split("\\|")
                : new String[0];
        final String datetime = row.isSet("datetime") ? row.get("datetime") : null;

        return new Task.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id))
                .setStage(stage.getId()).addAllTags(Arrays.asList(tags))
                .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis()
                        : Long.parseLong(datetime) * 1000L))
                .setType(StringUtils.defaultIfEmpty(type, TaskDAO.TASK_TYPE_SINGLE)).setDescription(description)
                .addAllAnswers(Arrays.asList(answers)).build();
    }).iterator();/*from   w  w  w. j  av  a  2s .c o  m*/
}