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.obm.push.mail.EmailSync.java

@Override
public MailChanges getSync(StoreClient imapStore, Integer devId, SyncState state, Integer collectionId)
        throws DaoException {
    Set<Email> emailsFromIMAP = getImapEmails(imapStore, state.getLastSync());
    Set<Email> alreadySyncedEmails = emailDao.alreadySyncedEmails(collectionId, devId, emailsFromIMAP);
    Set<Email> emailsToSync = Sets.difference(emailsFromIMAP, alreadySyncedEmails);
    MailChanges mailChanges = new MailChanges(new HashSet<Email>(), emailsToSync, emailsFromIMAP);
    loggerInfo(state.getLastSync(), emailsFromIMAP, mailChanges);
    return mailChanges;
}

From source file:eu.trentorise.opendata.semantics.exceptions.OpenEntityNotFoundException.java

public static Set<String> missingIds(Iterable<String> expectedIds, Iterable<String> foundIds) {
    Set expectedIdsSet = Sets.newHashSet(expectedIds);
    Set foundIdsSet = Sets.newHashSet(foundIds);

    if (expectedIdsSet.size() <= foundIdsSet.size()) {
        LOG.severe(" EXPECTED DIFFERENT IDs ARE " + expectedIdsSet.size()
                + ", WHICH IS LESS OR EQUAL THAN FOUND DIFFERENT IDs: " + foundIdsSet.size()
                + ", IGNORING THEM!");
        return new HashSet();
    }//w  w w .  ja v  a  2s  .  c  om

    SetView<String> difference = Sets.difference(expectedIdsSet, foundIdsSet);

    return difference;
}

From source file:org.onosproject.net.optical.device.FilteredAnnotation.java

@Override
public Set<String> keys() {
    return Sets.difference(delegate.keys(), filtered);
}

From source file:org.opendaylight.netvirt.sfc.classifier.service.domain.impl.ClassifierUpdate.java

@Override
public void run() {
    Set<ClassifierRenderableEntry> configurationEntries = configurationClassifier.getAllEntries();
    Set<ClassifierRenderableEntry> operationalEntries = operationalClassifier.getAllEntries();
    Set<ClassifierRenderableEntry> entriesToAdd = Sets.difference(configurationEntries, operationalEntries);
    Set<ClassifierRenderableEntry> entriesToRemove = Sets.difference(operationalEntries, configurationEntries);

    LOG.trace("Configuration entries: {}", configurationEntries);
    LOG.trace("Operational entries: {}", operationalEntries);
    LOG.trace("Entries to add: {}", entriesToAdd);
    LOG.trace("Entries to remove: {}", entriesToRemove);

    classifierRenderers.forEach(classifierRenderer -> {
        entriesToAdd.forEach(classifierRenderableEntry -> classifierRenderableEntry.render(classifierRenderer));
        entriesToRemove//from   w ww .  j a  v a2  s . c  o m
                .forEach(classifierRenderableEntry -> classifierRenderableEntry.suppress(classifierRenderer));
    });
}

From source file:tiger.TreeScopeSizer.java

public TreeScopeSizer(Map<ComponentInfo, ComponentInfo> scopeTree, @Nullable ComponentInfo rootComponentInfo) {
    this.scopeTree = scopeTree;
    if (!scopeTree.isEmpty()) {
        rootComponentInfo = Iterables/*from  w  w  w  . ja va2  s . c om*/
                .getOnlyElement(Sets.difference(Sets.newHashSet(scopeTree.values()), scopeTree.keySet()));
    } else {
        Preconditions.checkNotNull(rootComponentInfo);
    }
    scopeToDepthMap.put(rootComponentInfo, 0);
    largestScope = rootComponentInfo;
    for (ComponentInfo componentInfo : scopeTree.keySet()) {
        int depth = findTreeNodeDepth(scopeTree, componentInfo);
        scopeToDepthMap.put(componentInfo, depth);
    }

    int depth = 0;
    for (Map.Entry<ComponentInfo, Integer> entry : scopeToDepthMap.entrySet()) {
        int value = entry.getValue();
        if (value > depth) {
            depth = value;
        }
    }
    largestSize = depth;
    System.out.println(String.format("scopeTree: %s", scopeTree));
    System.out.println(String.format("scopeToDepthMap: %s", scopeToDepthMap));
}

From source file:com.facebook.buck.graph.DirectedAcyclicGraph.java

@Override
public ImmutableSet<T> getNodesWithNoOutgoingEdges() {
    return ImmutableSet.copyOf(Sets.difference(nodes, outgoingEdges.keySet()));
}

From source file:forms.api.FormMarkup.java

public RockerRaw closeForm() {
    // check that all fields have been used
    SetView<String> unused = Sets.difference(def.fieldNames(), usedFields);
    SetView<String> unknown = Sets.difference(usedFields, def.fieldNames());
    Preconditions.checkState(unused.isEmpty() && unknown.isEmpty(), "unused=%s unknown=%s", unused, unknown);

    return new RockerRaw()
            // CSRF
            .appendRaw("<input").appendAttr("type", "hidden", "name", CSRF_FIELD, "value", "TODO")
            .appendRaw(">").appendRaw("</input>\n")
            // then close the form
            .appendRaw("</form>\n");
}

From source file:com.continuuity.loom.admin.ParametersSpecification.java

public ParametersSpecification(Map<String, FieldSchema> fields, Set<Set<String>> required) {
    this.fields = fields == null ? ImmutableMap.<String, FieldSchema>of() : fields;
    this.required = required == null ? ImmutableSet.<Set<String>>of() : required;
    Set<String> flattenedRequires = Sets.newHashSet();
    for (Set<String> requiredSet : this.required) {
        flattenedRequires.addAll(requiredSet);
    }//from   w  ww. j a  v a 2s  .  c  o m
    Set<String> badRequires = Sets.difference(flattenedRequires, this.fields.keySet());
    if (badRequires.size() > 0) {
        String badRequiresStr = Joiner.on(',').join(badRequires);
        throw new IllegalArgumentException(badRequiresStr + " specified as required, but are not fields.");
    }
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.departmentAdmOffice.UpdateDepartmentsCompetenceCourseManagementGroup.java

private static void updateBolonhaManagerRoleToGroupDelta(Department department, Group original, Group changed) {
    Set<User> originalMembers = original.getMembers();
    Set<User> newMembers = changed.getMembers();
    for (User user : Sets.difference(originalMembers, newMembers)) {
        Person person = user.getPerson();
        if (person.hasRole(RoleType.BOLONHA_MANAGER) && !belongsToOtherGroupsWithSameRole(department, person)) {
            person.removeRoleByType(RoleType.BOLONHA_MANAGER);
        }//from  ww w .  ja  v  a 2s  . c  o  m
    }
    Role bolonhaRole = Role.getRoleByRoleType(RoleType.BOLONHA_MANAGER);
    for (User user : Sets.difference(newMembers, originalMembers)) {
        Person person = user.getPerson();
        if (!person.hasRole(RoleType.BOLONHA_MANAGER)) {
            person.addPersonRoles(bolonhaRole);
        }
    }
}

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

@Override
public TypedGroupSet asSet() {
    //more difficult to convert a group to a set, since duplicates in different groups may occur
    Set<Integer> acc = new BitSetSet();
    List<TypedSetGroup> groups = new ArrayList<>();
    for (TypedListGroup g : getGroups()) {
        TypedSetGroup s = g.asSet();/* w  w w  .jav a2  s  .c o m*/
        if (!acc.isEmpty()) {
            s = new TypedSetGroup(ImmutableSet.copyOf(Sets.difference(s, acc)), s.getIdType(), s.getLabel(),
                    s.getColor());
        }
        if (s.isEmpty())
            continue;
        acc.addAll(s);
        groups.add(s);
    }
    if (groups.isEmpty())
        return new TypedGroupSet(TypedGroups.createUngroupedGroup(TypedCollections.empty(getIdType())));
    return new TypedGroupSet(groups);
}