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:edu.mit.streamjit.impl.common.ParallelCompositeStreamVisitor.java

private ImmutableSet<StreamVisitor> enabledVisitors() {
    return Sets.difference(visitors, ImmutableSet.copyOf(disabled.values())).immutableCopy();
}

From source file:com.atlassian.jira.license.DefaultLicenseRoleManager.java

@Override
public void setGroups(@Nonnull final LicenseRoleId licenseRoleId, @Nonnull final Iterable<String> groups) {
    Assertions.notNull("licenseRoleId", licenseRoleId);
    Assertions.containsNoNulls("groups", groups);

    final ImmutableSet<String> wantedGroups = ImmutableSet.copyOf(groups);
    final ImmutableSet<String> currentGroups = getGroupsFor(licenseRoleId);

    boolean invalidate = true;
    try {// w w  w .  ja  va  2  s .c  o m
        invalidate = addGroups(licenseRoleId, Sets.difference(wantedGroups, currentGroups))
                | removeGroups(licenseRoleId, Sets.difference(currentGroups, wantedGroups));
    } finally {
        //Invalid the cache even when a SQL error occurs.
        if (invalidate) {
            licenseRoleGroupsCache.invalidateCacheEntry(licenseRoleId);
        }
    }
}

From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java

public void remove(Actor a) {
    assert actors.contains(a) : a;
    actors = ImmutableSortedSet.copyOf(Sets.difference(actors, ImmutableSet.of(a)));
    schedule = ImmutableMap.copyOf(Maps.difference(schedule, ImmutableMap.of(a, 0)).entriesOnlyOnLeft());
}

From source file:org.apache.brooklyn.util.core.config.ResolvingConfigBag.java

@Override
protected ConfigBag copyWhileSynched(ConfigBag otherRaw) {
    if (otherRaw instanceof ResolvingConfigBag) {
        ResolvingConfigBag other = (ResolvingConfigBag) otherRaw;
        if (isSealed())
            throw new IllegalStateException("Cannot copy " + other + " to " + this
                    + ": this config bag has been sealed and is now immutable.");
        putAll(other.getAllConfigUntransformed());
        markAll(Sets.difference(other.getAllConfigUntransformed().keySet(),
                other.getUnusedConfigUntransformed().keySet()));
        setDescription(other.getDescription());
        return this;
    } else {//  w  ww  . j a  v  a 2 s .com
        return super.copyWhileSynched(otherRaw);
    }
}

From source file:io.fabric8.partition.internal.TaskHandler.java

@Override
public synchronized void nodeChanged() throws Exception {
    LOGGER.info("Task Handler for {} detected change.", context.getId());
    WorkerNode node = readWorkerNode();// w  w w  .  j  a  va 2 s .c om
    Set<WorkItem> workItems = listWorkItemsOfNode(node);
    Set<WorkItem> added = new LinkedHashSet<WorkItem>(Sets.difference(workItems, assignedWorkItems));
    Set<WorkItem> removed = new LinkedHashSet<WorkItem>(Sets.difference(assignedWorkItems, workItems));
    assignedWorkItems.addAll(added);
    assignedWorkItems.removeAll(removed);
    LOGGER.info("Releasing work items: {}.", removed.toArray());
    worker.release(context, removed);
    LOGGER.info("Assigning work items: {}.", added.toArray());
    worker.assign(context, added);
}

From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparer.java

private FixObjectCompareResult checkDirFileList(Map<String, FixFsObject> expectedChldrn,
        Map<String, FixFsObject> actualChldrn) {
    Set<String> expectedDiff = Sets.difference(expectedChldrn.keySet(), actualChldrn.keySet());
    Set<String> actualDiff = Sets.difference(actualChldrn.keySet(), expectedChldrn.keySet());

    List<String> filesWithDifferentTypes = Lists.newArrayList();
    for (String key : Sets.intersection(expectedChldrn.keySet(), actualChldrn.keySet())) {
        FixFsObject expected = expectedChldrn.get(key);
        FixFsObject actual = actualChldrn.get(key);
        if (expected.isFile() != actual.isFile()) {
            String message = getWrongTypeDesc(key, expected, actual);
            filesWithDifferentTypes.add(message);
        }//from   ww  w . j  av a 2  s . c om
    }

    if (expectedDiff.isEmpty() && actualDiff.isEmpty() && filesWithDifferentTypes.isEmpty()) {
        return FixObjectCompareResult.SUCCESS;
    } else {
        StrBuilder strBuilder = new StrBuilder();
        appendMessages(expectedDiff, strBuilder, "Files found only in expected set: ");
        appendMessages(actualDiff, strBuilder, "Files found only in result set: ");
        appendMessages(filesWithDifferentTypes, strBuilder, "Files have different types: ");
        return FixObjectCompareResult.failed(strBuilder.toString());
    }
}

From source file:co.cask.cdap.security.authorization.InMemoryAuthorizer.java

@Override
public void enforce(EntityId entity, Principal principal, Set<Action> actions) throws UnauthorizedException {
    // super users do not have any enforcement
    if (superUsers.contains(principal) || superUsers.contains(allSuperUsers)) {
        return;/*from   w ww.  j  av  a2s  .  co  m*/
    }
    // actions allowed for this principal
    Set<Action> allowed = getActions(entity, principal);
    if (allowed.containsAll(actions)) {
        return;
    }
    Set<Action> allowedForRoles = new HashSet<>();
    // actions allowed for any of the roles to which this principal belongs if its not a role
    if (principal.getType() != Principal.PrincipalType.ROLE) {
        for (Role role : getRoles(principal)) {
            allowedForRoles.addAll(getActions(entity, role));
        }
    }
    if (!allowedForRoles.containsAll(actions)) {
        throw new UnauthorizedException(principal, Sets.difference(actions, allowed), entity);
    }
}

From source file:com.google.errorprone.bugpatterns.threadsafety.ImmutableChecker.java

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
    ImmutableAnalysis analysis = new ImmutableAnalysis(this, state,
            "@Immutable classes cannot have non-final fields", "@Immutable class has mutable field");
    if (tree.getSimpleName().length() == 0) {
        // anonymous classes have empty names
        // TODO(cushon): once Java 8 happens, require @Immutable on anonymous classes
        return handleAnonymousClass(tree, state, analysis);
    }//from   w  ww. ja  v  a2s. c  om

    ImmutableAnnotationInfo annotation = getImmutableAnnotation(tree);
    if (annotation == null) {
        // If the type isn't annotated we don't check for immutability, but we do
        // report an error if it extends/implements any @Immutable-annotated types.
        return checkSubtype(tree, state);
    }

    // Special-case visiting declarations of known-immutable types; these uses
    // of the annotation are "trusted".
    if (WellKnownMutability.KNOWN_IMMUTABLE.containsValue(annotation)) {
        return Description.NO_MATCH;
    }

    // Check that the types in containerOf actually exist
    Set<String> typarams = new HashSet<>();
    for (TypeParameterTree typaram : tree.getTypeParameters()) {
        typarams.add(typaram.getName().toString());
    }
    SetView<String> difference = Sets.difference(annotation.containerOf(), typarams);
    if (!difference.isEmpty()) {
        String message = String.format("could not find type(s) referenced by containerOf: %s",
                Joiner.on("', '").join(difference));
        return buildDescription(tree).setMessage(message).build();
    }

    // Main path for @Immutable-annotated types:
    //
    // Check that the fields (including inherited fields) are immutable, and
    // validate the type hierarchy superclass.

    Violation info = analysis.checkForImmutability(Optional.of(tree),
            immutableTypeParametersInScope(ASTHelpers.getSymbol(tree)), ASTHelpers.getType(tree));

    if (!info.isPresent()) {
        return Description.NO_MATCH;
    }

    String message = "type annotated with @Immutable could not be proven immutable: " + info.message();
    return buildDescription(tree).setMessage(message).build();
}

From source file:com.torodb.torod.db.backends.mysql.converters.json.MySQLValueToJsonConverterProvider.java

private MySQLValueToJsonConverterProvider() {
    converters = Maps.newEnumMap(ScalarType.class);
    converters.put(ScalarType.ARRAY,/* w  ww .  ja  v a  2s  .  c o  m*/
            new ArrayValueToJsonConverter(MySQLValueToArrayConverterProvider.getInstance()));
    converters.put(ScalarType.BOOLEAN, new BooleanValueToJsonConverter());
    converters.put(ScalarType.DATE, new DateValueToJsonConverter());
    converters.put(ScalarType.INSTANT, new InstantValueToJsonConverter());
    converters.put(ScalarType.DOUBLE, new DoubleValueToJsonConverter());
    converters.put(ScalarType.INTEGER, new IntegerValueToJsonConverter());
    converters.put(ScalarType.LONG, new LongValueToJsonConverter());
    converters.put(ScalarType.NULL, new NullValueToJsonConverter());
    converters.put(ScalarType.STRING, new StringValueToJsonConverter());
    converters.put(ScalarType.TIME, new TimeValueToJsonConverter());
    converters.put(ScalarType.MONGO_OBJECT_ID, new MongoObjectIdValueToJsonConverter());
    converters.put(ScalarType.MONGO_TIMESTAMP, new MongoTimestampValueToJsonConverter());
    converters.put(ScalarType.BINARY, new BinaryValueToJsonConverter());

    SetView<ScalarType> withoutConverter = Sets.difference(converters.keySet(), SUPPORTED_TYPES);
    if (!withoutConverter.isEmpty()) {
        throw new AssertionError("It is not defined how to convert from the following scalar "
                + "types to json: " + withoutConverter);
    }
}

From source file:org.apache.aurora.scheduler.updater.JobDiff.java

/**
 * Gets instances contained in a {@code scope} that are not a part of the job diff.
 *
 * @param scope Scope to search within.//from   ww  w .j  a v a  2s .  c  o m
 * @return Instance IDs in {@code scope} that are not in this job diff.
 */
public Set<Integer> getOutOfScopeInstances(Set<Integer> scope) {
    Set<Integer> allValidInstances = ImmutableSet.<Integer>builder().addAll(getReplacedInstances().keySet())
            .addAll(getReplacementInstances()).addAll(getUnchangedInstances().keySet()).build();
    return ImmutableSet.copyOf(Sets.difference(scope, allValidInstances));
}