Example usage for com.google.common.collect Iterables removeAll

List of usage examples for com.google.common.collect Iterables removeAll

Introduction

In this page you can find the example usage for com.google.common.collect Iterables removeAll.

Prototype

public static boolean removeAll(Iterable<?> removeFrom, Collection<?> elementsToRemove) 

Source Link

Document

Removes, from an iterable, every element that belongs to the provided collection.

Usage

From source file:org.eclipse.xtext.ide.server.BuildManager.java

protected void queue(final Set<URI> files, final Collection<URI> toRemove, final Collection<URI> toAdd) {
    Iterables.removeAll(files, toRemove);
    Iterables.<URI>addAll(files, toAdd);
}

From source file:org.eclipse.sirius.diagram.ui.business.api.helper.graphicalfilters.CompositeFilterApplicationBuilder.java

private void updateFilterApplication(DDiagramElement element, AppliedCompositeFilters filterApplication,
        List<CompositeFilterDescription> appliedFilters) {
    if (element != null && filterApplication != null && appliedFilters != null) {
        if (appliedFilters.isEmpty()) {
            element.getGraphicalFilters().remove(filterApplication);
        } else {// www.  j  a  va2 s.com
            Collection<CompositeFilterDescription> filterToAdd = Lists.newArrayList(appliedFilters);
            Iterables.removeAll(filterToAdd, filterApplication.getCompositeFilterDescriptions());

            Collection<CompositeFilterDescription> filterToRemove = Lists
                    .newArrayList(filterApplication.getCompositeFilterDescriptions());
            Iterables.removeAll(filterToRemove, appliedFilters);

            filterApplication.getCompositeFilterDescriptions().removeAll(filterToRemove);
            filterApplication.getCompositeFilterDescriptions().addAll(filterToAdd);
        }
    }
}

From source file:org.eclipse.sirius.diagram.ui.business.internal.command.SiriusSetConnectionAnchorsCommand.java

@SuppressWarnings("unchecked")
private Edge getEdge() {
    Edge edge = null;/*from   w w  w.ja va 2 s .c  om*/
    if (reconnectionKind == ReconnectionKind.RECONNECT_SOURCE_LITERAL) {
        final List<Edge> sourceEdges = new ArrayList<Edge>(reconnectionTarget.getSourceEdges());
        Iterables.removeAll(sourceEdges, reconnectionTargetEdges);
        Predicate<Edge> notToReconnectingEdge = new Predicate<Edge>() {

            public boolean apply(Edge input) {
                return !sourceEdges.contains(input.getTarget());
            }
        };
        // For case with reconnect edge source from borderedNode to
        // borderedNode
        // when borderedNode is mapping with EReference
        if (sourceEdges.isEmpty() && reconnectionTarget.getElement() instanceof AbstractDNode) {
            AbstractDNode abstractDNode = (AbstractDNode) reconnectionTarget.getElement();
            List<DNode> borderedNodes = abstractDNode.getOwnedBorderedNodes();
            if (!borderedNodes.isEmpty()) {
                DNode borderedNode = borderedNodes.get(borderedNodes.size() - 1);
                Collection<EObject> inverseReferences = new EObjectQuery(borderedNode)
                        .getInverseReferences(NotationPackage.eINSTANCE.getView_Element());
                Node nodeSource = Iterables.getOnlyElement(Iterables.filter(inverseReferences, Node.class));
                List<Edge> sourceEdgesOfBorderedNode = new ArrayList<Edge>(nodeSource.getSourceEdges());
                edge = Iterables
                        .getOnlyElement(Iterables.filter(sourceEdgesOfBorderedNode, notToReconnectingEdge));
            }
        } else {
            edge = Iterables.getOnlyElement(Iterables.filter(sourceEdges, notToReconnectingEdge));
        }
    } else {
        final List<Edge> targetEdges = new ArrayList<Edge>(reconnectionTarget.getTargetEdges());
        Iterables.removeAll(targetEdges, reconnectionTargetEdges);
        Predicate<Edge> notFromReconnectingEdge = new Predicate<Edge>() {

            public boolean apply(Edge input) {
                return !targetEdges.contains(input.getSource());
            }
        };
        // For case with reconnect edge target from borderedNode to
        // borderedNode
        // when borderedNode is mapping with EReference
        if (targetEdges.isEmpty() && reconnectionTarget.getElement() instanceof AbstractDNode) {
            AbstractDNode abstractDNode = (AbstractDNode) reconnectionTarget.getElement();
            List<DNode> borderedNodes = abstractDNode.getOwnedBorderedNodes();
            if (!borderedNodes.isEmpty()) {
                DNode borderedNode = borderedNodes.get(borderedNodes.size() - 1);
                Collection<EObject> inverseReferences = new EObjectQuery(borderedNode)
                        .getInverseReferences(NotationPackage.eINSTANCE.getView_Element());
                Node nodeTarget = Iterables.getOnlyElement(Iterables.filter(inverseReferences, Node.class));
                List<Edge> targetEdgesOfBorderedNode = new ArrayList<Edge>(nodeTarget.getTargetEdges());
                edge = Iterables
                        .getOnlyElement(Iterables.filter(targetEdgesOfBorderedNode, notFromReconnectingEdge));
            }
        } else {
            edge = Iterables.getOnlyElement(Iterables.filter(targetEdges, notFromReconnectingEdge));
        }
    }
    return edge;
}

From source file:org.eclipse.xtext.ide.server.BuildManager.java

protected List<IResourceDescription.Delta> internalBuild(final CancelIndicator cancelIndicator) {
    final ArrayList<URI> allDirty = new ArrayList<URI>(this.dirtyFiles);
    final HashMultimap<ProjectDescription, URI> project2dirty = HashMultimap.<ProjectDescription, URI>create();
    for (final URI dirty : allDirty) {
        {//from  w  w  w  . j a va  2 s.c  om
            final ProjectDescription projectManager = this.workspaceManager.getProjectManager(dirty)
                    .getProjectDescription();
            project2dirty.put(projectManager, dirty);
        }
    }
    final HashMultimap<ProjectDescription, URI> project2deleted = HashMultimap
            .<ProjectDescription, URI>create();
    for (final URI deleted : this.deletedFiles) {
        {
            final ProjectDescription projectManager = this.workspaceManager.getProjectManager(deleted)
                    .getProjectDescription();
            project2deleted.put(projectManager, deleted);
        }
    }
    Set<ProjectDescription> _keySet = project2dirty.keySet();
    Set<ProjectDescription> _keySet_1 = project2deleted.keySet();
    Iterable<ProjectDescription> _plus = Iterables.<ProjectDescription>concat(_keySet, _keySet_1);
    final List<ProjectDescription> sortedDescriptions = this.sortByDependencies(_plus);
    final ArrayList<IResourceDescription.Delta> result = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
    for (final ProjectDescription it : sortedDescriptions) {
        {
            final ProjectManager projectManager = this.workspaceManager.getProjectManager(it.getName());
            final List<URI> projectDirty = IterableExtensions.<URI>toList(project2dirty.get(it));
            final List<URI> projectDeleted = IterableExtensions.<URI>toList(project2deleted.get(it));
            final IncrementalBuilder.Result partialResult = projectManager.doBuild(projectDirty, projectDeleted,
                    result, cancelIndicator);
            final Function1<IResourceDescription.Delta, URI> _function = (IResourceDescription.Delta it_1) -> {
                return it_1.getUri();
            };
            allDirty.addAll(ListExtensions.<IResourceDescription.Delta, URI>map(
                    partialResult.getAffectedResources(), _function));
            Iterables.removeAll(this.dirtyFiles, projectDirty);
            Iterables.removeAll(this.deletedFiles, projectDeleted);
            result.addAll(partialResult.getAffectedResources());
        }
    }
    return result;
}

From source file:org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.DifferenceGroupManager.java

/**
 * Returns an ordered list of {@link IItemDescriptor}. The order of the list is either defined by the rank
 * in the registry or from preference if the rank has been overloaded. If any descriptor has been added or
 * removed since last modification of the preference, this method will merge the modification.
 * /*w w w  . java  2s  .  c o m*/
 * @param orderedDefaultDescriptor
 *            List of ordered default {@link IItemDescriptor}.
 * @param descriptorRegistry
 *            Registry of descriptor.
 * @param orderedItemPreferenceKey
 *            Key in preferences where are stored the new order of descriptor
 * @return Ordered list of descriptor.
 * @param <T>
 *            Descriptor type.
 */
private <T> List<IItemDescriptor<T>> getOrderedItems(List<IItemDescriptor<T>> orderedDefaultDescriptor,
        IItemRegistry<T> descriptorRegistry, String orderedItemPreferenceKey) {
    List<IItemDescriptor<T>> itemsDescriptor = ItemUtil.getItemsDescriptor(descriptorRegistry,
            orderedItemPreferenceKey, preferences);

    if (itemsDescriptor == null) {
        itemsDescriptor = orderedDefaultDescriptor;
    } else {
        HashSet<IItemDescriptor<T>> descriptorFromPrefSet = Sets.newLinkedHashSet(itemsDescriptor);
        HashSet<IItemDescriptor<T>> defaultDescriptorSet = Sets.newLinkedHashSet(orderedDefaultDescriptor);

        // Remove descriptor
        SetView<IItemDescriptor<T>> descriptorToRemove = Sets.difference(descriptorFromPrefSet,
                defaultDescriptorSet);
        Iterables.removeAll(itemsDescriptor, descriptorToRemove);

        // Add new descriptor
        SetView<IItemDescriptor<T>> descriptorToAdd = Sets.difference(defaultDescriptorSet,
                descriptorFromPrefSet);
        Iterables.addAll(itemsDescriptor, descriptorToAdd);

    }
    return itemsDescriptor;
}

From source file:org.syncany.cli.PluginCommand.java

private void printResultUpdate(final PluginOperationResult operationResult) {
    // Print regular result
    if (operationResult.getResultCode() == PluginResultCode.OK) {
        if (operationResult.getUpdatedPluginIds().size() == 0) {
            out.println("All plugins are up to date.");
        } else {//  w  ww  .j a va 2  s.c  o  m
            Iterables.removeAll(operationResult.getUpdatedPluginIds(), operationResult.getErroneousPluginIds());
            Iterables.removeAll(operationResult.getUpdatedPluginIds(), operationResult.getDelayedPluginIds());

            if (operationResult.getDelayedPluginIds().size() > 0) {
                out.printf("Plugins to be updated: %s\n",
                        StringUtil.join(operationResult.getDelayedPluginIds(), ", "));
            }

            if (operationResult.getUpdatedPluginIds().size() > 0) {
                out.printf("Plugins successfully updated: %s\n",
                        StringUtil.join(operationResult.getUpdatedPluginIds(), ", "));
            }

            if (operationResult.getErroneousPluginIds().size() > 0) {
                out.printf("Failed to update %s. Try -d to get more details\n",
                        StringUtil.join(operationResult.getErroneousPluginIds(), ", "));
            }

            out.println();
        }
    } else {
        out.println("Plugin update failed. Try -d to get more details.");
        out.println();
    }
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.util.SubEventsHelper.java

private Set<ISequenceEvent> getTopLevelEvents(Set<ISequenceEvent> events,
        Collection<ISequenceEvent> potentialParents, Set<Lifeline> coveredLifelines) {
    HashSet<ISequenceEvent> topLevel = Sets.newLinkedHashSet();
    boolean parentFrames = Iterables.size(Iterables.filter(potentialParents, AbstractFrame.class)) != 0;

    for (ISequenceEvent event : events) {
        final Range verticalRange = event.getVerticalRange();
        final ISequenceEvent potentialChild = event;

        Predicate<ISequenceEvent> isParentOfCurrent = new Predicate<ISequenceEvent>() {
            public boolean apply(ISequenceEvent input) {
                Range inputRange = input.getVerticalRange();
                boolean isParent = inputRange.includes(verticalRange);
                return isParent && input != potentialChild;
            }//from  ww  w.j  a v a  2  s  . com
        };

        List<ISequenceEvent> parents = Lists
                .newArrayList(Iterables.filter(potentialParents, isParentOfCurrent));
        if (parents.isEmpty()) {
            topLevel.add(potentialChild);
        } else if (potentialChild instanceof AbstractFrame && !parentFrames) {
            Collection<ISequenceEvent> carriers = Lists
                    .newArrayList(getCarryingParents((AbstractFrame) potentialChild, coveredLifelines));
            Iterables.removeAll(carriers, parents);
            if (!carriers.isEmpty()) {
                topLevel.add(potentialChild);
            }
        }
    }
    return topLevel;
}

From source file:org.eclipse.xtext.xbase.lib.CollectionExtensions.java

/**
 * Removes all of the specified elements from the specified collection.
 *
 * @param collection//from ww  w .  j a  v a2 s .  co  m
 *            the collection from which the {@code elements} are to be removed. May not be <code>null</code>.
 * @param elements
 *            the elements to remove from the {@code collection}. May not be <code>null</code> but may contain
 *            <code>null</code> entries if the {@code collection} allows that.
 * @return <code>true</code> if the collection changed as a result of the call
 * @since 2.4
 */
@Inline(value = "$3.$4removeAll($1, $2)", imported = Iterables.class)
public static <T> boolean removeAll(Collection<T> collection, Collection<? extends T> elements) {
    return Iterables.removeAll(collection, elements);
}

From source file:org.eclipse.xtext.xbase.lib.CollectionExtensions.java

/**
 * Removes all of the specified elements from the specified collection.
 * //from  w w w  . ja  va 2 s  . c  o  m
 * @param collection
 *            the collection from which the {@code elements} are to be removed. May not be <code>null</code>.
 * @param elements
 *            the elements to remove from the {@code collection}. May not be <code>null</code> but may contain
 *            <code>null</code> entries if the {@code collection} allows that.
 * @return <code>true</code> if the collection changed as a result of the call
 * @since 2.4
 */
public static <T> boolean removeAll(Collection<T> collection, Iterable<? extends T> elements) {
    return Iterables.removeAll(collection, newHashSet(elements));
}

From source file:co.cask.cdap.data2.metadata.dataset.MetadataDataset.java

/**
 * Removes the specified tags from the specified entity.
 *
 * @param targetId the {@link Id.NamespacedId} from which to remove the specified tags
 * @param tagsToRemove the tags to remove
 *///from  w  w w  .  j  ava  2 s. c o  m
public void removeTags(Id.NamespacedId targetId, String... tagsToRemove) {
    Set<String> existingTags = getTags(targetId);
    if (existingTags.isEmpty()) {
        // nothing to remove
        return;
    }

    Iterables.removeAll(existingTags, Arrays.asList(tagsToRemove));

    // call remove metadata for tags which will delete all the existing indexes for tags of this targetId
    removeMetadata(targetId, TAGS_KEY);
    setTags(targetId, Iterables.toArray(existingTags, String.class));
}