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

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

Introduction

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

Prototype

public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if any element in iterable satisfies the predicate.

Usage

From source file:org.eclipse.emf.compare.ide.ui.internal.logical.resolver.ModelsResolution.java

/**
 * If we found some storages in the right traversal that were not part of the left traversal, we need to
 * check whether they exist in the left, since in such a case they must be considered as part of the same
 * logical model.//from www . j ava  2 s  .  c  o  m
 * <p>
 * <b>Important</b> : note that the input {@code left} and {@code right} sets <b>will be modified</b> as a
 * result of this call if there are any additional storages to load on these sides.
 * </p>
 * 
 * @param leftSet
 *            Traversal of the left logical model.
 * @param rightSet
 *            Traversal of the right logical model.
 * @param additional
 *            the addition storages we are to lookup in left.
 * @param tspm
 *            Monitor on which to report progress to the user.
 * @return The set of all additional resources (both on left and right) that have been loaded as a result
 *         of this call.
 * @throws InterruptedException
 *             Thrown if the resolution is cancelled or interrupted one way or another.
 */
private Set<IStorage> loadAdditionalRemoteStorages(Set<IStorage> leftSet, Set<IStorage> rightSet,
        Set<IStorage> additional, ThreadSafeProgressMonitor tspm) throws InterruptedException {
    /*
     * This loop will be extremely costly at best, but we hope the case to be sufficiently rare (and the
     * new resources well spread when it happens) not to pose an issue in the most frequent cases.
     */

    // Make sure we properly update the dependency graph if our source side is local
    final boolean sourceIsLocal = Iterables.any(leftSet, new Predicate<IStorage>() {
        public boolean apply(IStorage input) {
            return adaptAs(input, IFile.class) != null;
        }
    });

    final Set<IStorage> additionalStorages = new LinkedHashSet<IStorage>();
    final Set<URI> additionalURIs = new LinkedHashSet<URI>();
    // Have we found new resources in the right as compared to the left?
    Set<IStorage> differenceRightLeft = additional;
    boolean somethingToAdd = !differenceRightLeft.isEmpty();
    while (somethingToAdd) {
        somethingToAdd = false;
        // There's at least one resource in the right that was not found in the left.
        // This might be a new resource added on the right side... but it might also be a cross-reference
        // that's been either removed from left or added in right. In this second case, we need the
        // resource to be present in both traversals to make sure we'll be able to properly detect
        // potential conflicts. However, since this resource could itself be a part of a larger logical
        // model, we need to start the resolving again with it.
        final Set<IStorage> additionalLeft;
        if (sourceIsLocal) {
            additionalLeft = findAdditionalLocalTraversal(leftSet, differenceRightLeft, tspm);
        } else {
            additionalLeft = findAdditionalRemoteTraversal(leftSet, differenceRightLeft, DiffSide.SOURCE, tspm);
        }
        if (leftSet.addAll(additionalLeft)) {
            somethingToAdd = true;
            for (IStorage storage : additionalLeft) {
                final URI newURI = asURI().apply(storage);
                if (additionalURIs.add(newURI)) {
                    additionalStorages.add(storage);
                }
            }
        }
        // have we only loaded the resources that were present in the right but not in the left, or have
        // we found even more?
        final Set<IStorage> differenceAdditionalLeftRight = difference(additionalLeft, asURISet(rightSet));
        // If so, we once more need to augment the right traversal
        final Set<IStorage> additionalRight = findAdditionalRemoteTraversal(rightSet,
                differenceAdditionalLeftRight, DiffSide.REMOTE, tspm);
        if (rightSet.addAll(additionalRight)) {
            somethingToAdd = true;
            for (IStorage storage : additionalRight) {
                final URI newURI = asURI().apply(storage);
                if (additionalURIs.add(newURI)) {
                    additionalStorages.add(storage);
                }
            }
        }
        // Start this loop anew if we once again augmented the right further than what we had in
        // left
        if (somethingToAdd) {
            differenceRightLeft = difference(additionalRight, asURISet(leftSet));
        }
    }
    return additionalStorages;
}

From source file:org.opennms.netmgt.enlinkd.EnLinkdTestHelper.java

public static <T> boolean checkLinks(Iterable<T> iterable, Predicate<T>... matchers) {
    for (Predicate<T> matcher : matchers) {
        if (!Iterables.any(iterable, matcher)) {
            return false;
        }/*from  w  w w  . j a v a 2 s . com*/
    }
    return true;
}

From source file:gov.nih.nci.caarray.domain.array.ArrayDesign.java

/**
 * Check whether this is a array design that has been imported imported but not parsed. implemented for it). This
 * will be the case if any of the design files associated with the array design meet this condition.
 * //  www.  j  a  v a  2  s  . c o m
 * @return true if the design has been imported and parsed, false otherwise.
 */
@Transient
public boolean isImportedAndParsed() {
    return Iterables.any(getDesignFiles(), new Predicate<CaArrayFile>() {
        @Override
        public boolean apply(CaArrayFile file) {
            return file.getFileStatus() == FileStatus.IMPORTED;
        }
    });
}

From source file:org.jclouds.googlecomputeengine.compute.extensions.GoogleComputeEngineSecurityGroupExtension.java

private SecurityGroup groupForTagsInNetwork(Network nw, final Set<String> tags) {
    ListOptions opts = new Builder().filter("network eq .*/" + nw.getName());
    Set<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(opts).concat()
            .filter(new Predicate<Firewall>() {
                @Override//from   w ww.j  a v  a 2 s  . c  om
                public boolean apply(final Firewall input) {
                    // If any of the targetTags on the firewall apply or the firewall has no target tags...
                    return Iterables.any(input.getTargetTags(), Predicates.in(tags))
                            || Predicates.equalTo(0).apply(input.getTargetTags().size());
                }
            }).toSet();

    if (fws.isEmpty()) {
        return null;
    }

    return groupConverter.apply(nw);
}

From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java

/**
 * Tests whether the dDiagramElement is explicitly folded, i.e. it is a
 * folding point.//from  w w  w . j  a  v a  2  s . co m
 * 
 * @return <code>true</code> if the dDiagramElement is explicitly folded.
 */
public boolean isExplicitlyFolded() {
    return Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(FoldingPointFilter.class));
}

From source file:pt.ist.maidSyncher.domain.github.GHIssue.java

/**
 * Enforces only one Label that corresponds to an ACProject.
 * <strong>Makes changes to the GH repository</strong>
 * /*from   ww  w.j ava 2s. c om*/
 * @throws IOException
 * @{@link Deprecated} - not the behavior used anymore
 */
@Deprecated
private void validateAndCorrectLabels() throws IOException {
    GHLabel labelFound = null;
    Set<GHLabel> labelsToRemove = new HashSet<>();
    for (GHLabel ghLabel : getLabelsSet()) {
        if (ghLabel.getDSIObject() != null) {
            if (labelFound != null) {
                labelsToRemove.add(ghLabel);
            } else {
                labelFound = ghLabel;
            }
        }
    }

    //let us enforce the labels then
    IssueService issueService = new IssueService(MaidRoot.getGitHubClient());
    Issue issueToRemoveLabelsFrom = issueService.getIssue(getRepository(), getNumber());
    for (Label currentLabel : issueToRemoveLabelsFrom.getLabels()) {
        final String currentLabelName = currentLabel.getName();
        boolean removeThisOne = Iterables.any(labelsToRemove, new Predicate<GHLabel>() {
            @Override
            public boolean apply(GHLabel input) {
                if (input == null)
                    return false;
                return input.getName().equalsIgnoreCase(currentLabelName);

            }

        });
        if (removeThisOne) {
            issueToRemoveLabelsFrom.getLabels().remove(currentLabel);
        }
    }

    //let us communicate the changes
    Issue newlyEditedIssue = issueService.editIssue(getRepository(), issueToRemoveLabelsFrom);
    try {
        copyPropertiesFrom(newlyEditedIssue);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new Error(e);
    }

}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeISequenceEventsSemanticOrderingOperation.java

private Set<EventEnd> selectEndsToIgnore(ISequenceEvent ise, List<EventEnd> endsBySemanticOrder,
        final List<EventEnd> iseEnds, final List<EventEnd> compoundEnds) {
    final Iterable<ISequenceEvent> movedElements = Iterables.filter(allElementsToReorder,
            Predicates.not(Predicates.in(reordered)));
    final Set<EObject> semanticLinked = Sets.newHashSet(Iterables.filter(
            Iterables.transform(movedElements, ISequenceElement.SEMANTIC_TARGET), Predicates.notNull()));
    final Predicate<EObject> isLinkedSubEventEnd = new Predicate<EObject>() {
        @Override//from   w w  w  . j a v  a 2  s . co  m
        public boolean apply(EObject input) {
            return semanticLinked.contains(input);
        }
    };

    final Set<EObject> semanticDescendants = Sets
            .newHashSet(Iterables.filter(Iterables.transform(new ISequenceEventQuery(ise).getAllDescendants(),
                    ISequenceElement.SEMANTIC_TARGET), Predicates.notNull()));
    final Predicate<EObject> isSemanticSubEventEnd = new Predicate<EObject>() {
        @Override
        public boolean apply(EObject input) {
            return semanticDescendants.contains(input);
        }
    };

    Predicate<EventEnd> toIgnore = new Predicate<EventEnd>() {
        @Override
        public boolean apply(EventEnd input) {
            return !iseEnds.contains(input) && (Iterables.any(EventEndHelper.getSemanticEvents(input),
                    Predicates.or(isSemanticSubEventEnd, isLinkedSubEventEnd)) || compoundEnds.contains(input));
        }
    };
    HashSet<EventEnd> newHashSet = Sets.newHashSet(Iterables.filter(endsBySemanticOrder, toIgnore));
    return newHashSet;
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java

private Map<ISequenceEvent, Range> computePunctualEventsGraphicalRanges(Map<EventEnd, Integer> endLocations,
        boolean pack) {
    final Map<ISequenceEvent, Range> sequenceEventsToRange = new LinkedHashMap<ISequenceEvent, Range>();
    if (pack) {//from   w ww . j  a v a2  s. c  o m
        for (EventEnd cee : Iterables.filter(semanticOrdering, EventEndHelper.PUNCTUAL_COMPOUND_EVENT_END)) {
            if (endLocations.containsKey(cee) && endToISequencEvents.containsKey(cee)) {
                int loc = endLocations.get(cee);
                Collection<ISequenceEvent> ises = endToISequencEvents.get(cee);

                if (Iterables.any(ises, Predicates.instanceOf(State.class)) && ises.size() == 1) {
                    State ise = (State) ises.iterator().next();
                    int midSize = getAbstractNodeEventVerticalSize(cee, ise, ises, pack) / 2;
                    sequenceEventsToRange.put(ise, new Range(loc - midSize, loc + midSize));
                }
            }
        }
    }
    return sequenceEventsToRange;
}

From source file:org.eclipse.emf.compare.internal.conflict.AbstractConflictSearch.java

/**
 * Checks whether the given {@code value} has been deleted from the given {@code feature} of {@code match}
 * .//ww w.j av  a2s . co m
 * 
 * @param match
 *            The match which differences we'll check.
 * @param feature
 *            The feature on which we expect a difference.
 * @param value
 *            The value we expect to have been removed from {@code feature}.
 * @return <code>true</code> if there is such a Diff on {@code match}, <code>false</code> otherwise.
 */
protected boolean hasDeleteDiff(Match match, EStructuralFeature feature, Object value) {
    checkArgument(match.getComparison() == comparison);
    final Object expectedValue;
    if (value instanceof EObject && comparison.isThreeWay()) {
        final Match valueMatch = comparison.getMatch((EObject) value);
        if (valueMatch != null) {
            expectedValue = valueMatch.getOrigin();
        } else {
            expectedValue = value;
        }
    } else {
        expectedValue = value;
    }
    return Iterables.any(match.getDifferences(),
            and(onFeature(feature.getName()), valueIs(expectedValue), ofKind(DELETE)));
}

From source file:org.eclipse.sirius.diagram.ui.business.internal.migration.DiagramRepresentationsFileMigrationParticipantV670.java

/**
 * Add a {@link IndirectlyCollapsedFilter} to the children of CollapsedNode
 * (to retrieve the same behavior as before). The migration of GMF bounds of
 * this indirectly collapsed nodes, if they are bordered nodes, are deal
 * later in method {{@link #migrateGMFBoundsOfBorderedNodes(List)}.
 * //w ww. j  ava 2 s  .c om
 * @param diagram
 *            GMF Diagram to migrate.
 */
private void migrateChildrenOfCollapsedNode(Diagram diagram) {
    List<DDiagramElement> indirectlyCollaspedDDEs = Lists.newArrayList();
    Iterator<Node> viewIterator = Iterators.filter(Iterators.filter(diagram.eAllContents(), Node.class),
            isDirectlyCollapsedNode);
    while (viewIterator.hasNext()) {
        final Node node = viewIterator.next();
        if (node.getElement() instanceof AbstractDNode) {
            AbstractDNode abstractDNode = (AbstractDNode) node.getElement();
            indirectlyCollaspedDDEs.addAll(abstractDNode.getOwnedBorderedNodes());
            if (abstractDNode instanceof DNodeContainer) {
                DNodeContainer dDiagramElementContainer = (DNodeContainer) abstractDNode;
                indirectlyCollaspedDDEs.addAll(dDiagramElementContainer.getOwnedDiagramElements());
            } else if (abstractDNode instanceof DNodeList) {
                DNodeList dNodeList = (DNodeList) abstractDNode;
                indirectlyCollaspedDDEs.addAll(dNodeList.getOwnedElements());
            }
        }
    }
    for (DDiagramElement indirectlyCollaspedDDE : indirectlyCollaspedDDEs) {
        if (!Iterables.any(indirectlyCollaspedDDE.getGraphicalFilters(),
                Predicates.instanceOf(IndirectlyCollapseFilter.class))) {
            IndirectlyCollapseFilter indirectlyCollapseFilter = DiagramFactory.eINSTANCE
                    .createIndirectlyCollapseFilter();
            indirectlyCollaspedDDE.getGraphicalFilters().add(indirectlyCollapseFilter);
        }
    }
}