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:io.wcm.testing.mock.aem.MockPage.java
@Override public Iterator<Page> listChildren(final Filter<Page> filter, final boolean deep) { Iterator<Resource> resources; if (deep) {//from ww w . ja va 2s. co m resources = new DeepResourceIterator(resource); } else { resources = resource.getResourceResolver().listChildren(resource); } // transform resources to pages final Iterator<Page> pages = Iterators.transform(resources, new Function<Resource, Page>() { @Override public Page apply(Resource resourceItem) { return resourceItem.adaptTo(Page.class); } }); // filter pages return Iterators.filter(pages, new Predicate<Page>() { @Override public boolean apply(Page pageItem) { return pageItem != null && (filter == null || filter.includes(pageItem)); } }); }
From source file:org.geogit.geotools.plumbing.ExportOp.java
private static Iterator<SimpleFeature> getFeatures(final RevTree typeTree, final ObjectDatabase database, final ObjectId defaultMetadataId, final ProgressListener progressListener) { Iterator<NodeRef> nodes = new DepthTreeIterator("", defaultMetadataId, typeTree, database, Strategy.FEATURES_ONLY);// ww w . ja v a 2 s . co m // progress reporting nodes = Iterators.transform(nodes, new Function<NodeRef, NodeRef>() { private AtomicInteger count = new AtomicInteger(); @Override public NodeRef apply(NodeRef input) { progressListener.progress((count.incrementAndGet() * 100.f) / typeTree.size()); return input; } }); Function<NodeRef, SimpleFeature> asFeature = new Function<NodeRef, SimpleFeature>() { private Map<ObjectId, FeatureBuilder> ftCache = Maps.newHashMap(); @Override @Nullable public SimpleFeature apply(final NodeRef input) { final ObjectId metadataId = input.getMetadataId(); final RevFeature revFeature = database.getFeature(input.objectId()); FeatureBuilder featureBuilder = getBuilderFor(metadataId); Feature feature = featureBuilder.build(input.name(), revFeature); feature.getUserData().put(Hints.USE_PROVIDED_FID, true); feature.getUserData().put(RevFeature.class, revFeature); feature.getUserData().put(RevFeatureType.class, featureBuilder.getType()); if (feature instanceof SimpleFeature) { return (SimpleFeature) feature; } return null; } private FeatureBuilder getBuilderFor(final ObjectId metadataId) { FeatureBuilder featureBuilder = ftCache.get(metadataId); if (featureBuilder == null) { RevFeatureType revFtype = database.getFeatureType(metadataId); featureBuilder = new FeatureBuilder(revFtype); ftCache.put(metadataId, featureBuilder); } return featureBuilder; } }; Iterator<SimpleFeature> asFeatures = Iterators.transform(nodes, asFeature); UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull()); return filterNulls; }
From source file:com.puppetlabs.geppetto.pp.dsl.linking.NameInScopeFilter.java
public Iterator<IEObjectDescription> iterator() { return Iterators.filter(unfiltered.iterator(), filter); }
From source file:org.apache.kylin.cube.cuboid.DefaultCuboidScheduler.java
/** * Get all parent for children cuboids, considering dim cap. * @param children children cuboids/*from ww w . j ava2 s . c o m*/ * @return all parents cuboids */ private Set<Long> getOnTreeParentsByLayer(Collection<Long> children) { Set<Long> parents = new HashSet<>(); for (long child : children) { parents.addAll(getOnTreeParents(child)); } parents = Sets.newHashSet(Iterators.filter(parents.iterator(), new Predicate<Long>() { @Override public boolean apply(@Nullable Long cuboidId) { if (cuboidId == Cuboid.getBaseCuboidId(cubeDesc)) { return true; } for (AggregationGroup agg : cubeDesc.getAggregationGroups()) { if (agg.isOnTree(cuboidId) && checkDimCap(agg, cuboidId)) { return true; } } return false; } })); return parents; }
From source file:org.eclipse.xtext.generator.parser.packrat.PackratParserGenUtil.java
public static Iterator<Keyword> getConflictingKeywords(final TerminalRule rule, final Iterator<Keyword> allKeywords) { return Iterators.filter(allKeywords, new Predicate<Keyword>() { @Override/* w w w . ja v a2 s . c o m*/ public boolean apply(Keyword param) { final ParserRule containerRule = EcoreUtil2.getContainerOfType(param, ParserRule.class); if (containerRule == null) return false; TerminalRuleInterpreter interpreter = new TerminalRuleInterpreter(param); return interpreter.matches(rule); } }); }
From source file:org.eclipse.sirius.diagram.sequence.ui.business.internal.migration.SequenceDiagramRepresentationsFileMigrationParticipant.java
private void migrateGMFBoundsOfCollapsedBorderedNode(List<Diagram> sequenceDiagrams) { for (Diagram diagram : sequenceDiagrams) { // 1-Add new IndirectlyCollapseFilter migrateChildrenOfCollapsedNode(diagram); // 2-Set width and height of graphical filters of collapsed nodes // (directly or not) with GMF size and set GMF bounds. Iterator<Node> viewIterator = Iterators.filter(Iterators.filter(diagram.eAllContents(), Node.class), Predicates.and(isNode, isCollapsedNode)); while (viewIterator.hasNext()) { Node node = viewIterator.next(); DNode dNode = (DNode) node.getElement(); LayoutConstraint layoutConstraint = node.getLayoutConstraint(); if (layoutConstraint instanceof Bounds) { Bounds bounds = (Bounds) layoutConstraint; // The GMF node size must be stored in collapse filter (to // can // set this size when this node is expanded). for (GraphicalFilter graphicalFilter : dNode.getGraphicalFilters()) { if (graphicalFilter instanceof CollapseFilter) { ((CollapseFilter) graphicalFilter).setWidth(bounds.getWidth()); ((CollapseFilter) graphicalFilter).setHeight(bounds.getHeight()); }//from w w w. ja v a 2 s . co m } // Set new collapsed GMF bounds SequenceCollapseUpdater scbu = new SequenceCollapseUpdater(); scbu.collapseBounds(node, dNode); } } } }
From source file:org.eclipse.emf.ecoretools.design.service.DesignServices.java
public boolean hasNoClassifier(DSemanticDiagram diagram) { Iterator<DSemanticDecorator> it = Iterators.filter(diagram.getOwnedDiagramElements().iterator(), DSemanticDecorator.class); while (it.hasNext()) { DSemanticDecorator dec = it.next(); if (dec.getTarget() instanceof EClassifier) return true; }/* www.j a v a 2s .c o m*/ return false; }
From source file:org.geogit.api.porcelain.LogOp.java
/** * Executes the log operation./* w ww .j a v a 2 s.c o m*/ * * @return the list of commits that satisfy the query criteria, most recent first. * @see org.geogit.api.AbstractGeoGitOp#call() */ @Override public Iterator<RevCommit> call() { ObjectId newestCommitId; ObjectId oldestCommitId; { if (this.until == null) { newestCommitId = command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); } else { if (!repository.commitExists(this.until)) { throw new IllegalArgumentException( "Provided 'until' commit id does not exist: " + until.toString()); } newestCommitId = this.until; } if (this.since == null) { oldestCommitId = ObjectId.NULL; } else { if (!repository.commitExists(this.since)) { throw new IllegalArgumentException( "Provided 'since' commit id does not exist: " + since.toString()); } oldestCommitId = this.since; } } Iterator<RevCommit> history; if (firstParent) { history = new LinearHistoryIterator(newestCommitId, repository); } else { if (commits.isEmpty()) { commits.add(newestCommitId); } if (topo) { history = new TopologicalHistoryIterator(commits, repository, graphDb); } else { history = new ChronologicalHistoryIterator(commits, repository); } } LogFilter filter = new LogFilter(oldestCommitId, timeRange, paths, author, commiter); Iterator<RevCommit> filteredCommits = Iterators.filter(history, filter); if (skip != null) { Iterators.advance(filteredCommits, skip.intValue()); } if (limit != null) { filteredCommits = Iterators.limit(filteredCommits, limit.intValue()); } return filteredCommits; }
From source file:org.obeonetwork.dsl.uml2.design.api.services.CompositeStructureDiagramServices.java
/** * Get required interfaces./*from w ww .j a v a2s . com*/ * * @param diagram * Diagram * @return The interfaces used by ports visible on the diagram */ public Collection<EObject> getPortUsage(DDiagram diagram) { final Set<EObject> result = Sets.newLinkedHashSet(); if (diagram instanceof DSemanticDecorator) { final Session sess = SessionManager.INSTANCE.getSession(((DSemanticDecorator) diagram).getTarget()); final Iterator<EObject> it = Iterators.transform( Iterators.filter(diagram.eAllContents(), AbstractDNode.class), new Function<AbstractDNode, EObject>() { public EObject apply(AbstractDNode input) { return input.getTarget(); } }); while (it.hasNext()) { final EObject displayedAsANode = it.next(); if (displayedAsANode != null) { for (final Setting xRef : sess.getSemanticCrossReferencer() .getInverseReferences(displayedAsANode)) { EObject eObject = xRef.getEObject(); if (eObject instanceof DNode) { eObject = ((DNode) eObject).getTarget(); } if (sess.getModelAccessor().eInstanceOf(eObject, "Port")) { //$NON-NLS-1$ final Port port = (Port) eObject; if (port.getRequireds().size() > 0) { result.add(port); } } } } } } return result; }
From source file:de.uni_stuttgart.iste.cowolf.model.sequence_diagram.sirius.editor.design.services.UMLServices.java
/** * Retrieve the cross references of the given type of all the UML elements displayed as node in a Diagram. * Note that a Property cross reference will lead to retrieve the cross references of this property. * //w ww.ja v a2 s . co m * @param diagram * a diagram. * @param typeName * the expected type. * @return the list of cross reference of the given */ private Collection<EObject> getNodeInverseRefs(DDiagram diagram, String typeName) { Set<EObject> result = Sets.newLinkedHashSet(); if (diagram instanceof DSemanticDecorator) { Session sess = SessionManager.INSTANCE.getSession(((DSemanticDecorator) diagram).getTarget()); Iterator<EObject> it = Iterators.transform( Iterators.filter(diagram.eAllContents(), AbstractDNode.class), new Function<AbstractDNode, EObject>() { public EObject apply(AbstractDNode input) { return input.getTarget(); } }); while (it.hasNext()) { EObject displayedAsANode = it.next(); if (displayedAsANode != null) { for (Setting xRef : sess.getSemanticCrossReferencer().getInverseReferences(displayedAsANode)) { EObject eObject = xRef.getEObject(); if (sess.getModelAccessor().eInstanceOf(eObject, typeName)) { result.add(eObject); } /* * In the case of an association the real interesting object is the association linked * to the Property and not the direct cross reference. */ if (eObject instanceof Property) { if (((Property) eObject).getAssociation() != null) { if (sess.getModelAccessor().eInstanceOf(((Property) eObject).getAssociation(), typeName)) { result.add(((Property) eObject).getAssociation()); } } } } } } } return result; }