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

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

Introduction

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

Prototype

@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType) 

Source Link

Document

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

Usage

From source file:org.estatio.dom.communicationchannel.CommunicationChannelType.java

public static List<CommunicationChannelType> matching(final Class<? extends CommunicationChannel> cls) {
    return Lists/*from  ww w. j  a v a  2  s. com*/
            .newArrayList(Iterables.filter(Arrays.asList(values()), new Predicate<CommunicationChannelType>() {

                @Override
                public boolean apply(final CommunicationChannelType input) {
                    return input.cls == cls;
                }
            }));
}

From source file:com.eviware.loadui.util.ReleasableUtils.java

/**
 * Releases all Releasable objects in the given varargs. For arguments that
 * are a Collection, each of its children will be released.
 * //from   ww  w. j  av  a 2 s.c  om
 * @param objects
 */
public static void releaseAll(Object... objects) {
    for (Object object : objects) {
        if (object instanceof Iterable && !(object instanceof Releasable)) {
            for (Object child : ImmutableSet.copyOf(Iterables.filter((Iterable<?>) object, Object.class)))
                releaseAll(child);
        }
        release(object);
    }
}

From source file:playground.michalm.taxi.util.TaxicabUtils.java

public static int countVehicles(Iterable<? extends Vehicle> vehicles, Predicate<Vehicle> predicate) {
    return Iterables.size(Iterables.filter(vehicles, predicate));
}

From source file:sfsoftware.util.ClasspathHelper.java

public static List<URL> elementsOfFolder(String folder) throws IOException, URISyntaxException {
    List<URL> elements = new ArrayList<>();

    for (URL url : Iterables.filter(getClasspath(), JarFile)) {
        JarFile jar = new JarFile(url.getPath().replaceAll("%20", " "));
        for (JarEntry entry : Collections.list(jar.entries())) {
            String name = entry.getName();
            if (name.startsWith(folder)) {
                elements.add(new URL("jar:" + url + "!/" + name));
            }/*from  w  w  w .j a va 2  s  .  com*/
        }
        jar.close();
    }
    for (URL url : Iterables.filter(getClasspath(), Folder)) {
        Path root = Paths.get(url.toURI());
        FileCollector collector = new FileCollector(root.resolve(folder));
        Files.walkFileTree(root, collector);
        elements.addAll(collector.collected);
    }

    return elements;
}

From source file:org.elasticsearch.search.aggregations.LeafBucketCollector.java

public static LeafBucketCollector wrap(Iterable<LeafBucketCollector> collectors) {
    final Iterable<LeafBucketCollector> actualCollectors = Iterables.filter(collectors,
            new Predicate<LeafBucketCollector>() {
                @Override/* www .  java2s . com*/
                public boolean apply(LeafBucketCollector c) {
                    return c != NO_OP_COLLECTOR;
                }
            });
    final LeafBucketCollector[] colls = Iterables.toArray(actualCollectors, LeafBucketCollector.class);
    switch (colls.length) {
    case 0:
        return NO_OP_COLLECTOR;
    case 1:
        return colls[0];
    default:
        return new LeafBucketCollector() {

            @Override
            public void setScorer(Scorer s) throws IOException {
                for (LeafBucketCollector c : colls) {
                    c.setScorer(s);
                }
            }

            @Override
            public void collect(int doc, long bucket) throws IOException {
                for (LeafBucketCollector c : colls) {
                    c.collect(doc, bucket);
                }
            }

        };
    }
}

From source file:org.trancecode.concurrent.TcFutures.java

public static <T> Iterable<Future<T>> done(final Iterable<Future<T>> tasks) {
    final Predicate<Future<T>> filter = FuturePredicates.isDone();
    return Iterables.filter(tasks, filter);
}

From source file:uk.co.blackpepper.common.model.Identifiables.java

public static <T extends Identifiable<?>> Iterable<T> getPersistents(Iterable<T> identifiables) {
    return Iterables.filter(identifiables, arePersistent());
}

From source file:org.zalando.crypto.Decrypters.java

public static List<Decrypter> findByPrefix(List<Decrypter> decrypters, String prefix) {
    Preconditions.checkNotNull(decrypters, "'Decrypter's-list should not be null");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(prefix), "'prefix' should never be null or empty.");
    return Lists.newArrayList(Iterables.filter(decrypters,
            Predicates.and(new PrefixedDecrypterPredicate(), new PrefixPredicate(prefix))));
}

From source file:jflowmap.util.CollectionUtils.java

/**
 * @param pattern Regular expression//from w w  w . j ava 2 s  .  co  m
 */
public static Iterable<String> filterByPattern(Iterable<String> items, final String pattern) {
    return Iterables.filter(items, new Predicate<String>() {
        Pattern p = Pattern.compile(pattern);

        @Override
        public boolean apply(String attr) {
            return p.matcher(attr).matches();
        }
    });
}

From source file:com.isotrol.impe3.core.component.Operators.java

static Iterable<Method> filter(Iterable<Method> methods, Class<? extends Annotation> annotation) {
    return Iterables.filter(methods, annotated(annotation));
}