List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.elk.gmf.ElkLayoutProvider.java
/** * {@inheritDoc}<br>// www. j a va2 s.c o m * <br> * This method returns <code>true</code> only for {@link IGraphicalEditPart IGraphicalEditParts} * whose figures are visible and that contain at least a {@link ShapeNodeEditPart}, which is not * an {@link AbstractBorderItemEditPart} or an {@link AbstractImageEditPart}.<br> * <br> * In short, returns only true if the provided edit part contains children that can be layouted. */ @SuppressWarnings("rawtypes") public boolean canLayoutNodes(final List layoutNodes, final boolean shouldOffsetFromBoundingBox, final IAdaptable layoutHint) { Object o = layoutHint.getAdapter(IGraphicalEditPart.class); if (!(o instanceof IGraphicalEditPart)) { return false; } final IGraphicalEditPart parent = (IGraphicalEditPart) o; // check the availability of children that can be arranged // computing layout on the element wouldn't make sense otherwise if (layoutNodes.isEmpty()) { return Iterables.any((List<?>) parent.getChildren(), new Predicate<Object>() { public boolean apply(final Object o) { return o instanceof ShapeNodeEditPart && !(o instanceof AbstractBorderItemEditPart) && !(o instanceof AbstractImageEditPart); } }); } else { return Iterables.any((List<?>) layoutNodes, new Predicate<Object>() { public boolean apply(final Object o) { ILayoutNode layoutNode = (ILayoutNode) o; IGraphicalEditPart editPart = findEditPart(parent, layoutNode.getNode()); return editPart instanceof ShapeNodeEditPart && !(editPart instanceof AbstractBorderItemEditPart) && !(editPart instanceof AbstractImageEditPart); } }); } }
From source file:org.sonar.updatecenter.common.PluginReferential.java
public boolean doesContainPlugin(final String key) { return Iterables.any(plugins, new Predicate<Plugin>() { public boolean apply(Plugin input) { return input.getKey().equals(key); }//from ww w . j a v a 2 s.com }); }
From source file:ch.acanda.eclipse.pmd.java.resolution.design.UseUtilityClassQuickFix.java
private void addFinalIfNecessary(final TypeDeclaration typeDeclaration, final ASTRewrite rewrite) { @SuppressWarnings("unchecked") final List<IExtendedModifier> modifiers = typeDeclaration.modifiers(); if (!Iterables.any(modifiers, isFinal())) { final ListRewrite modifierRewrite = rewrite.getListRewrite(typeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY); final Modifier modifier = (Modifier) typeDeclaration.getAST().createInstance(Modifier.class); modifier.setKeyword(ModifierKeyword.FINAL_KEYWORD); modifierRewrite.insertLast(modifier, null); }// www . j a v a 2 s . c om }
From source file:org.killbill.billing.invoice.generator.InvoiceWithMetadata.java
private boolean hasItemsForSubscription(final UUID subscriptionId, final InvoiceItemType invoiceItemType) { return invoice != null && Iterables.any(invoice.getInvoiceItems(), new Predicate<InvoiceItem>() { @Override//from ww w. j a v a 2 s.com public boolean apply(final InvoiceItem input) { return input.getInvoiceItemType() == invoiceItemType && input.getSubscriptionId().equals(subscriptionId); } }); }
From source file:eu.numberfour.n4js.utils.quickfix.DelegatingQuickfixProvider.java
@Override public boolean hasResolutionFor(final String issueCode) { if (super.hasResolutionFor(issueCode)) { return true; }//from ww w.j a v a 2 s .c om return Iterables.any(getDelegates(), p -> p.hasResolutionFor(issueCode)); }
From source file:org.eclipse.sirius.diagram.tools.internal.validation.description.constraints.MappingForReconnectToolsConstraint.java
private Collection<String> getReconnectOnRegions(ReconnectEdgeDescription tool) { Predicate<ContainerMapping> isRegionMapping = new Predicate<ContainerMapping>() { @Override/*w w w . j a v a 2s . c om*/ public boolean apply(ContainerMapping input) { return new ContainerMappingQuery(input).isRegion(); } }; Collection<EdgeMapping> edgeToRegions = Sets.newLinkedHashSet(); for (EdgeMapping em : tool.getMappings()) { if (tool.getReconnectionKind() == ReconnectionKind.RECONNECT_SOURCE_LITERAL || tool.getReconnectionKind() == ReconnectionKind.RECONNECT_BOTH_LITERAL) { if (Iterables.any(Iterables.filter(em.getSourceMapping(), ContainerMapping.class), isRegionMapping)) { edgeToRegions.add(em); } } if (tool.getReconnectionKind() == ReconnectionKind.RECONNECT_TARGET_LITERAL || tool.getReconnectionKind() == ReconnectionKind.RECONNECT_BOTH_LITERAL) { if (Iterables.any(Iterables.filter(em.getTargetMapping(), ContainerMapping.class), isRegionMapping)) { edgeToRegions.add(em); } } } Collection<String> mappingsLabel = Lists.newArrayList(); for (EdgeMapping mapping : edgeToRegions) { mappingsLabel.add(new IdentifiedElementQuery(mapping).getLabel()); } return mappingsLabel; }
From source file:org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider.java
/** * @see org.eclipse.xtext.ui.editor.model.IXtextModelListener#modelChanged(org.eclipse.xtext.resource.XtextResource) *///from w w w. j av a2 s .c o m @Override public void modelChanged(XtextResource resource) { if (resource == null) return; boolean existingSyntaxErrors = Iterables.any(resource.getErrors(), new Predicate<Diagnostic>() { @Override public boolean apply(Diagnostic diagnostic) { return diagnostic instanceof XtextSyntaxDiagnostic; } }); if (!existingSyntaxErrors) { calculateProjectionAnnotationModel(false); } }
From source file:org.pentaho.di.trans.dataservice.optimization.cache.ServiceObserver.java
public ListenableFuture<CachedService> install() { List<Runnable> serviceReady = executor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY); if (Iterables.any(serviceReady, instanceOf(ServiceObserver.class))) { setException(new IllegalStateException("More than one cache is configured for this data service.")); } else {//from w ww . j ava2s. co m serviceReady.add(this); } return this; }
From source file:xml.entity.immutableelement.ImmutableElements.java
/** * Test if this node has a child matching the given predicate. * /*from w w w. ja v a 2 s . c om*/ * @param matching * This predicate will be applied to the children of the matched * node. * @return true if any child matches the given predicate. */ public static Predicate<ImmutableElement> hasChild(final Predicate<ImmutableElement> matching) { return new Predicate<ImmutableElement>() { @Override public boolean apply(@Nullable final ImmutableElement input) { return Iterables.any(input.children(), matching); } @Override public String toString() { return matching.toString(); } }; }
From source file:org.eclipse.elk.layered.intermediate.LabelDummyInserter.java
/** * {@inheritDoc}//from www . java 2 s.c o m */ public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) { monitor.begin("Label dummy insertions", 1); List<LNode> newDummyNodes = Lists.newArrayList(); double labelSpacing = layeredGraph.getProperty(LayoutOptions.LABEL_SPACING).doubleValue(); Direction layoutDirection = layeredGraph.getProperty(LayoutOptions.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(LayoutOptions.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(LayoutOptions.THICKNESS); if (thickness < 0) { thickness = 0; edge.setProperty(LayoutOptions.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(LayoutOptions.EDGE_LABEL_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(); }