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:org.calrissian.mango.collect.CloseableIterators.java

/**
 * Returns all instances of class {@code type} in {@code unfiltered}. The
 * returned closeable iterator has elements whose class is {@code type} or a subclass of
 * {@code type}./*w  w  w  .  j a v a  2s.  c  o m*/
 */
public static <T> CloseableIterator<T> filter(final CloseableIterator<?> iterator, final Class<T> type) {
    return wrap(Iterators.filter(iterator, type), iterator);
}

From source file:qdg.view.SubMixedGraph.java

@Override
public Iterator<Node> getNodeIterator() {
    return Iterators.filter(g.getNodeIterator(), nodeFilterPredicate);
}

From source file:com.lyndir.lhunath.opal.security.service.impl.SecurityServiceImpl.java

@Override
public <S extends Subject, O extends SecureObject<S, ?>> Iterator<O> filterAccess(final Permission permission,
        final SecurityToken<S> token, final Iterator<O> source) {

    return Iterators.filter(source, new Predicate<O>() {

        @Override//from  w w  w. j  a  v  a 2  s .c o m
        public boolean apply(final O input) {

            return hasAccess(permission, token, input);
        }
    });
}

From source file:at.molindo.notify.util.NotifyUtils.java

/**
 * @param templates/*from  w  w w.  j a va2  s.c  om*/
 *            a list of templates to choose from. keys needn't be equal
 * @param type
 *            null if not required, prefers HTML over TEXT
 * @param version
 *            null if not required, prefers LONG over SHORT
 * 
 * @return the best matching template from list. type is more important than
 *         version
 */
public static Template choose(@Nonnull List<Template> templates, final Type type, final Version version) {

    List<Template> filtered = IteratorUtils
            .list(Iterators.filter(templates.iterator(), new Predicate<Template>() {

                @Override
                public boolean apply(Template input) {
                    if (type != null && type != input.getType()) {
                        return false;
                    }
                    if (version != null && version != input.getVersion()) {
                        return false;
                    }
                    return true;
                }
            }), templates.size());

    switch (filtered.size()) {
    case 0:
        return null;
    case 1:
        return filtered.get(0);
    default:
        Collections.sort(filtered, TEMPLATE_COMPARATOR);
        return filtered.get(0);
    }
}

From source file:net.tridentsdk.server.entity.EntityManager.java

/**
 * Gets all entities with the given type class
 *
 * @param type the type to search for entities
 * @param <T>  the entity type//w w w  . j a  va 2s .co  m
 * @return the list of entities with the specified type
 */
public <T> ArrayList<T> getEntities(final Class<T> type) {
    Predicate<Entity> pred = new Predicate<Entity>() {
        @Override
        public boolean apply(Entity e) {
            return Predicates.assignableFrom(type.getClass()).apply(e.getClass());
        }
    };

    return (ArrayList<T>) Lists.newArrayList(Iterators.filter(this.entities.values().iterator(), pred));
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.query.SequenceDiagramDescriptionQuery.java

/**
 * return any ExecutionMapping contained in the diagram having the given
 * name.// ww  w .j  av  a  2s. co  m
 * 
 * @param name
 *            name of the searched element.
 * @return any ExecutionMapping contained in the diagram having the given
 *         name.
 */
public Iterator<ExecutionMapping> getExecutionMappings(final String name) {
    return Iterators.filter(Iterators.filter(diag.eAllContents(), ExecutionMapping.class),
            new Predicate<ExecutionMapping>() {

                public boolean apply(ExecutionMapping input) {
                    return name.equals(input.getName());
                }

            });
}

From source file:org.apache.accumulo.shell.commands.ListCompactionsCommand.java

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {

    List<String> tservers;
    String filterText = null;// ww  w  .  ja  v a  2  s. c  om

    final InstanceOperations instanceOps = shellState.getAccumuloClient().instanceOperations();

    final boolean paginate = !cl.hasOption(disablePaginationOpt.getOpt());

    if (cl.hasOption(tserverOption.getOpt())) {
        tservers = new ArrayList<>();
        tservers.add(cl.getOptionValue(tserverOption.getOpt()));
    } else {
        tservers = instanceOps.getTabletServers();
    }

    if (cl.hasOption(filterOption.getOpt())) {
        filterText = ".*" + cl.getOptionValue(filterOption.getOpt()) + ".*";
    }

    Iterator<String> activeCompactionIterator = new ActiveCompactionIterator(tservers, instanceOps);
    if (filterText != null) {
        String finalFilterText = filterText;
        activeCompactionIterator = Iterators.filter(activeCompactionIterator, t -> t.matches(finalFilterText));
    }

    shellState.printLines(activeCompactionIterator, paginate);

    return 0;
}

From source file:com.protectwise.cassandra.db.columniterator.FilteringOnDiskAtomIterator.java

public FilteringOnDiskAtomIterator(final OnDiskAtomIterator underlying, IOnDiskAtomFilter filter,
        final ColumnFamilyStore cfs, final boolean dryRun, final IDeletedRecordsSink backupSink) {
    this.underlying = underlying;
    this.filter = filter;
    this.cfs = cfs;
    this.dryRun = dryRun;

    final boolean hasIndexes = cfs.indexManager.hasIndexes();
    if (hasIndexes)
        this.indexedColumnsInRow = new ArrayList<Cell>();
    else//ww w . j  a va  2 s  .c  o  m
        this.indexedColumnsInRow = null;

    iterator = Iterators.filter(underlying, new Predicate<OnDiskAtom>() {
        @Override
        public boolean apply(OnDiskAtom input) {
            if (FilteringOnDiskAtomIterator.this.filter.shouldKeepAtom(underlying, input)) {
                kept += 1;
                return true;
            } else if (dryRun) {
                // Dry run, we're not deleting anything, but record that we would have done so.
                filtered += 1;
                return true;
            } else {
                if (backupSink != null) {
                    backupSink.accept(underlying.getKey(), input);
                }
                // Actually delete the record
                // TODO: BUG: THERE IS A BUG HERE,
                // Records with an indexed clustered key which were created with UPDATE rather than INSERT
                // will not have the clustered key's index cleaned up correctly.  This seems to be a problem found
                // even in vanilla Cassandra's cleanup routine.  When INSERTs are done, a boundary cell is written
                // which becomes responsible for cleaning up the cluster keys during cleanup style operations (which
                // deleting compaction shares much in common with).  During UPDATE no such boundary cell is written,
                // which doesn't leave the appropriate value to trigger index cleanup on.
                // To address that here, we'd need to manufacture a synthetic boundary cell and convict it
                // for cluster keys that are convicted.  Forcing a reindex corrects this, but of course reindexing
                // after deletes is I/O prohibitive.  I suspect but have not tested that this will affect TTLd
                // columns as well.
                if (hasIndexes && input instanceof Cell && cfs.indexManager.indexes((Cell) input)) {
                    indexedColumnsInRow.add((Cell) input);
                }
                filtered += 1;
                return false;
            }
        }
    });
}

From source file:io.druid.java.util.common.guava.FunctionalIterator.java

public <RetType> FunctionalIterator<RetType> keep(Function<T, RetType> fn) {
    return new FunctionalIterator<>(Iterators.filter(Iterators.transform(delegate, fn), Predicates.notNull()));
}

From source file:sg.atom.utils._beta.functional.FunctionalIterator.java

public FunctionalIterator<T> filter(Predicate<T> pred) {
    return new FunctionalIterator<T>(Iterators.filter(delegate, pred));
}