List of usage examples for com.google.common.collect Iterators filter
@SuppressWarnings("unchecked") @GwtIncompatible("Class.isInstance") @CheckReturnValue public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType)
From source file:org.eclipse.sirius.tree.business.internal.migration.description.InitializeCreationToolElementsToSelectExpressionParticipant.java
@Override protected void postLoad(Group group, Version loadedVersion) { if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) { EList<Viewpoint> ownedViewpoints = group.getOwnedViewpoints(); for (Viewpoint viewpoint : ownedViewpoints) { boolean atLeastOneChange = false; for (TreeDescription treeDescription : Iterables.filter(viewpoint.getOwnedRepresentations(), TreeDescription.class)) { Iterator<EObject> creationTools = Iterators.filter(treeDescription.eAllContents(), Predicates.or(//from w w w . j a v a 2 s.c o m Predicates.or(Predicates.instanceOf(TreeItemContainerDropTool.class), Predicates.instanceOf(TreeItemDragTool.class)), Predicates.instanceOf(TreeItemCreationTool.class))); while (creationTools.hasNext()) { AbstractToolDescription tool = (AbstractToolDescription) creationTools.next(); if (StringUtil.isEmpty(tool.getElementsToSelect())) { tool.setElementsToSelect(ELEMENTS_TO_SELECT_EXPRESSION); atLeastOneChange = true; } } } if (atLeastOneChange) { // Add the Java Extension to use the service: if (!Iterables.any(viewpoint.getOwnedJavaExtensions(), new Predicate<JavaExtension>() { @Override public boolean apply(JavaExtension input) { return JAVA_EXTENSION_QUALIFIED_NAME.equals(input.getQualifiedClassName()); } })) { JavaExtension javaExtension = DescriptionFactory.eINSTANCE.createJavaExtension(); javaExtension.setQualifiedClassName(JAVA_EXTENSION_QUALIFIED_NAME); viewpoint.getOwnedJavaExtensions().add(javaExtension); } } } } }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.query.SequenceDiagramDescriptionQuery.java
/** * return any {@link EndOfLifeMapping} contained in the diagram having the * given name.//from w ww . j a va 2 s.c om * * @param name * name of the searched element. * @return any EndOfLifeMapping contained in the diagram having the given * name. */ public Iterator<EndOfLifeMapping> getEndOfLifeMappings(final String name) { return Iterators.filter(Iterators.filter(diag.eAllContents(), EndOfLifeMapping.class), new Predicate<EndOfLifeMapping>() { public boolean apply(EndOfLifeMapping input) { return name.equals(input.getName()); } }); }
From source file:msi.gama.lang.gaml.ui.templates.GamlEditTemplateDialog.java
public GamlEditTemplateDialog(final Shell parent, final TemplatePersistenceData data, final boolean edit, final ContextTypeRegistry registry, final TemplatesLanguageConfiguration configuration, final IEditedResourceProvider resourceProvider, final String languageName) { super(parent); this.data = data; this.configuration = configuration; this.resourceProvider = resourceProvider; this.languageName = languageName; String title = edit ? TemplateDialogMessages.EditTemplateDialog_title_edit : TemplateDialogMessages.EditTemplateDialog_title_new; setTitle(title);//from w w w . j av a 2 s.c o m // this.fTemplate = data.getTemplate(); // fIsNameModifiable = isNameModifiable; List<String[]> contexts = Lists.newArrayList(); for (Iterator<TemplateContextType> it = Iterators.filter(registry.contextTypes(), TemplateContextType.class); it.hasNext();) { TemplateContextType type = it.next(); contexts.add(new String[] { type.getId(), type.getName() }); } // fContextTypes = contexts.toArray(new String[contexts.size()][]); // fContextTypeRegistry = registry; }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.pinning.AbstractPinUnpinElementsEclipseAction.java
/** * Get current selected diagram elements. * // w w w . j a v a 2s. c om * @param selection * Selection * @return Selected elements. */ private Collection<DDiagramElement> getSelectedDiagramElements(final ISelection selection) { if (selection instanceof IStructuredSelection) { final UnmodifiableIterator<IGraphicalEditPart> iter = Iterators .filter(((IStructuredSelection) selection).iterator(), IGraphicalEditPart.class); final Collection<DDiagramElement> elements = Lists.newArrayList(); while (iter.hasNext()) { final IGraphicalEditPart part = iter.next(); if (keepElement(part)) { final EObject semanticElement = part.resolveSemanticElement(); if (semanticElement instanceof DDiagramElement) { elements.add((DDiagramElement) semanticElement); } } } return elements; } return Collections.emptyList(); }
From source file:qdg.view.SubMixedGraph.java
@Override public Iterator<Edge> getArcIterator() { return Iterators.filter(g.getArcIterator(), spanningEdgeFilterPredicate); }
From source file:org.fcrepo.kernel.modeshape.rdf.impl.ReferencesRdfContext.java
@SuppressWarnings("unchecked") private void putReferencesIntoContext(final Node node) throws RepositoryException { Iterator<Property> references = node.getReferences(); Iterator<Property> weakReferences = node.getWeakReferences(); Iterator<Property> allReferences = Iterators.concat(references, weakReferences); concat(flatMap(allReferences, property2triple)); references = node.getReferences();// w w w . j a v a 2 s. c o m weakReferences = node.getWeakReferences(); allReferences = Iterators.concat(references, weakReferences); concat(Iterators.filter(flatMap(flatMap(allReferences, potentialProxies), triplesForValue), INBOUND::test)); }
From source file:org.eclipse.viatra.query.patternlanguage.emf.scoping.BaseMetamodelProviderService.java
@Override public boolean isGeneratedCodeAvailable(EPackage ePackage, ResourceSet set) { if (getProvidedMetamodels().contains(ePackage.getNsURI())) { Iterator<EClassifier> it = Iterators.filter(ePackage.eAllContents(), EClassifier.class); boolean missingNameFound = false; while (!missingNameFound && it.hasNext()) { final String instanceClassName = it.next().getInstanceClassName(); missingNameFound = Strings.isNullOrEmpty(instanceClassName); }/*from ww w .j a v a 2s . c om*/ GenPackage genPackage = getGenmodelRegistry().findGenPackage(ePackage.getNsURI(), set); return !missingNameFound || genPackage != null; } else { return false; } }
From source file:de.cau.cs.kieler.ecoreviz.OpenDiagramHandler.java
/** * {@inheritDoc}/*from ww w . j a v a 2 s. c o m*/ */ @SuppressWarnings("unchecked") public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { final IStructuredSelection sSelection = (IStructuredSelection) selection; final List<EModelElement> listSelection = new LinkedList<EModelElement>(); if (selection instanceof KlighdTreeSelection) { // do not react on selections in KLighD diagrams return null; } // if all elements are either ecore packages or classes if (Iterators.all(sSelection.iterator(), EPACKAGE_ECLASS_PREDICATE)) { Iterator<EModelElement> emIt = Iterators.filter(sSelection.iterator(), EMODEL_ELEMENT_PREDICATE); while (emIt.hasNext()) { listSelection.add(emIt.next()); } } else { // otherwise check the elements piece by piece for files for (Object o : sSelection.toArray()) { if (o instanceof IFile) { try { IFile f = (IFile) o; ResourceSet rs = new ResourceSetImpl(); Resource r = rs.getResource( URI.createPlatformResourceURI(f.getFullPath().toString(), true), true); if (r.getContents().size() > 0) { if (r.getContents().get(0) instanceof EPackage) { listSelection.add((EModelElement) r.getContents().get(0)); } } } catch (Exception e) { StatusManager.getManager().handle( new Status(IStatus.ERROR, PLUGIN_ID, "Could not load selected file.", e), StatusManager.SHOW); } } else { handleUnknownSelection(selection); return null; } } } EModelElementCollection model = EModelElementCollection.of(listSelection.iterator()); DiagramViewManager.createView("de.cau.cs.kieler.ecoreviz.EModelElementCollectionDiagram", "Ecore Diagram", model, KlighdSynthesisProperties.create()); return null; } handleUnknownSelection(selection); return null; }
From source file:org.apache.fluo.core.util.NotificationScanner.java
@Override public Iterator<RowColumnValue> iterator() { Iterator<RowColumnValue> iter = Iterators.transform(scanner.iterator(), entry -> { Notification n = Notification.from(entry.getKey()); return new RowColumnValue(n.getRow(), n.getColumn(), Bytes.of(entry.getValue().get())); });/* ww w . j av a 2 s. c om*/ return Iterators.filter(iter, rcv -> filter.test(rcv)); }
From source file:org.elasticsearch.index.codec.postingsformat.Elasticsearch090PostingsFormat.java
@Override public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException { final BloomFilteredFieldsConsumer fieldsConsumer = bloomPostings.fieldsConsumer(state); return new FieldsConsumer() { @Override/*from ww w . j a va2 s. c om*/ public void write(Fields fields) throws IOException { Fields maskedFields = new FilterLeafReader.FilterFields(fields) { @Override public Iterator<String> iterator() { return Iterators.filter(this.in.iterator(), Predicates.not(UID_FIELD_FILTER)); } }; fieldsConsumer.getDelegate().write(maskedFields); maskedFields = new FilterLeafReader.FilterFields(fields) { @Override public Iterator<String> iterator() { return Iterators.singletonIterator(UidFieldMapper.NAME); } }; // only go through bloom for the UID field fieldsConsumer.write(maskedFields); } @Override public void close() throws IOException { fieldsConsumer.close(); } }; }