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.pentaho.di.trans.dataservice.serialization.ServiceTrans.java

public static Predicate<ServiceTrans> isValid(final Repository repository) {
    return new Predicate<ServiceTrans>() {
        @Override/*from w w  w .  ja  v a 2 s .c  o m*/
        public boolean apply(ServiceTrans input) {
            return Iterables.any(input.getReferences(), Reference.isValid(repository));
        }
    };
}

From source file:org.eclipse.emf.compare.ide.ui.mergeresolution.MergeResolutionManager.java

/**
 * Called when a merge result view's flush method is called. This indicates that the user has saved the
 * contents, but does not necessarily mean that all conflicts are resolved.
 * //from w  ww  .j av a2  s.  c o m
 * @param input
 *            The content of the merge resolution being flushed. This can either be a {@link Match}, a
 *            {@link Diff} or a {@link MatchResource} object.
 */
public void handleFlush(Object input) {
    // We only know how to handle TreeNodeCompareInput
    if (!(input instanceof TreeNodeCompareInput)) {
        return;
    }
    TreeNodeCompareInput treeNodeCompareInput = (TreeNodeCompareInput) input;
    EObject eobject = treeNodeCompareInput.getComparisonObject();

    Comparison comparison = ComparisonUtil.getComparison(eobject);

    if (comparison == null) {
        // what to do? how do we get the Comparison object?
        return;
    }

    Predicate<Conflict> unresolvedConflict = new Predicate<Conflict>() {
        public boolean apply(Conflict conflict) {
            return conflict != null && conflict.getKind() != ConflictKind.PSEUDO && Iterables
                    .any(conflict.getDifferences(), EMFComparePredicates.hasState(DifferenceState.UNRESOLVED));
        }
    };
    if (Iterables.any(comparison.getConflicts(), unresolvedConflict)) {
        mergeResolutionListenerRegistry.mergeResolutionCompleted(comparison);
    }
}

From source file:org.garethaye.minimax.tic_tac_toe.TicTacToeServer.java

private static boolean hasThreeInARow(List<List<Integer>> board, final int id) {
    return Iterables.any(getAllTriples(board), new Predicate<List<Integer>>() {
        @Override/*  w  w w .ja  va2 s.c  o  m*/
        public boolean apply(List<Integer> three) {
            return BotUtils.allEqual(three, id);
        }
    });
}

From source file:org.eclipse.elk.alg.layered.intermediate.LabelDummyInserter.java

/**
 * {@inheritDoc}/*w w w. j  a  v  a 2s . c om*/
 */
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Label dummy insertions", 1);

    List<LNode> newDummyNodes = Lists.newArrayList();

    float labelSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_LABEL);
    Direction layoutDirection = layeredGraph.getProperty(LayeredOptions.DIRECTION);

    for (LNode node : layeredGraph.getLayerlessNodes()) {
        for (LPort port : node.getPorts()) {
            for (LEdge edge : port.getOutgoingEdges()) {
                // Ignore self-loops for the moment (see KIPRA-1073)
                if (edge.getSource().getNode() != edge.getTarget().getNode()
                        && Iterables.any(edge.getLabels(), CENTER_LABEL)) {

                    // Remember the list of edge labels represented by the dummy node
                    List<LLabel> representedLabels = Lists.newArrayListWithCapacity(edge.getLabels().size());

                    // Create dummy node
                    LNode dummyNode = new LNode(layeredGraph);
                    dummyNode.setType(NodeType.LABEL);

                    dummyNode.setProperty(InternalProperties.ORIGIN, edge);
                    dummyNode.setProperty(InternalProperties.REPRESENTED_LABELS, representedLabels);
                    dummyNode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
                    dummyNode.setProperty(InternalProperties.LONG_EDGE_SOURCE, edge.getSource());
                    dummyNode.setProperty(InternalProperties.LONG_EDGE_TARGET, edge.getTarget());

                    newDummyNodes.add(dummyNode);

                    // Actually split the edge
                    LongEdgeSplitter.splitEdge(edge, dummyNode);

                    // Set thickness of the edge and place ports at its center
                    float thickness = edge.getProperty(LayeredOptions.EDGE_THICKNESS);
                    if (thickness < 0) {
                        thickness = 0;
                        edge.setProperty(LayeredOptions.EDGE_THICKNESS, thickness);
                    }
                    double portPos = Math.floor(thickness / 2);

                    // Apply port positions
                    for (LPort dummyPort : dummyNode.getPorts()) {
                        dummyPort.getPosition().y = portPos;
                    }

                    // Determine the size of the dummy node and move labels over to it
                    KVector dummySize = dummyNode.getSize();

                    ListIterator<LLabel> iterator = edge.getLabels().listIterator();
                    while (iterator.hasNext()) {
                        LLabel label = iterator.next();

                        if (label.getProperty(
                                LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.CENTER) {

                            // The way we stack labels depends on the layout direction
                            if (layoutDirection.isVertical()) {
                                dummySize.x += label.getSize().x + labelSpacing;
                                dummySize.y = Math.max(dummySize.y, label.getSize().y);
                            } else {
                                dummySize.x = Math.max(dummySize.x, label.getSize().x);
                                dummySize.y += label.getSize().y + labelSpacing;
                            }

                            // Move the label over to the dummy node's REPRESENTED_LABELS property
                            representedLabels.add(label);
                            iterator.remove();
                        }
                    }

                    // Determine the final dummy node size
                    if (layoutDirection.isVertical()) {
                        dummySize.x -= labelSpacing;
                        dummySize.y += labelSpacing + thickness;
                    } else {
                        dummySize.y += labelSpacing + thickness;
                    }
                }
            }
        }
    }

    // Add created dummies to graph
    layeredGraph.getLayerlessNodes().addAll(newDummyNodes);

    monitor.done();
}

From source file:io.crate.planner.PlanNodeBuilder.java

static CollectNode collect(AbstractDataAnalyzedStatement analysis, List<Symbol> toCollect,
        ImmutableList<Projection> projections, @Nullable String partitionIdent) {
    assert !Iterables.any(toCollect, Predicates.instanceOf(InputColumn.class)) : "cannot collect inputcolumns";
    Routing routing = analysis.table().getRouting(analysis.whereClause());
    if (partitionIdent != null && routing.hasLocations()) {
        routing = filterRouting(routing, PartitionName
                .fromPartitionIdent(analysis.table().ident().name(), partitionIdent).stringValue());
    }/*ww w .  j a v a  2  s  .  com*/
    CollectNode node = new CollectNode("collect", routing);
    node.whereClause(analysis.whereClause());
    node.toCollect(toCollect);
    node.maxRowGranularity(analysis.table().rowGranularity());
    node.projections(projections);
    node.isPartitioned(analysis.table().isPartitioned());
    setOutputTypes(node);
    return node;
}

From source file:com.mycelium.wallet.activity.main.BuySellFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(false);/*from   w  ww  . ja  v  a2  s. c  om*/
    showButton = Iterables.any(_mbwManager.getEnvironmentSettings().getBuySellServices(),
            new Predicate<BuySellServiceDescriptor>() {
                @Override
                public boolean apply(@Nullable BuySellServiceDescriptor input) {
                    return input.isEnabled(_mbwManager);
                }
            });
    super.onCreate(savedInstanceState);
}

From source file:org.asoem.greyfish.utils.collect.FunctionalFifoBuffer.java

@Override
public boolean any(final Predicate<M> predicate) {
    return Iterables.any(buffer, predicate);
}

From source file:com.siemens.sw360.portal.common.datatables.DataTablesParser.java

protected static List<Map<String, String[]>> vectorize(Map<String, String[]> parametersMap) {
    int i = 0;/*  w w  w.ja v a2 s .c om*/
    ImmutableList.Builder<Map<String, String[]>> builder = ImmutableList.builder();
    Set<String> parametersName = parametersMap.keySet();

    while (Iterables.any(parametersName, startsWith("[" + i + "]"))) {
        builder.add(unprefix(parametersMap, "[" + i + "]"));
        i++;
    }

    return builder.build();
}

From source file:org.xrepl.ui.embedded.EmbeddedFoldingStructureProvider.java

/**
 * @see org.eclipse.xtext.ui.editor.model.IXtextModelListener#modelChanged(org.eclipse.xtext.resource.XtextResource)
 *///from  www  . j a  v  a2 s. co  m
public void modelChanged(XtextResource resource) {
    boolean existingSyntaxErrors = Iterables.any(resource.getErrors(), new Predicate<Diagnostic>() {
        public boolean apply(Diagnostic diagnostic) {
            return diagnostic instanceof XtextSyntaxDiagnostic;
        }
    });

    if (!existingSyntaxErrors) {
        calculateProjectionAnnotationModel(false);
    }
}

From source file:org.apache.beam.runners.spark.SparkNativePipelineVisitor.java

private boolean shouldDebug(final TransformHierarchy.Node node) {
    return node == null || !Iterables.any(transforms, new Predicate<NativeTransform>() {
        @Override/*from  w w w.  j  ava 2s.co m*/
        public boolean apply(NativeTransform debugTransform) {
            return debugTransform.getNode().equals(node) && debugTransform.isComposite();
        }
    }) && shouldDebug(node.getEnclosingNode());
}