Example usage for com.google.common.collect Iterators filter

List of usage examples for com.google.common.collect Iterators filter

Introduction

In this page you can find the example usage for com.google.common.collect Iterators filter.

Prototype

@SuppressWarnings("unchecked") 
@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) 

Source Link

Document

Returns all elements in unfiltered that are of the type desiredType .

Usage

From source file:nz.ac.massey.cs.guery.PathConstraint.java

public Iterator<? extends Path<V, E>> check(final GraphAdapter<V, E> g, final V source, final V target,
        PathFinder<V, E> finder) {
    if (this.negated) {
        Iterator<Path<V, E>> iter = finder.findLinks(g, source, minLength, maxLength, true, filter, false);
        while (iter.hasNext()) {
            Path<V, E> path = iter.next();
            /** for debugging only
             for (E e:path.getEdges()) {
             System.out.print(e);//from   w w w  . j  av  a  2 s  . c  o m
             System.out.print(",");
             }
             System.out.println();
             */
            if (path.getEnd() == target)
                return Iterators.emptyIterator(); // represents "false"
        }
        return Iterators.singletonIterator(new NoPath<V, E>(source, target));
    } else {
        if (this.computeAll) {
            Iterator<Path<V, E>> allOutgoing = finder.findLinks(g, source, this.minLength, this.maxLength, true,
                    filter, computeAll);
            Predicate<Path<V, E>> connectToTargetFilter = new Predicate<Path<V, E>>() {
                @Override
                public boolean apply(Path<V, E> p) {
                    return p.getEnd() == target;
                }
            };
            return Iterators.filter(allOutgoing, connectToTargetFilter);
        } else {
            Iterator<Path<V, E>> iter = finder.findLinks(g, source, minLength, maxLength, true, filter, false);
            while (iter.hasNext()) {
                Path<V, E> path = iter.next();
                if (path.getEnd() == target)
                    return Iterators.singletonIterator(path);
            }
            return Iterators.emptyIterator();
        }
    }
}

From source file:de.zib.gndms.c3resource.C3ResourceReader.java

private Iterator<C3GridResource> validResources(final InputStream in) {
    return Iterators.filter(readResources(in), new Predicate<C3GridResource>() {
        public boolean apply(@Nullable final C3GridResource resourceParam) {
            return resourceParam != null && resourceParam.getSite() != null;
        }/* w  ww  . jav  a 2 s . c  o m*/
    });
}

From source file:org.fcrepo.kernel.modeshape.rdf.impl.LdpIsMemberOfRdfContext.java

private void concatIsMemberOfRelation(final FedoraResource container) throws RepositoryException {
    final Property property = container.getProperty(LDP_IS_MEMBER_OF_RELATION);

    final Resource memberRelation = createResource(property.getString());
    final Node membershipResource = getMemberResource(container);

    if (membershipResource == null) {
        return;//from  w w  w  .j ava  2  s  .  c  om
    }

    final String insertedContainerProperty;

    if (container.hasType(LDP_INDIRECT_CONTAINER)) {
        if (container.hasProperty(LDP_INSERTED_CONTENT_RELATION)) {
            insertedContainerProperty = container.getProperty(LDP_INSERTED_CONTENT_RELATION).getString();
        } else {
            return;
        }
    } else {
        insertedContainerProperty = MEMBER_SUBJECT.getURI();
    }

    if (insertedContainerProperty.equals(MEMBER_SUBJECT.getURI())) {
        concat(create(subject(), memberRelation.asNode(), membershipResource));
    } else if (container.hasType(LDP_INDIRECT_CONTAINER)) {
        final String insertedContentProperty = getPropertyNameFromPredicate(resource().getNode(),
                createResource(insertedContainerProperty), null);

        if (!resource().hasProperty(insertedContentProperty)) {
            return;
        }

        final PropertyValueIterator values = new PropertyValueIterator(
                resource().getProperty(insertedContentProperty));

        final Iterator<RDFNode> insertedContentRelations = Iterators.filter(
                Iterators.transform(values, valueConverter),
                n -> n.isURIResource() && translator().inDomain(n.asResource()));

        concat(Iterators.transform(insertedContentRelations,
                s -> create(s.asNode(), memberRelation.asNode(), membershipResource)));
    }
}

From source file:com.cloudera.cdk.data.filesystem.FileSystemPartitionIterator.java

FileSystemPartitionIterator(FileSystem fs, Path root, PartitionStrategy strategy, MarkerRange range)
        throws IOException {
    Preconditions.checkArgument(fs.isDirectory(root));
    this.fs = fs;
    this.rootDirectory = root;
    this.iterator = Iterators.filter(Iterators
            .transform(new FileSystemIterator(strategy.getFieldPartitioners().size()), new MakeKey(strategy)),
            new InRange(range));
}

From source file:tech.beshu.ror.es.security.DocumentFieldReader.java

@Override
public Fields getTermVectors(int docID) throws IOException {
    Fields original = in.getTermVectors(docID);

    return new Fields() {
        @Override// ww  w .j  a  v a 2  s.  com
        public Iterator<String> iterator() {
            return Iterators.filter(original.iterator(), s -> policy.canKeep(s));
        }

        @Override
        public Terms terms(String field) throws IOException {
            return policy.canKeep(field) ? original.terms(field) : null;
        }

        @Override
        public int size() {
            return remainingFieldsInfo.size();
        }
    };
}

From source file:org.fcrepo.kernel.impl.rdf.impl.LdpIsMemberOfRdfContext.java

private void concatIsMemberOfRelation(final FedoraResource container) throws RepositoryException {
    final Property property = container.getProperty(LDP_IS_MEMBER_OF_RELATION);

    final Resource memberRelation = createResource(property.getString());
    final Resource membershipResource = getMemberResource(container);

    if (membershipResource == null) {
        return;/*from   w  w w  . j a v a  2  s  . co  m*/
    }

    final String insertedContainerProperty;

    if (container.hasType(LDP_INDIRECT_CONTAINER)) {
        if (container.hasProperty(LDP_INSERTED_CONTENT_RELATION)) {
            insertedContainerProperty = container.getProperty(LDP_INSERTED_CONTENT_RELATION).getString();
        } else {
            return;
        }
    } else {
        insertedContainerProperty = RdfLexicon.MEMBER_SUBJECT.getURI();
    }

    if (insertedContainerProperty.equals(RdfLexicon.MEMBER_SUBJECT.getURI())) {
        concat(create(subject(), memberRelation.asNode(), membershipResource.asNode()));
    } else if (container.hasType(LDP_INDIRECT_CONTAINER)) {
        final String insertedContentProperty = getPropertyNameFromPredicate(resource().getNode(),
                createResource(insertedContainerProperty), null);

        if (!resource().hasProperty(insertedContentProperty)) {
            return;
        }

        final PropertyValueIterator values = new PropertyValueIterator(
                resource().getProperty(insertedContentProperty));

        final Iterator<RDFNode> insertedContentRelations = Iterators
                .filter(Iterators.transform(values, valueConverter), new Predicate<RDFNode>() {
                    @Override
                    public boolean apply(final RDFNode input) {
                        return input.isURIResource() && translator().inDomain(input.asResource());
                    }
                });

        concat(Iterators.transform(insertedContentRelations, new Function<RDFNode, Triple>() {
            @Override
            public Triple apply(final RDFNode input) {
                return create(input.asNode(), memberRelation.asNode(), membershipResource.asNode());
            }
        }));

    }
}

From source file:org.obeonetwork.dsl.uml2.design.internal.services.StereotypeServices.java

/**
 * Unapply a profile//from  ww  w . j  a v a2s  .c  o m
 *
 * @param element
 *            Element
 * @param alreadyAppliedStereotype
 *            Stereotype
 */
public void unapplyProfile(Element element, final Stereotype alreadyAppliedStereotype) {
    // If no other stereotype is used, unapply the profile
    final Profile profile = alreadyAppliedStereotype.getProfile();
    final Package pkg = element.getNearestPackage();
    final List<EObject> stereotypeApplications = Lists.newArrayList();

    final Iterator<Element> it = Iterators.filter(EcoreUtil.getAllProperContents(pkg, true), Element.class);
    while (it.hasNext()) {
        final Element cur = it.next();
        stereotypeApplications.addAll(cur.getStereotypeApplications());
    }

    for (final EObject stereotypeApplication : stereotypeApplications) {
        // Get base class
        final Element baseClass = getBaseClass(stereotypeApplication);
        // Get all applied stereotypes
        for (final Stereotype stereotype : baseClass.getAppliedStereotypes()) {
            // Get profile
            if (stereotype.getProfile().equals(profile)) {
                // If stereotypes are still applied return else unapply profile on package
                return;
            }
        }
    }
    pkg.unapplyProfile(profile);
}

From source file:org.richfaces.renderkit.MessageRendererBase.java

/**
 * <p class="changed_added_4_0">/* w  ww  .  ja  va 2s .c  o  m*/
 * TODO - make Generator aware of Iterator.
 * </p>
 *
 * @param context
 * @param component
 */
protected Iterable<MessageForRender> getVisibleMessages(FacesContext context, UIComponent component) {
    String forId = getFor(component);
    Iterator<MessageForRender> messages = getMessages(context, forId, component);
    UnmodifiableIterator<MessageForRender> filteredMessages = Iterators.filter(messages,
            getMessagesLevelFilter(context, component));
    return Lists.newArrayList(filteredMessages);
}

From source file:com.cloudera.kitten.lua.LuaWrapper.java

public Iterator<LuaPair> hashIterator() {
    return Iterators.filter(iterator(), new Predicate<LuaPair>() {
        @Override// w  ww. j ava 2s. c  o  m
        public boolean apply(LuaPair lp) {
            return !lp.key.isint();
        }
    });
}

From source file:org.apache.giraph.block_app.library.internal.SendMessageWithCombinerPiece.java

/**
 * Stripe message sending computation across multiple stripes, in
 * each stripe only part of the vertices will receive messages.
 *
 * @param stripes Number of stripes//  ww  w.  j  av  a2s.co m
 * @param stripeSupplier Stripe supplier function, if IDs are Longs, you can
 *                       use StripingUtils::fastHashStripingPredicate
 * @return Resulting block
 */
public Block stripeByReceiver(int stripes, Int2ObjFunction<Int2ObjFunction<Predicate<I>>> stripeSupplier) {
    return StripingUtils.generateStripedBlock(stripes, new Function<Predicate<I>, Block>() {
        @Override
        public Block apply(final Predicate<I> stripePredicate) {
            return FilteringPiece.createReceiveFiltering(new SupplierFromVertex<I, V, E, Boolean>() {
                @Override
                public Boolean get(Vertex<I, V, E> vertex) {
                    return stripePredicate.apply(vertex.getId());
                }
            }, new SendMessageWithCombinerPiece<>(name, messageCombiner, messageSupplier,
                    new SupplierFromVertex<I, V, E, Iterator<I>>() {
                        @Override
                        public Iterator<I> get(Vertex<I, V, E> vertex) {
                            return Iterators.filter(targetsSupplier.get(vertex),
                                    new com.google.common.base.Predicate<I>() {
                                        @Override
                                        public boolean apply(I targetId) {
                                            return stripePredicate.apply(targetId);
                                        }
                                    });
                        }
                    }, messagesConsumer));
        }
    }, stripeSupplier);
}