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:org.obiba.mica.dataset.search.rest.harmonization.ContingencyUtils.java

public static List<String> getTermsHeaders(DatasetVariable variable, Mica.DatasetVariableContingenciesDto dto) {
    List<String> dtoTerms = Lists.newArrayList(dto.getContingenciesList().stream()
            .flatMap(c -> c.getAggregationsList().stream()).map(a -> a.getTerm()).collect(toSet()));
    List<String> terms = variable.getCategories() != null
            ? variable.getCategories().stream().map(c -> c.getName()).collect(toList())
            : Lists.newArrayList();/*from  w ww  . ja  v a2  s .  c  o  m*/
    terms.addAll(Sets.difference(Sets.newHashSet(dtoTerms), Sets.newHashSet(terms)));

    return terms;
}

From source file:com.github.naios.wide.api.util.Flags.java

public static <T extends Enum<?>> void calculateDifferenceTo(final Class<T> enumClass, final int oldMask,
        final int newMask, final Collection<T> add, final Collection<T> remove) {
    final Set<T> currentFlags = Flags.flagSet(enumClass, newMask);
    final Set<T> oldFlags = Flags.flagSet(enumClass, oldMask);

    add.addAll(Sets.difference(currentFlags, oldFlags));
    remove.addAll(Sets.difference(oldFlags, currentFlags));
}

From source file:io.druid.query.Queries.java

public static void verifyAggregations(List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) {
    Preconditions.checkNotNull(aggFactories, "aggregations cannot be null");
    Preconditions.checkArgument(aggFactories.size() > 0, "Must have at least one AggregatorFactory");

    final Set<String> aggNames = Sets.newHashSet();
    for (AggregatorFactory aggFactory : aggFactories) {
        Preconditions.checkArgument(aggNames.add(aggFactory.getName()), "[%s] already defined",
                aggFactory.getName());/*from   ww w.j av  a2 s  .  c  o m*/
    }

    if (postAggs != null && !postAggs.isEmpty()) {
        final Set<String> combinedAggNames = Sets.newHashSet(aggNames);

        for (PostAggregator postAgg : postAggs) {
            final Set<String> dependencies = postAgg.getDependentFields();
            final Set<String> missing = Sets.difference(dependencies, combinedAggNames);

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

From source file:org.apache.atlas.repository.impexp.ImportServiceTestUtils.java

public static void verifyImportedEntities(List<String> creationOrder, List<String> processedEntities) {
    Set<String> lhs = com.google.common.collect.Sets.newHashSet(creationOrder);
    Set<String> rhs = com.google.common.collect.Sets.newHashSet(processedEntities);
    Set<String> difference = Sets.difference(lhs, rhs);

    Assert.assertNotNull(difference);//from  www. ja  v a  2 s. c  o  m
    Assert.assertEquals(difference.size(), 0);
}

From source file:com.facebook.buck.testutil.MoreAsserts.java

/**
 * Asserts that two sets have the same contents.
 * On failure, prints a readable diff of the two sets for easy debugging.
 *//*from w  w w. j av  a  2 s .  c  om*/
public static <E> void assertSetEquals(Set<E> expected, Set<E> actual) {
    Set<E> missing = Sets.difference(expected, actual);
    Set<E> extra = Sets.difference(actual, expected);
    boolean setsEqual = missing.isEmpty() && extra.isEmpty();
    Assert.assertTrue(String.format("%nMissing elements:%n%s%nExtraneous elements:%n%s", missing, extra),
            setsEqual);
}

From source file:org.obiba.mica.dataset.search.rest.harmonization.ContingencyUtils.java

public static List<String> getTermsHeaders(DatasetVariable variable, Mica.DatasetVariableContingencyDto dto) {
    List<String> terms = variable.getCategories() != null
            ? variable.getCategories().stream().map(c -> c.getName()).collect(toList())
            : Lists.newArrayList();//  ww w .j  a  v  a 2  s  .c o m
    List<String> dtoTerms = dto.getAggregationsList().stream().map(a -> a.getTerm())
            .collect(Collectors.toList());
    terms.addAll(Sets.difference(Sets.newHashSet(dtoTerms), Sets.newHashSet(terms)));

    return terms;
}

From source file:org.apache.druid.collections.IntSetTestUtility.java

public static Boolean equalSets(Set<Integer> s1, ImmutableBitmap s2) {
    Set<Integer> s3 = new HashSet<>();
    for (Integer i : new IntIt(s2.iterator())) {
        s3.add(i);/*from   w  w  w  .  jav a  2 s.co  m*/
    }
    return Sets.difference(s1, s3).isEmpty();
}

From source file:com.metamx.druid.query.Queries.java

public static void verifyAggregations(List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) {
    Preconditions.checkNotNull(aggFactories, "aggregations cannot be null");
    Preconditions.checkArgument(aggFactories.size() > 0, "Must have at least one AggregatorFactory");

    if (postAggs != null && !postAggs.isEmpty()) {
        Set<String> combinedAggNames = Sets
                .newHashSet(Lists.transform(aggFactories, new Function<AggregatorFactory, String>() {
                    @Override/*  ww w . j  a  v  a 2 s .c om*/
                    public String apply(@Nullable AggregatorFactory input) {
                        return input.getName();
                    }
                }));

        for (PostAggregator postAgg : postAggs) {
            Set<String> dependencies = postAgg.getDependentFields();
            Set<String> missing = Sets.difference(dependencies, combinedAggNames);

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

From source file:com.facebook.buck.jvm.java.DefaultSuggestBuildRules.java

/**
 * @return A function that takes a list of failed imports from a javac invocation and returns a
 *    set of rules to suggest that the developer import to satisfy those imports.
 *//*from  w  w  w.j  a v  a2 s.  c  om*/
static SuggestBuildRules createSuggestBuildFunction(final JarResolver jarResolver,
        final ImmutableSet<JavaLibrary> declaredDeps, final ImmutableSet<JavaLibrary> transitiveDeps,
        final Iterable<BuildRule> buildRules) {

    final Supplier<ImmutableList<JavaLibrary>> sortedTransitiveNotDeclaredDeps = Suppliers
            .memoize(new Supplier<ImmutableList<JavaLibrary>>() {
                @Override
                public ImmutableList<JavaLibrary> get() {
                    Set<JavaLibrary> transitiveNotDeclaredDeps = Sets.difference(transitiveDeps,
                            Sets.union(ImmutableSet.of(this), declaredDeps));
                    DirectedAcyclicGraph<BuildRule> graph = BuildRuleDependencyVisitors
                            .getBuildRuleDirectedGraphFilteredBy(buildRules, JavaLibrary.class::isInstance,
                                    JavaLibrary.class::isInstance);
                    return FluentIterable.from(TopologicalSort.sort(graph)).filter(JavaLibrary.class)
                            .filter(transitiveNotDeclaredDeps::contains).toList().reverse();
                }
            });

    return new DefaultSuggestBuildRules(sortedTransitiveNotDeclaredDeps, jarResolver);
}

From source file:com.netflix.exhibitor.core.config.RollingHostNamesBuilder.java

RollingHostNamesBuilder(InstanceConfig rootConfig, InstanceConfig rollingConfig, String leaderHostname) {
    ServerList rootServers = new ServerList(rootConfig.getString(StringConfigs.SERVERS_SPEC));
    ServerList rollingServers = new ServerList(rollingConfig.getString(StringConfigs.SERVERS_SPEC));

    Set<String> newServers = Sets.difference(Sets.newTreeSet(rollingServers.getHostnames()),
            Sets.newTreeSet(rootServers.getHostnames()));
    Set<String> unchangedServers = Sets.intersection(Sets.newTreeSet(rollingServers.getHostnames()),
            Sets.newTreeSet(rootServers.getHostnames()));

    ImmutableList.Builder<String> builder = ImmutableList.builder();
    builder.addAll(newServers); // new servers need to be started first as the others will try to communicate with them. You may have issues if there is more than 1 new server
    if ((leaderHostname != null) && unchangedServers.contains(leaderHostname)) {
        Set<String> allButLeader = Sets.difference(unchangedServers, Sets.newHashSet(leaderHostname));
        builder.addAll(allButLeader); // the servers that are staying in the cluster can be restarted next.
        builder.add(leaderHostname); // restart the leader last in the hopes of keeping quorum as long as possible
    } else {/* w  ww  .j a  v  a 2  s.com*/
        builder.addAll(unchangedServers); // the servers that are staying in the cluster can be restarted next.
    }
    rollingHostNames = builder.build(); // servers coming out of the cluster can be restarted all at once at the end (assuming they still exist)
}