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.sonar.server.db.migrations.v45.AddMissingCustomRuleParametersMigration.java

private boolean hasParameter(final String parameter, Collection<RuleParameter> customRuleParams) {
    return Iterables.any(customRuleParams, new Predicate<RuleParameter>() {
        @Override//from  w ww  .j a va 2s.  c  o  m
        public boolean apply(@Nullable RuleParameter input) {
            return input != null && input.getName().equals(parameter);
        }
    });
}

From source file:forge.game.combat.CombatUtil.java

/**
 * Check whether a {@link Card} can attack any {@link GameEntity} that's legal for its controller to attack.
 * @param attacker/*from   w w w .  j  a  va2  s .  co m*/
 *            the attacking {@link Card}.
 * @return a boolean.
 * @see #canAttack(Card, GameEntity)
 */
public static boolean canAttack(final Card attacker) {
    return Iterables.any(getAllPossibleDefenders(attacker.getController()), new Predicate<GameEntity>() {
        @Override
        public boolean apply(final GameEntity defender) {
            return canAttack(attacker, defender);
        }
    });
}

From source file:org.killbill.billing.invoice.generator.UsageInvoiceItemGenerator.java

@Override
public List<InvoiceItem> generateItems(final ImmutableAccountData account, final UUID invoiceId,
        final BillingEventSet eventSet, @Nullable final List<Invoice> existingInvoices,
        final LocalDate targetDate, final Currency targetCurrency,
        final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDates,
        final InternalCallContext internalCallContext) throws InvoiceApiException {
    final Map<UUID, List<InvoiceItem>> perSubscriptionInArrearUsageItems = extractPerSubscriptionExistingInArrearUsageItems(
            eventSet.getUsages(), existingInvoices);
    try {//from  ww  w  .  j a v  a2 s  . c o m
        // Pretty-print the generated invoice items from the junction events
        final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId,
                account.getId(), "usage", log);

        final LocalDate minBillingEventDate = getMinBillingEventDate(eventSet, internalCallContext);

        final List<InvoiceItem> items = Lists.newArrayList();
        final Iterator<BillingEvent> events = eventSet.iterator();

        RawUsageOptimizerResult rawUsageOptimizerResult = null;
        List<BillingEvent> curEvents = Lists.newArrayList();
        UUID curSubscriptionId = null;
        while (events.hasNext()) {
            final BillingEvent event = events.next();
            // Skip events that are posterior to the targetDate
            final LocalDate eventLocalEffectiveDate = internalCallContext.toLocalDate(event.getEffectiveDate());
            if (eventLocalEffectiveDate.isAfter(targetDate)) {
                continue;
            }

            // Optimize to do the usage query only once after we know there are indeed some usage items
            if (rawUsageOptimizerResult == null && Iterables.any(event.getUsages(), new Predicate<Usage>() {
                @Override
                public boolean apply(@Nullable final Usage input) {
                    return input.getBillingMode() == BillingMode.IN_ARREAR;
                }
            })) {
                rawUsageOptimizerResult = rawUsageOptimizer.getInArrearUsage(minBillingEventDate, targetDate,
                        Iterables.concat(perSubscriptionInArrearUsageItems.values()), eventSet.getUsages(),
                        internalCallContext);
            }

            // None of the billing events report any usage IN_ARREAR sections
            if (rawUsageOptimizerResult == null) {
                continue;
            }

            final UUID subscriptionId = event.getSubscription().getId();
            if (curSubscriptionId != null && !curSubscriptionId.equals(subscriptionId)) {
                final SubscriptionUsageInArrear subscriptionUsageInArrear = new SubscriptionUsageInArrear(
                        account.getId(), invoiceId, curEvents, rawUsageOptimizerResult.getRawUsage(),
                        targetDate, rawUsageOptimizerResult.getRawUsageStartDate(), internalCallContext);
                final List<InvoiceItem> usageInArrearItems = perSubscriptionInArrearUsageItems
                        .get(curSubscriptionId);

                final SubscriptionUsageInArrearItemsAndNextNotificationDate subscriptionResult = subscriptionUsageInArrear
                        .computeMissingUsageInvoiceItems(usageInArrearItems != null ? usageInArrearItems
                                : ImmutableList.<InvoiceItem>of(), invoiceItemGeneratorLogger);
                final List<InvoiceItem> newInArrearUsageItems = subscriptionResult.getInvoiceItems();
                items.addAll(newInArrearUsageItems);
                updatePerSubscriptionNextNotificationUsageDate(curSubscriptionId,
                        subscriptionResult.getPerUsageNotificationDates(), BillingMode.IN_ARREAR,
                        perSubscriptionFutureNotificationDates);
                curEvents = Lists.newArrayList();
            }
            curSubscriptionId = subscriptionId;
            curEvents.add(event);
        }
        if (curSubscriptionId != null) {
            final SubscriptionUsageInArrear subscriptionUsageInArrear = new SubscriptionUsageInArrear(
                    account.getId(), invoiceId, curEvents, rawUsageOptimizerResult.getRawUsage(), targetDate,
                    rawUsageOptimizerResult.getRawUsageStartDate(), internalCallContext);
            final List<InvoiceItem> usageInArrearItems = perSubscriptionInArrearUsageItems
                    .get(curSubscriptionId);

            final SubscriptionUsageInArrearItemsAndNextNotificationDate subscriptionResult = subscriptionUsageInArrear
                    .computeMissingUsageInvoiceItems(
                            usageInArrearItems != null ? usageInArrearItems : ImmutableList.<InvoiceItem>of(),
                            invoiceItemGeneratorLogger);
            final List<InvoiceItem> newInArrearUsageItems = subscriptionResult.getInvoiceItems();
            items.addAll(newInArrearUsageItems);
            updatePerSubscriptionNextNotificationUsageDate(curSubscriptionId,
                    subscriptionResult.getPerUsageNotificationDates(), BillingMode.IN_ARREAR,
                    perSubscriptionFutureNotificationDates);
        }

        invoiceItemGeneratorLogger.logItems();

        return items;
    } catch (final CatalogApiException e) {
        throw new InvoiceApiException(e);
    }
}

From source file:de.dennishoersch.web.css.parser.Parser.java

private static List<Style> parseStyles(String styles) {
    Multimap<String, Style> reduced = LinkedHashMultimap.create();
    for (String style_ : _STYLE_SPLITTER.split(styles)) {
        Style style = new Style(style_);
        reduced.put(style.getName(), style);
    }//w w w.  ja va  2  s  .  c  om

    // Wenn keiner der Werte zu einem Style ein Vendor-Prefix enthlt, dann
    // kann der letzte alle anderen berschreiben
    List<Style> result = Lists.newArrayList();
    for (Map.Entry<String, Collection<Style>> entry : reduced.asMap().entrySet()) {
        Collection<Style> values = entry.getValue();
        if (Iterables.any(values, HasVendorPrefixValue.INSTANCE)) {
            result.addAll(values);
        } else {
            result.add(Iterables.getLast(values));
        }
    }
    return result;
}

From source file:de.cau.cs.kieler.klay.layered.compound.CompoundGraphPostprocessor.java

/**
 * {@inheritDoc}//from   w ww  .  j av  a2 s  .  c o  m
 */
public void process(final LGraph graph, final IKielerProgressMonitor monitor) {
    monitor.begin("Compound graph postprocessor", 1);

    // whether bend points should be added whenever crossing a hierarchy boundary
    boolean addUnnecessaryBendpoints = graph.getProperty(Properties.ADD_UNNECESSARY_BENDPOINTS);

    // restore the cross-hierarchy map that was built by the preprocessor
    Multimap<LEdge, CrossHierarchyEdge> crossHierarchyMap = graph
            .getProperty(InternalProperties.CROSS_HIERARCHY_MAP);

    // remember all dummy edges we encounter; these need to be removed at the end
    Set<LEdge> dummyEdges = Sets.newHashSet();

    // iterate over all original edges
    for (LEdge origEdge : crossHierarchyMap.keySet()) {
        List<CrossHierarchyEdge> crossHierarchyEdges = new ArrayList<CrossHierarchyEdge>(
                crossHierarchyMap.get(origEdge));

        // put the cross-hierarchy edges in proper order from source to target
        Collections.sort(crossHierarchyEdges, new CrossHierarchyEdgeComparator(graph));
        LPort sourcePort = crossHierarchyEdges.get(0).getActualSource();
        LPort targetPort = crossHierarchyEdges.get(crossHierarchyEdges.size() - 1).getActualTarget();
        origEdge.getBendPoints().clear();

        // determine the reference graph for all bend points
        LNode referenceNode = sourcePort.getNode();
        LGraph referenceGraph;
        if (LGraphUtil.isDescendant(targetPort.getNode(), referenceNode)) {
            referenceGraph = referenceNode.getProperty(InternalProperties.NESTED_LGRAPH);
        } else {
            referenceGraph = referenceNode.getGraph();
        }

        // check whether there are any junction points
        KVectorChain junctionPoints = origEdge.getProperty(LayoutOptions.JUNCTION_POINTS);
        if (Iterables.any(crossHierarchyEdges, HAS_JUNCTION_POINTS_PREDICATE)) {
            // if so, make sure the original edge has an empty non-null junction point list
            if (junctionPoints == null) {
                junctionPoints = new KVectorChain();
                origEdge.setProperty(LayoutOptions.JUNCTION_POINTS, junctionPoints);
            } else {
                junctionPoints.clear();
            }
        } else if (junctionPoints != null) {
            origEdge.setProperty(LayoutOptions.JUNCTION_POINTS, null);
        }

        // apply the computed layouts to the cross-hierarchy edge
        KVector lastPoint = null;
        for (CrossHierarchyEdge chEdge : crossHierarchyEdges) {
            // transform all coordinates from the graph of the dummy edge to the reference graph
            KVector offset = new KVector();
            LGraphUtil.changeCoordSystem(offset, chEdge.getGraph(), referenceGraph);

            LEdge ledge = chEdge.getEdge();
            KVectorChain bendPoints = new KVectorChain();
            bendPoints.addAllAsCopies(0, ledge.getBendPoints());
            bendPoints.offset(offset);

            // Note: if an NPE occurs here, that means KLay Layered has replaced the original edge
            KVector sourcePoint = new KVector(ledge.getSource().getAbsoluteAnchor());
            KVector targetPoint = new KVector(ledge.getTarget().getAbsoluteAnchor());
            sourcePoint.add(offset);
            targetPoint.add(offset);

            if (lastPoint != null) {
                KVector nextPoint;
                if (bendPoints.isEmpty()) {
                    nextPoint = targetPoint;
                } else {
                    nextPoint = bendPoints.getFirst();
                }

                // we add the source point as a bend point to properly connect the hierarchy levels
                // either if the last point of the previous hierarchy edge segment is a certain
                // level of tolerance away or if we are required to add unnecessary bend points
                boolean xDiffEnough = Math
                        .abs(lastPoint.x - nextPoint.x) > OrthogonalRoutingGenerator.TOLERANCE;
                boolean yDiffEnough = Math
                        .abs(lastPoint.y - nextPoint.y) > OrthogonalRoutingGenerator.TOLERANCE;

                if ((!addUnnecessaryBendpoints && xDiffEnough && yDiffEnough)
                        || (addUnnecessaryBendpoints && (xDiffEnough || yDiffEnough))) {

                    origEdge.getBendPoints().add(sourcePoint);
                }
            }

            origEdge.getBendPoints().addAll(bendPoints);

            if (bendPoints.isEmpty()) {
                lastPoint = sourcePoint;
            } else {
                lastPoint = bendPoints.getLast();
            }

            // copy junction points
            KVectorChain ledgeJPs = ledge.getProperty(LayoutOptions.JUNCTION_POINTS);
            if (ledgeJPs != null) {
                KVectorChain jpCopies = new KVectorChain();
                jpCopies.addAllAsCopies(0, ledgeJPs);
                jpCopies.offset(offset);

                junctionPoints.addAll(jpCopies);
            }

            // add offset to target port with a special property
            if (chEdge.getActualTarget() == targetPort) {
                if (targetPort.getNode().getGraph() != chEdge.getGraph()) {
                    // the target port is in a different coordinate system -- recompute the offset
                    offset = new KVector();
                    LGraphUtil.changeCoordSystem(offset, targetPort.getNode().getGraph(), referenceGraph);
                }
                origEdge.setProperty(InternalProperties.TARGET_OFFSET, offset);
            }

            // copy labels back to the original edge
            Iterator<LLabel> labelIterator = ledge.getLabels().listIterator();
            while (labelIterator.hasNext()) {
                LLabel currLabel = labelIterator.next();
                if (currLabel.getProperty(InternalProperties.ORIGINAL_LABEL_EDGE) != origEdge) {
                    continue;
                }

                LGraphUtil.changeCoordSystem(currLabel.getPosition(), ledge.getSource().getNode().getGraph(),
                        referenceGraph);
                labelIterator.remove();
                origEdge.getLabels().add(currLabel);
            }

            // remember the dummy edge for later removal (dummy edges may be in use by several
            // different original edges, which is why we cannot just go and remove it now)
            dummyEdges.add(ledge);
        }

        // restore the original source port and target port
        origEdge.setSource(sourcePort);
        origEdge.setTarget(targetPort);
    }

    // remove the dummy edges from the graph (dummy ports and dummy nodes are retained)
    for (LEdge dummyEdge : dummyEdges) {
        dummyEdge.setSource(null);
        dummyEdge.setTarget(null);
    }

    monitor.done();
}

From source file:org.gradle.model.internal.manage.schema.store.ModelSchemaExtractor.java

private boolean isSupportedUnmanagedType(final ModelType<?> propertyType) {
    return Iterables.any(SUPPORTED_UNMANAGED_TYPES, new Predicate<ModelType<?>>() {
        public boolean apply(ModelType<?> supportedType) {
            return supportedType.equals(propertyType);
        }//from   w ww .  j a  v a  2s .co m
    });
}

From source file:org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy.java

/**
 * Find the next node names that can be used. These will be derived from the tag and the
 * template. We will pre-allocate a specified quantity, and attempt to verify that there is no
 * name conflict with the current service.
 * /*from  w  w  w . j a  va  2 s .  c  o m*/
 * @param tag
 * @param count
 * @param template
 * @return
 */
protected Set<String> getNextNames(final String tag, final Template template, int count) {
    Set<String> names = Sets.newHashSet();
    Iterable<? extends ComputeMetadata> currentNodes = listNodesStrategy.listNodes();
    int maxTries = 100;
    int currentTries = 0;
    while (names.size() < count && currentTries++ < maxTries) {
        final String name = getNextName(tag, template);
        if (!Iterables.any(currentNodes, new Predicate<ComputeMetadata>() {

            @Override
            public boolean apply(ComputeMetadata input) {
                return name.equals(input.getName());
            }

        })) {
            names.add(name);
        }
    }
    return names;
}

From source file:com.censoredsoftware.infractions.bukkit.origin.Origin.java

/**
 * Set of Infractions with data from this Origin.
 *
 * @return Infractions.//ww w . j  a v  a 2 s. com
 */
public Set<Infraction> getContributedInfractions() {
    final Origin origin = this;
    return Sets.filter(Infractions.allInfractions(), new Predicate<Infraction>() {
        @Override
        public boolean apply(Infraction infraction) {
            return Iterables.any(infraction.getEvidence(), new Predicate<Evidence>() {
                @Override
                public boolean apply(Evidence evidence) {
                    return origin.equals(evidence.getOrigin());
                }
            });
        }
    });
}

From source file:org.eclipse.elk.alg.layered.compound.CompoundGraphPostprocessor.java

/**
 * {@inheritDoc}/* www .  j av a 2  s .co m*/
 */
public void process(final LGraph graph, final IElkProgressMonitor monitor) {
    monitor.begin("Compound graph postprocessor", 1);

    // whether bend points should be added whenever crossing a hierarchy boundary
    boolean addUnnecessaryBendpoints = graph.getProperty(LayeredOptions.UNNECESSARY_BENDPOINTS);

    // restore the cross-hierarchy map that was built by the preprocessor
    Multimap<LEdge, CrossHierarchyEdge> crossHierarchyMap = graph
            .getProperty(InternalProperties.CROSS_HIERARCHY_MAP);

    // remember all dummy edges we encounter; these need to be removed at the end
    Set<LEdge> dummyEdges = Sets.newHashSet();

    // iterate over all original edges
    for (LEdge origEdge : crossHierarchyMap.keySet()) {
        List<CrossHierarchyEdge> crossHierarchyEdges = new ArrayList<CrossHierarchyEdge>(
                crossHierarchyMap.get(origEdge));

        // put the cross-hierarchy edges in proper order from source to target
        Collections.sort(crossHierarchyEdges, new CrossHierarchyEdgeComparator(graph));
        LPort sourcePort = crossHierarchyEdges.get(0).getActualSource();
        LPort targetPort = crossHierarchyEdges.get(crossHierarchyEdges.size() - 1).getActualTarget();
        origEdge.getBendPoints().clear();

        // determine the reference graph for all bend points
        LNode referenceNode = sourcePort.getNode();
        LGraph referenceGraph;
        if (LGraphUtil.isDescendant(targetPort.getNode(), referenceNode)) {
            referenceGraph = referenceNode.getProperty(InternalProperties.NESTED_LGRAPH);
        } else {
            referenceGraph = referenceNode.getGraph();
        }

        // check whether there are any junction points
        KVectorChain junctionPoints = origEdge.getProperty(LayeredOptions.JUNCTION_POINTS);
        if (Iterables.any(crossHierarchyEdges, HAS_JUNCTION_POINTS_PREDICATE)) {
            // if so, make sure the original edge has an empty non-null junction point list
            if (junctionPoints == null) {
                junctionPoints = new KVectorChain();
                origEdge.setProperty(LayeredOptions.JUNCTION_POINTS, junctionPoints);
            } else {
                junctionPoints.clear();
            }
        } else if (junctionPoints != null) {
            origEdge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
        }

        // apply the computed layouts to the cross-hierarchy edge
        KVector lastPoint = null;
        for (CrossHierarchyEdge chEdge : crossHierarchyEdges) {
            // transform all coordinates from the graph of the dummy edge to the reference graph
            KVector offset = new KVector();
            LGraphUtil.changeCoordSystem(offset, chEdge.getGraph(), referenceGraph);

            LEdge ledge = chEdge.getEdge();
            KVectorChain bendPoints = new KVectorChain();
            bendPoints.addAllAsCopies(0, ledge.getBendPoints());
            bendPoints.offset(offset);

            // Note: if an NPE occurs here, that means KLay Layered has replaced the original edge
            KVector sourcePoint = new KVector(ledge.getSource().getAbsoluteAnchor());
            KVector targetPoint = new KVector(ledge.getTarget().getAbsoluteAnchor());
            sourcePoint.add(offset);
            targetPoint.add(offset);

            if (lastPoint != null) {
                KVector nextPoint;
                if (bendPoints.isEmpty()) {
                    nextPoint = targetPoint;
                } else {
                    nextPoint = bendPoints.getFirst();
                }

                // we add the source point as a bend point to properly connect the hierarchy levels
                // either if the last point of the previous hierarchy edge segment is a certain
                // level of tolerance away or if we are required to add unnecessary bend points
                boolean xDiffEnough = Math
                        .abs(lastPoint.x - nextPoint.x) > OrthogonalRoutingGenerator.TOLERANCE;
                boolean yDiffEnough = Math
                        .abs(lastPoint.y - nextPoint.y) > OrthogonalRoutingGenerator.TOLERANCE;

                if ((!addUnnecessaryBendpoints && xDiffEnough && yDiffEnough)
                        || (addUnnecessaryBendpoints && (xDiffEnough || yDiffEnough))) {

                    origEdge.getBendPoints().add(sourcePoint);
                }
            }

            origEdge.getBendPoints().addAll(bendPoints);

            if (bendPoints.isEmpty()) {
                lastPoint = sourcePoint;
            } else {
                lastPoint = bendPoints.getLast();
            }

            // copy junction points
            KVectorChain ledgeJPs = ledge.getProperty(LayeredOptions.JUNCTION_POINTS);
            if (ledgeJPs != null) {
                KVectorChain jpCopies = new KVectorChain();
                jpCopies.addAllAsCopies(0, ledgeJPs);
                jpCopies.offset(offset);

                junctionPoints.addAll(jpCopies);
            }

            // add offset to target port with a special property
            if (chEdge.getActualTarget() == targetPort) {
                if (targetPort.getNode().getGraph() != chEdge.getGraph()) {
                    // the target port is in a different coordinate system -- recompute the offset
                    offset = new KVector();
                    LGraphUtil.changeCoordSystem(offset, targetPort.getNode().getGraph(), referenceGraph);
                }
                origEdge.setProperty(InternalProperties.TARGET_OFFSET, offset);
            }

            // copy labels back to the original edge
            Iterator<LLabel> labelIterator = ledge.getLabels().listIterator();
            while (labelIterator.hasNext()) {
                LLabel currLabel = labelIterator.next();
                if (currLabel.getProperty(InternalProperties.ORIGINAL_LABEL_EDGE) != origEdge) {
                    continue;
                }

                LGraphUtil.changeCoordSystem(currLabel.getPosition(), ledge.getSource().getNode().getGraph(),
                        referenceGraph);
                labelIterator.remove();
                origEdge.getLabels().add(currLabel);
            }

            // remember the dummy edge for later removal (dummy edges may be in use by several
            // different original edges, which is why we cannot just go and remove it now)
            dummyEdges.add(ledge);
        }

        // restore the original source port and target port
        origEdge.setSource(sourcePort);
        origEdge.setTarget(targetPort);
    }

    // remove the dummy edges from the graph (dummy ports and dummy nodes are retained)
    for (LEdge dummyEdge : dummyEdges) {
        dummyEdge.setSource(null);
        dummyEdge.setTarget(null);
    }

    monitor.done();
}

From source file:org.splevo.jamopp.refactoring.java.caslicensehandler.cheatsheet.actions.CASLicenseHandlerConfiguration.java

private boolean isLicenseAlreadyAssigned(final String licenseToCheck, final String... variantIdsToIgnore) {
    final Iterable<String> idsToIgnore = Lists.newArrayList(variantIdsToIgnore);
    return Iterables.any(variantToLicenseMap.entrySet(), new Predicate<Entry<String, String>>() {
        @Override//from   w  ww .ja v  a2s  .c  o  m
        public boolean apply(Entry<String, String> input) {
            if (Iterables.contains(idsToIgnore, input.getKey())) {
                return false;
            }
            return input.getValue().equals(licenseToCheck);
        }
    });
}