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:io.joynr.util.AnnotationUtil.java

public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotationType) {
    Iterable<T> allAnnotations = Iterables.filter(getAnnotationsRecursive(clazz), annotationType);
    if (allAnnotations.iterator().hasNext()) {
        return allAnnotations.iterator().next();
    }//from  w ww  .  j  a  va 2  s .  c om
    return null;
}

From source file:org.robotframework.red.viewers.Selections.java

public static <T> List<T> getElements(final IStructuredSelection selection, final Class<T> elementsClass) {
    return newArrayList(Iterables.filter(selection.toList(), elementsClass));
}

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

public static List<Decrypter> nonPrefixedDecrypters(List<Decrypter> toFilter) {
    return Lists.newArrayList(Iterables.filter(toFilter, new PrefixedDecrypterPredicate()));
}

From source file:uk.ac.stfc.isis.ibex.ui.configserver.editing.blocks.filters.UsedIocFilter.java

public static Collection<EditableIoc> filterIocs(Collection<EditableIoc> unfiltered) {
    return Lists.newArrayList(Iterables.filter(unfiltered, new Predicate<EditableIoc>() {
        @Override/*from   w ww. ja  v  a2 s .  com*/
        public boolean apply(EditableIoc ioc) {
            return !isDefault(ioc);
        }
    }));
}

From source file:org.isisaddons.app.kitchensink.dom.SomeSubcategory.java

public static Iterable<SomeSubcategory> under(final SomeCategory category) {
    return Iterables.filter(Arrays.asList(values()), new Predicate<SomeSubcategory>() {
        @Override//ww  w  . ja  v  a2s .  c  o  m
        public boolean apply(SomeSubcategory input) {
            return input.category == category;
        }
    });
}

From source file:io.sidecar.util.CollectionUtils.java

public static <T> ImmutableSet<T> filterNulls(Set<T> orig) {
    if (orig == null) {
        return ImmutableSet.of();
    }/*w  w w .  j av a  2 s  .  c o m*/
    return ImmutableSet.copyOf(Iterables.filter(orig, new Predicate<T>() {
        @Override
        public boolean apply(T t) {
            return t != null;
        }
    }));
}

From source file:de.flapdoodle.guava.Merger.java

public static <T> ImmutableList<T> merge(Iterable<? extends T> left, Iterable<? extends T> right,
        Equivalence<? super T> matcher, Foldleft<? super T, T> fold) {
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    Iterable<? extends T> notMerged = right;
    for (T l : left) {
        Iterable<? extends T> matching = Iterables.filter(notMerged, matcher.equivalentTo(l));
        notMerged = Iterables.filter(notMerged, Predicates.not(matcher.equivalentTo(l)));

        boolean noMatching = true;
        for (T r : matching) {
            builder.add(fold.apply(l, r));
            noMatching = false;//from  ww w  .ja v a  2s .com
        }
        if (noMatching) {
            builder.add(l);
        }
    }
    builder.addAll(notMerged);
    return builder.build();
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.MapPropertyAdapter.java

public static Iterable<Object> stringsOnly(Iterable<Object> input) {
    return Iterables.filter(input, new Predicate<Object>() {
        @Override/*from w  w  w  . j  a va 2s  . c om*/
        public boolean apply(Object input) {
            return input != null && input instanceof String;
        }
    });
}

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

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

From source file:com.facebook.buck.rules.DependencyAggregationTestUtil.java

/**
 * Return dependencies of a rule, traversing through any dependency aggregations.
 *//*w  w  w.java 2s .  com*/
public static Iterable<BuildRule> getDisaggregatedDeps(BuildRule rule) {
    return FluentIterable.from(rule.getDeps()).filter(DependencyAggregation.class)
            .transformAndConcat(new Function<DependencyAggregation, Iterable<BuildRule>>() {
                @Override
                public Iterable<BuildRule> apply(DependencyAggregation input) {
                    return input.getDeps();
                }
            }).append(Iterables.filter(rule.getDeps(),
                    Predicates.not(Predicates.instanceOf(DependencyAggregation.class))));
}