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.palantir.atlasdb.keyvalue.impl.TieredKeyValueService.java

private TieredKeyValueService(Set<String> tieredTables, KeyValueService primary, KeyValueService secondary,
        ExecutorService executor) {
    Set<String> badTables = Sets.intersection(AtlasDbConstants.hiddenTables, tieredTables);
    Preconditions.checkArgument(badTables.isEmpty(), "The hidden tables %s cannot be tiered.", badTables);
    this.tieredTables = ImmutableSet.copyOf(tieredTables);
    this.primary = primary;
    this.secondary = secondary;
    this.executor = executor;
}

From source file:org.caleydo.view.tourguide.impl.Statistics.java

/**
 * computes the adjusted rand, see <a href="http://en.wikipedia.org/wiki/Rand_index">Rand_Index</a> in Wikipedia
 *
 * @param x//from   w  w w.j  av  a2 s. c  o m
 *            the collection of groups of the first stratification
 * @param y
 *            the collection of groups of the second stratification
 * @return its adjusted rand
 */
public static float adjustedRand(Collection<Set<Integer>> x, Collection<Set<Integer>> y) {
    // http://en.wikipedia.org/wiki/Rand_index
    // ARI = \frac{ \sum_{ij} \binom{n_{ij}}{2} - [\sum_i \binom{a_i}{2} \sum_j \binom{b_j}{2}] / \binom{n}{2} }{
    // \frac{1}{2} [\sum_i \binom{a_i}{2} + \sum_j \binom{b_j}{2}] - [\sum_i \binom{a_i}{2} \sum_j \binom{b_j}{2}] /
    // \binom{n}{2} }
    // where n_{ij}, a_i, b_j are values from the contingency table.

    int n = 0;
    int ais = 0;
    int bjs = 0;
    int nijs = 0;

    int bj[] = new int[y.size()];
    Arrays.fill(bj, 0);

    for (Set<Integer> xi : x) {
        int ai = 0;
        int j = 0;
        for (Set<Integer> yi : y) {
            int nij = Sets.intersection(xi, yi).size();
            ai += nij;
            nijs += binom2(nij);
            bj[j] += nij;
            j++;
        }
        ais += binom2(ai);
        n += xi.size();
    }
    for (int j = 0; j < bj.length; j++)
        bjs += binom2(bj[j]);

    float n2 = 1.f / binom2(n);

    float ari = (nijs - (ais * bjs) * n2) / (0.5f * (ais + bjs) - (ais * bjs) * n2);

    return ari;
}

From source file:edu.mit.streamjit.impl.blob.DrainData.java

/**
 * Merge this DrainData with the given DrainData object, appending any
 * channel data to the data in this DrainData (just as adding to a List
 * appends at the end)./*from ww  w. j av  a  2  s  .  com*/
 * @param other the DrainData to merge with
 * @return a merged DrainData
 */
public DrainData merge(DrainData other) {
    ImmutableMap.Builder<Token, ImmutableList<Object>> dataBuilder = ImmutableMap.builder();
    for (Token t : Sets.union(data.keySet(), other.data.keySet())) {
        ImmutableList<Object> us = getData(t) != null ? getData(t) : ImmutableList.of();
        ImmutableList<Object> them = other.getData(t) != null ? other.getData(t) : ImmutableList.of();
        dataBuilder.put(t, ImmutableList.builder().addAll(us).addAll(them).build());
    }

    if (!Sets.intersection(state.rowKeySet(), other.state.rowKeySet()).isEmpty())
        throw new IllegalArgumentException("bad merge: one worker's state split across DrainData");
    return new DrainData(dataBuilder.build(), CollectionUtils.union(state, other.state));
}

From source file:org.caleydo.view.domino.api.model.typed.TypedSet.java

private Set<Integer> intersectImpl(TypedSet that) {
    Set<Integer> r;//w  w w  .j a  v  a2s.  co  m
    if (this.size() < that.size()) { // smaller at the beginning
        r = Sets.intersection(that.wrappee, this.wrappee);
    } else
        r = Sets.intersection(this.wrappee, that.wrappee);
    return r;
}

From source file:eu.lp0.cursus.scoring.scores.impl.GenericOverallPenaltiesData.java

@Override
protected List<Penalty> calculateSimulatedOverallPenalties(Pilot pilot) {
    List<Penalty> penalties = new ArrayList<Penalty>(1);

    if (eventNonAttendancePenalty != 0) {
        for (Event event : lazyEventRaces.get().keySet()) {
            if (!event.getAttendees().contains(pilot) && Sets
                    .intersection(lazyEventRaces.get().get(event), pilot.getRaces().keySet()).isEmpty()) {
                penalties.add(new Penalty(Penalty.Type.EVENT_NON_ATTENDANCE, eventNonAttendancePenalty,
                        event.getName()));
            }//from   ww w. j  av a 2s.c  o  m
        }
    }

    for (int i = 0; i < eventNonAttendanceDiscards && i < penalties.size(); i++) {
        penalties.get(penalties.size() - (i + 1)).setValue(0);
    }

    return penalties;
}

From source file:org.gradle.internal.component.AmbiguousConfigurationSelectionException.java

static void formatConfiguration(StringBuilder sb, AttributeContainer fromConfigurationAttributes,
        AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, Set<String> requestedAttributes,
        int maxConfLength, final String conf) {
    Optional<ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() {
        @Override// w w w  .  j a va  2s  .  c  om
        public boolean apply(ConfigurationMetadata input) {
            return conf.equals(input.getName());
        }
    });
    if (match.isPresent()) {
        AttributeContainer producerAttributes = match.get().getAttributes();
        Set<Attribute<?>> targetAttributes = producerAttributes.keySet();
        Set<String> targetAttributeNames = Sets
                .newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME));
        Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(),
                producerAttributes.keySet());
        Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames);
        Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames);
        sb.append("   ").append("- Configuration '").append(StringUtils.rightPad(conf + "'", maxConfLength + 1))
                .append(" :");
        List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes);
        List<String> values = new ArrayList<String>(sortedAttributes.size());
        formatAttributes(sb, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes,
                consumerOnlyAttributes, sortedAttributes, values);
    }
}

From source file:gobblin.util.PullFileLoader.java

public PullFileLoader(Path rootDirectory, FileSystem fs, Collection<String> javaPropsPullFileExtensions,
        Collection<String> hoconPullFileExtensions) {

    Set<String> commonExtensions = Sets.intersection(Sets.newHashSet(javaPropsPullFileExtensions),
            Sets.newHashSet(hoconPullFileExtensions));
    Preconditions.checkArgument(commonExtensions.isEmpty(),
            "Java props and HOCON pull file extensions intersect: "
                    + Arrays.toString(commonExtensions.toArray()));

    this.rootDirectory = rootDirectory;
    this.fs = fs;
    this.javaPropsPullFileFilter = new ExtensionFilter(javaPropsPullFileExtensions);
    this.hoconPullFileFilter = new ExtensionFilter(hoconPullFileExtensions);
}

From source file:org.icgc.dcc.download.job.core.DefaultDownloadJob.java

private static Set<DownloadDataType> filterClinical(Set<DownloadDataType> dataTypes) {
    return Sets.intersection(CLINICAL, dataTypes);
}

From source file:org.dllearner.learningproblems.PosNegLPStrict.java

@Override
public ScorePosNeg computeScore(OWLClassExpression concept) {
    if (isUseRetrievalForClassification()) {
        SortedSet<OWLIndividual> posClassified = getReasoner().getIndividuals(concept);
        SortedSet<OWLIndividual> negClassified = getReasoner()
                .getIndividuals(dataFactory.getOWLObjectComplementOf(concept));
        Set<OWLIndividual> neutClassified = new TreeSet<>(
                Sets.intersection(getReasoner().getIndividuals(), posClassified));
        neutClassified.retainAll(negClassified);
        return new ScoreThreeValued(OWLClassExpressionUtils.getLength(concept), accuracyPenalty, errorPenalty,
                penaliseNeutralExamples, getPercentPerLengthUnit(), posClassified, neutClassified,
                negClassified, positiveExamples, neutralExamples, negativeExamples);
    } else {/*from  w  w  w  .ja va  2s  .c om*/
        if (getReasoner().getReasonerType().isOWLAPIReasoner()) {
            if (penaliseNeutralExamples)
                throw new Error("It does not make sense to use single instance checks when"
                        + "neutral examples are penalized. Use Retrievals instead.");

            // TODO: umschreiben in instance checks
            SortedSet<OWLIndividual> posClassified = new TreeSet<>();
            SortedSet<OWLIndividual> negClassified = new TreeSet<>();
            // Beispiele durchgehen
            // TODO: Implementierung ist ineffizient, da man hier schon in Klassen wie
            // posAsNeut, posAsNeg etc. einteilen koennte; so wird das extra in der Score-Klasse
            // gemacht; bei wichtigen Benchmarks des 3-wertigen Lernproblems muesste man das
            // umstellen
            // pos => pos
            for (OWLIndividual example : positiveExamples) {
                if (getReasoner().hasType(concept, example))
                    posClassified.add(example);
            }
            // neg => pos
            for (OWLIndividual example : negativeExamples) {
                if (getReasoner().hasType(concept, example))
                    posClassified.add(example);
            }

            OWLClassExpression negatedConcept = dataFactory.getOWLObjectComplementOf(concept);

            // pos => neg
            for (OWLIndividual example : positiveExamples) {
                if (getReasoner().hasType(negatedConcept, example))
                    negClassified.add(example);
            }
            // neg => neg
            for (OWLIndividual example : negativeExamples) {
                if (getReasoner().hasType(negatedConcept, example))
                    negClassified.add(example);
            }

            Set<OWLIndividual> neutClassified = new TreeSet<>(
                    Sets.intersection(getReasoner().getIndividuals(), posClassified));
            neutClassified.retainAll(negClassified);
            return new ScoreThreeValued(OWLClassExpressionUtils.getLength(concept), accuracyPenalty,
                    errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), posClassified,
                    neutClassified, negClassified, positiveExamples, neutralExamples, negativeExamples);
        } else
            throw new Error("score cannot be computed in this configuration");
    }
}

From source file:com.github.rinde.rinsim.core.model.DependencyResolver.java

void addDefaultModels() {
    for (final ModelBuilder<?, ?> b : defaultModels) {
        final ImmutableSet<Class<?>> providingTypes = b.getProvidingTypes();
        if (providingTypes.isEmpty() || !providerMap.keySet().containsAll(providingTypes)) {
            checkArgument(Sets.intersection(providerMap.keySet(), providingTypes).isEmpty());
            add(b);//from   ww  w  .  j  a v a 2s .  co m
        }
    }
}