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.apache.cassandra.io.LazilyCompactedRow.java
public Iterator<IColumn> iterator() { for (SSTableIdentityIterator row : rows) { row.reset();//from w w w.ja va2 s . c o m } iter = new LazyColumnIterator(new CollatingIterator(getComparator().columnComparator, rows)); return Iterators.filter(iter, Predicates.notNull()); }
From source file:gr.forth.ics.swkm.model2.index.HorizontalModelIndexer.java
public Iterator<Resource> findInNamespace(final RdfType type, final Uri namespace) { if (!type.isSchema()) { throw new IllegalArgumentException("Requested type: " + type + " is not schema"); }//w w w .ja v a 2 s. com if (namespace.getLocalName().length() > 0) { throw new IllegalArgumentException( "Uri: '" + namespace + "' is not purely a namespace; it also contains a local part"); } return Iterators.filter(allResources().iterator(), new Predicate<Resource>() { public boolean apply(Resource resource) { return resource.type() == type && resource.getUri().hasEqualNamespace(namespace); } }); }
From source file:org.eclipse.xtext.ide.editor.contentassist.IndentationAwareCompletionPrefixProvider.java
private PeekingIterator<ILeafNode> createReversedLeafIterator(INode root, INode candidate, LinkedList<ILeafNode> sameGrammarElement) { EObject grammarElement = null;/*from w w w . j a v a 2s . c o m*/ PeekingIterator<ILeafNode> iterator = Iterators .peekingIterator(Iterators.filter(root.getAsTreeIterable().reverse().iterator(), ILeafNode.class)); // traverse until we find the current candidate while (iterator.hasNext()) { ILeafNode next = iterator.next(); if (candidate.equals(next)) { break; } else if (next.getTotalLength() == 0) { EObject otherGrammarElement = tryGetGrammarElementAsRule(next); if (grammarElement == null) { grammarElement = otherGrammarElement; } if (otherGrammarElement.equals(grammarElement)) { sameGrammarElement.add(next); } else { sameGrammarElement.removeLast(); } } } return iterator; }
From source file:org.locationtech.geogig.geotools.plumbing.ExportOp.java
/** * Executes the export operation using the parameters that have been specified. * /*ww w .j a v a2s . com*/ * @return a FeatureCollection with the specified features */ @Override protected SimpleFeatureStore _call() { final ObjectDatabase database = objectDatabase(); if (filterFeatureTypeId != null) { RevObject filterType = database.getIfPresent(filterFeatureTypeId); checkArgument(filterType instanceof RevFeatureType, "Provided filter feature type is does not exist"); } final SimpleFeatureStore targetStore = getTargetStore(); final String refspec = resolveRefSpec(); final String treePath = refspec.substring(refspec.indexOf(':') + 1); final RevTree rootTree = resolveRootTree(refspec); final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree); final ObjectId defaultMetadataId = typeTreeRef.getMetadataId(); final RevTree typeTree = database.getTree(typeTreeRef.objectId()); final ProgressListener progressListener = getProgressListener(); progressListener.started(); progressListener .setDescription("Exporting from " + path + " to " + targetStore.getName().getLocalPart() + "... "); final Iterator<SimpleFeature> filtered; { final Iterator<SimpleFeature> plainFeatures = getFeatures(typeTree, database, defaultMetadataId, progressListener); Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures, defaultMetadataId); Iterator<Optional<Feature>> transformed = Iterators.transform(adaptedFeatures, ExportOp.this.function); Iterator<SimpleFeature> result = Iterators .filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() { @Override public SimpleFeature apply(Optional<Feature> input) { return (SimpleFeature) input.orNull(); } }), Predicates.notNull()); // check the resulting schema has something to contribute PeekingIterator<SimpleFeature> peekingIt = Iterators.peekingIterator(result); if (peekingIt.hasNext()) { Function<AttributeDescriptor, String> toString = new Function<AttributeDescriptor, String>() { @Override public String apply(AttributeDescriptor input) { return input.getLocalName(); } }; SimpleFeature peek = peekingIt.peek(); Set<String> sourceAtts = new HashSet<String>( Lists.transform(peek.getFeatureType().getAttributeDescriptors(), toString)); Set<String> targetAtts = new HashSet<String>( Lists.transform(targetStore.getSchema().getAttributeDescriptors(), toString)); if (Sets.intersection(sourceAtts, targetAtts).isEmpty()) { throw new GeoToolsOpException(StatusCode.UNABLE_TO_ADD, "No common attributes between source and target feature types"); } } filtered = peekingIt; } FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() { @Override public FeatureIterator<SimpleFeature> features() { return new DelegateFeatureIterator<SimpleFeature>(filtered); } }; // add the feature collection to the feature store final Transaction transaction; if (transactional) { transaction = new DefaultTransaction("create"); } else { transaction = Transaction.AUTO_COMMIT; } try { targetStore.setTransaction(transaction); try { targetStore.addFeatures(asFeatureCollection); transaction.commit(); } catch (final Exception e) { if (transactional) { transaction.rollback(); } Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class); throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD); } finally { transaction.close(); } } catch (IOException e) { throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD); } progressListener.complete(); return targetStore; }
From source file:org.eclipse.sirius.business.api.componentization.ViewpointRegistryImpl.java
/** * Avoid instantiation.//from w w w .j ava 2 s .c om */ public ViewpointRegistryImpl() { collectors = Maps.newHashMap(); collectors.put(SiriusUtil.DESCRIPTION_MODEL_EXTENSION, new ViewpointFileCollector() { @Override public boolean isValid(final EObject descRoot) { boolean result; if (descRoot instanceof Group) { result = true; } else { result = false; if (descRoot == null) { // Nothing, already been log } else { SiriusPlugin.getDefault().warning( MessageFormat.format(Messages.ViewpointRegistryImpl_cantLoadVSMErrorMsg, descRoot.eResource().getURI()), new RuntimeException(Messages.ViewpointRegistryImpl_cantDeployVSMErrorMsg)); } } return result; } @Override public Collection<Viewpoint> collect(EObject root) { return Lists.newArrayList(Iterators.filter(root.eAllContents(), Viewpoint.class)); } }); prepareFoundCache(); }
From source file:org.wso2.developerstudio.eclipse.ds.provider.choiceListProvider.DSPropertyDescriptor.java
private static void populateQueryIds(Object object) { if (object instanceof EObject) { rootObject = EcoreUtil.getRootContainer((EObject) object); // Get the Query elements in the tree Iterator<Query> queryIterator = Iterators.filter(((EObject) rootObject).eAllContents(), Query.class); queryList = new ArrayList<String>(); while (queryIterator.hasNext()) { Query query = queryIterator.next(); queryList.add(query.getId()); }/*from w ww . j a v a 2 s . com*/ } }
From source file:com.thinkbiganalytics.metadata.core.dataset.InMemoryDatasourceProvider.java
@Override public List<Datasource> getDatasources(DatasourceCriteria criteria) { // TODO replace cast with copy method DatasetCriteriaImpl critImpl = (DatasetCriteriaImpl) criteria; Iterator<Datasource> filtered = Iterators.filter(this.datasets.values().iterator(), critImpl); Iterator<Datasource> limited = Iterators.limit(filtered, critImpl.getLimit()); List<Datasource> list = Lists.newArrayList(limited); Collections.sort(list, critImpl); return list;// w ww . j a v a 2 s .c o m }
From source file:org.apache.tajo.engine.planner.physical.CommonJoinExec.java
/** * Return an tuple iterator filters rows in a right table by using a join filter. * It must takes rows of a right table./* ww w .j a v a 2 s. com*/ * * @param rightTuples Tuple iterator * @return rows Filtered by a join filter on right table. */ protected Iterator<Tuple> rightFiltered(Iterable<Tuple> rightTuples) { if (rightTuples == null) { return Iterators.emptyIterator(); } if (rightJoinFilter == null) { return rightTuples.iterator(); } return Iterators.filter(rightTuples.iterator(), new Predicate<Tuple>() { @Override public boolean apply(Tuple input) { return rightJoinFilter.eval(input).isTrue(); } }); }
From source file:org.obeonetwork.dsl.uml2.design.api.services.ReusedDescriptionServices.java
private List<EObject> allValidSessionElements(EObject cur, Predicate<EObject> validForClassDiagram) { final Session found = SessionManager.INSTANCE.getSession(cur); final List<EObject> result = Lists.newArrayList(); if (found != null) { for (final Resource res : found.getSemanticResources()) { if (res.getURI().isPlatformResource() || res.getURI().isPlatformPlugin()) { Iterators.addAll(result, Iterators.filter(res.getAllContents(), validForClassDiagram)); }//from www. j a va 2s .c o m } } return result; }
From source file:org.apache.phoenix.index.IndexMaintainer.java
public static Iterator<PTable> enabledLocalIndexIterator(Iterator<PTable> indexes) { return Iterators.filter(indexes, new Predicate<PTable>() { @Override//from w w w.ja v a 2s. c o m public boolean apply(PTable index) { return !PIndexState.DISABLE.equals(index.getIndexState()) && index.getIndexType().equals(IndexType.LOCAL); } }); }