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

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

Introduction

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

Prototype

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

Source Link

Document

Returns an unmodifiable view of the difference of two sets.

Usage

From source file:ai.grakn.graql.internal.gremlin.ConjunctionQuery.java

/**
 * @param patternConjunction a pattern containing no disjunctions to find in the graph
 *///w  w  w.j ava2s .  c  om
ConjunctionQuery(Conjunction<VarPatternAdmin> patternConjunction, GraknGraph graph) {
    vars = patternConjunction.getPatterns();

    if (vars.size() == 0) {
        throw GraqlQueryException.noPatterns();
    }

    ImmutableSet<EquivalentFragmentSet> fragmentSets = vars.stream()
            .flatMap(ConjunctionQuery::equivalentFragmentSetsRecursive).collect(toImmutableSet());

    // Get all variable names mentioned in non-starting fragments
    Set<Var> names = fragmentSets.stream().flatMap(EquivalentFragmentSet::stream)
            .filter(fragment -> !fragment.isStartingFragment())
            .flatMap(fragment -> fragment.getVariableNames().stream()).collect(toImmutableSet());

    // Get all dependencies fragments have on certain variables existing
    Set<Var> dependencies = fragmentSets.stream().flatMap(EquivalentFragmentSet::stream)
            .flatMap(fragment -> fragment.getDependencies().stream()).collect(toImmutableSet());

    Set<Var> validNames = Sets.difference(names, dependencies);

    // Filter out any non-essential starting fragments (because other fragments refer to their starting variable)
    Set<EquivalentFragmentSet> initialEquivalentFragmentSets = fragmentSets.stream()
            .filter(set -> set.stream().anyMatch(
                    fragment -> !fragment.isStartingFragment() || !validNames.contains(fragment.getStart())))
            .collect(toSet());

    // Apply final optimisations
    EquivalentFragmentSets.optimiseFragmentSets(initialEquivalentFragmentSets, graph);

    this.equivalentFragmentSets = ImmutableSet.copyOf(initialEquivalentFragmentSets);
}

From source file:com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacetEditor.java

@Override
public void apply() {
    if (appEngineStandardLibraryPanel.isEnabled()) {
        Set<AppEngineStandardMavenLibrary> savedLibs = facetConfiguration.getLibraries(context.getProject());
        Set<AppEngineStandardMavenLibrary> selectedLibs = appEngineStandardLibraryPanel.getSelectedLibraries();

        Set<AppEngineStandardMavenLibrary> libsToAdd = Sets.difference(selectedLibs, savedLibs);
        Set<AppEngineStandardMavenLibrary> libsToRemove = Sets.difference(savedLibs, selectedLibs);

        if (!libsToAdd.isEmpty()) {
            for (AppEngineStandardMavenLibrary library : libsToAdd) {
                MavenRepositoryLibraryDownloader.getInstance().downloadLibrary(context.getModule(), library);
            }//from   w  w  w .  jav a  2 s.c  o  m
        }

        if (!libsToRemove.isEmpty()) {
            AppEngineStandardSupportProvider.removeMavenLibraries(libsToRemove, context.getModule());
        }
    }
}

From source file:org.apache.druid.query.Queries.java

/**
 * Returns decorated post-aggregators, based on original un-decorated post-aggregators. In addition, this method
 * also verifies that there are no output name collisions, and that all of the post-aggregators' required input
 * fields are present.//from   w  ww.  j a v  a 2  s .  co m
 *
 * @param otherOutputNames names of fields that will appear in the same output namespace as aggregators and
 *                         post-aggregators, and are also assumed to be valid inputs to post-aggregators. For most
 *                         built-in query types, this is either empty, or the list of dimension output names.
 * @param aggFactories     aggregator factories for this query
 * @param postAggs         post-aggregators for this query
 *
 * @return decorated post-aggregators
 *
 * @throws NullPointerException     if otherOutputNames or aggFactories is null
 * @throws IllegalArgumentException if there are any output name collisions or missing post-aggregator inputs
 */
public static List<PostAggregator> prepareAggregations(List<String> otherOutputNames,
        List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) {
    Preconditions.checkNotNull(otherOutputNames, "otherOutputNames cannot be null");
    Preconditions.checkNotNull(aggFactories, "aggregations cannot be null");

    final Set<String> combinedOutputNames = new HashSet<>();
    combinedOutputNames.addAll(otherOutputNames);

    final Map<String, AggregatorFactory> aggsFactoryMap = new HashMap<>();
    for (AggregatorFactory aggFactory : aggFactories) {
        Preconditions.checkArgument(combinedOutputNames.add(aggFactory.getName()), "[%s] already defined",
                aggFactory.getName());
        aggsFactoryMap.put(aggFactory.getName(), aggFactory);
    }

    if (postAggs != null && !postAggs.isEmpty()) {
        List<PostAggregator> decorated = Lists.newArrayListWithExpectedSize(postAggs.size());
        for (final PostAggregator postAgg : postAggs) {
            final Set<String> dependencies = postAgg.getDependentFields();
            final Set<String> missing = Sets.difference(dependencies, combinedOutputNames);

            Preconditions.checkArgument(missing.isEmpty(), "Missing fields [%s] for postAggregator [%s]",
                    missing, postAgg.getName());
            Preconditions.checkArgument(combinedOutputNames.add(postAgg.getName()), "[%s] already defined",
                    postAgg.getName());

            decorated.add(postAgg.decorate(aggsFactoryMap));
        }
        return decorated;
    }

    return postAggs;
}

From source file:org.elasticlib.console.display.TreePrinter.java

private void addCurrentParents() {
    Set<Hash> parents = current.getParents();
    Set<Hash> known = Sets.intersection(parents, new HashSet<>(nextBranches));
    Set<Hash> unknown = Sets.difference(parents, known);
    nextBranches.addAll(known);//from w  w  w . j a v  a 2 s . co m
    nextBranches.addAll(unknown);
}

From source file:biz.ganttproject.impex.csv.RecordGroup.java

public void setHeader(List<String> header) {
    myHeader = header;
    myCustomFields = Sets.difference(Sets.newHashSet(header), myFields);
}

From source file:org.obiba.mica.study.service.HarmonizationStudyService.java

@Override
protected void saveInternal(final HarmonizationStudy study, String comment, boolean cascade) {
    log.info("Saving harmonization study: {}", study.getId());

    // checks if population and dce are still the same
    String studyId = study.getId();
    if (studyId != null) {
        List<String> list = populationsAffected(study, harmonizationStudyRepository.findOne(study.getId()));
        if (list != null && list.size() > 0) {
            checkPopulationMissingConstraints(studyId, list);
        }//from  ww w  .  ja  va  2 s  .co  m
    }

    if (study.getLogo() != null && study.getLogo().isJustUploaded()) {
        fileStoreService.save(study.getLogo().getId());
        study.getLogo().setJustUploaded(false);
    }

    ImmutableSet<String> invalidRoles = ImmutableSet.copyOf(Sets.difference(study.membershipRoles(),
            Sets.newHashSet(micaConfigService.getConfig().getRoles())));

    invalidRoles.forEach(study::removeRole);

    HarmonizationStudyState studyState = findEntityState(study, HarmonizationStudyState::new);

    if (!study.isNew())
        ensureGitRepository(studyState);

    studyState.incrementRevisionsAhead();
    harmonizationStudyStateRepository.save(studyState);

    study.setLastModifiedDate(DateTime.now());

    if (cascade)
        harmonizationStudyRepository.saveWithReferences(study);
    else
        harmonizationStudyRepository.save(study);

    gitService.save(study, comment);
    eventBus.post(new DraftStudyUpdatedEvent(study));
}

From source file:org.icgc.dcc.portal.model.UnionAnalysisRequest.java

public List<UnionUnit> toUnionSets() {

    val setSize = lists.size();
    val subsets = Sets.powerSet(this.lists);

    /*// w  w w .  j  a  v  a 2 s.c  o m
     * Used to remove the empty set and itself from the subsets.
     */
    val predicate = new Predicate<Collection<?>>() {

        @Override
        public boolean apply(Collection<?> s) {
            val size = s.size();
            return (size > 0) && (size < setSize);
        }
    };
    val filteredSubsets = Sets.filter(subsets, predicate);
    val resultSize = filteredSubsets.size();

    val result = new ArrayList<UnionUnit>(resultSize + 1);

    for (val subset : filteredSubsets) {
        val unionUnit = new UnionUnit(Sets.difference(this.lists, subset), subset);
        result.add(unionUnit);
    }
    result.add(UnionUnit.noExclusionInstance(this.lists));

    return result;
}

From source file:org.graylog2.indexer.esplugin.IndexChangeMonitor.java

private Set<String> calculateClosedIndices(ClusterState currentState, @Nullable ClusterState previousState) {
    if (previousState == null || previousState.metaData() == currentState.metaData()) {
        return Collections.emptySet();
    }/*w ww  .j  a v a2s  .  co m*/

    final Set<String> currentClosedIndices = getClosedIndices(currentState.getMetaData());
    final Set<String> previousClosedIndices = getClosedIndices(previousState.getMetaData());

    return Sets.difference(currentClosedIndices, previousClosedIndices);
}

From source file:org.apache.druid.segment.QueryableIndexStorageAdapter.java

@Override
public Iterable<String> getAvailableMetrics() {
    HashSet<String> columnNames = Sets.newHashSet(index.getColumnNames());
    return Sets.difference(columnNames, Sets.newHashSet(index.getAvailableDimensions()));
}

From source file:dagger2.internal.codegen.ModuleProcessingStep.java

@Override
public void process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
    // first, check and collect all provides methods
    ImmutableSet.Builder<ExecutableElement> validProvidesMethodsBuilder = ImmutableSet.builder();
    for (Element providesElement : elementsByAnnotation.get(Provides.class)) {
        if (providesElement.getKind().equals(METHOD)) {
            ExecutableElement providesMethodElement = (ExecutableElement) providesElement;
            ValidationReport<ExecutableElement> methodReport = providesMethodValidator
                    .validate(providesMethodElement);
            methodReport.printMessagesTo(messager);
            if (methodReport.isClean()) {
                validProvidesMethodsBuilder.add(providesMethodElement);
            }/*w  w w . ja  va2 s  .c om*/
        }
    }
    ImmutableSet<ExecutableElement> validProvidesMethods = validProvidesMethodsBuilder.build();

    // process each module
    for (Element moduleElement : Sets.difference(elementsByAnnotation.get(Module.class),
            processedModuleElements)) {
        ValidationReport<TypeElement> report = moduleValidator.validate(MoreElements.asType(moduleElement));
        report.printMessagesTo(messager);

        if (report.isClean()) {
            ImmutableSet.Builder<ExecutableElement> moduleProvidesMethodsBuilder = ImmutableSet.builder();
            List<ExecutableElement> moduleMethods = ElementFilter
                    .methodsIn(moduleElement.getEnclosedElements());
            for (ExecutableElement methodElement : moduleMethods) {
                if (isAnnotationPresent(methodElement, Provides.class)) {
                    moduleProvidesMethodsBuilder.add(methodElement);
                }
            }
            ImmutableSet<ExecutableElement> moduleProvidesMethods = moduleProvidesMethodsBuilder.build();

            if (Sets.difference(moduleProvidesMethods, validProvidesMethods).isEmpty()) {
                // all of the provides methods in this module are valid!
                // time to generate some factories!
                ImmutableSet<ProvisionBinding> bindings = FluentIterable.from(moduleProvidesMethods)
                        .transform(new Function<ExecutableElement, ProvisionBinding>() {
                            @Override
                            public ProvisionBinding apply(ExecutableElement providesMethod) {
                                return provisionBindingFactory.forProvidesMethod(providesMethod,
                                        providesMethod.getEnclosingElement().asType());
                            }
                        }).toSet();

                try {
                    for (ProvisionBinding binding : bindings) {
                        factoryGenerator.generate(binding);
                    }
                } catch (SourceFileGenerationException e) {
                    e.printMessageTo(messager);
                }
            }
        }
        processedModuleElements.add(moduleElement);
    }
}