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.jclouds.rest.functions.ReturnNullOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return null;
    } else if (rto404.apply(from)) {
        return null;
    }//from   w  ww.  jav a  2 s  .c o  m
    return Object.class.cast(propagateOrNull(from));
}

From source file:org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404.java

public Void apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return null;
    } else {/* ww  w. ja  v a  2  s. co  m*/
        Boolean value = rto404.apply(from);
        if (value != null && value)
            return null;
    }
    return Void.class.cast(propagateOrNull(from));
}

From source file:co.cask.cdap.logging.appender.LoggingContextMDC.java

LoggingContextMDC(LoggingContext loggingContext, Map<String, String> eventMDC) {
    this.systemTags = loggingContext.getSystemTagsAsString();
    this.eventMDC = eventMDC;
    this.entryIterable = Iterables.concat(systemTags.entrySet(),
            Iterables.filter(eventMDC.entrySet(), new Predicate<Entry<String, String>>() {
                @Override/*from  www  .j a va2  s.  c  om*/
                public boolean apply(Entry<String, String> entry) {
                    return !systemTags.containsKey(entry.getKey());
                }
            }));
}

From source file:org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return PagedIterables.EMPTY;
    } else if (rto404.apply(from)) {
        return PagedIterables.EMPTY;
    }//w  w w  . jav  a  2 s .c om
    throw Throwables.propagate(from);
}

From source file:org.obiba.opal.core.runtime.jdbc.DefaultJdbcDriverRegistry.java

@Override
public Iterable<Driver> listDrivers() {
    return Iterables.filter(Collections.list(DriverManager.getDrivers()), new Predicate<Driver>() {
        @Override// ww  w .  j av  a  2 s.co m
        public boolean apply(Driver driver) {
            return SUPPORTED_DRIVER_CLASS_TO_NAME.containsKey(driver.getClass().getName());
        }
    });
}

From source file:org.apache.curator.x.discovery.details.FilteredInstanceProvider.java

@Override
public List<ServiceInstance<T>> getInstances() throws Exception {
    Iterable<ServiceInstance<T>> filtered = Iterables.filter(instanceProvider.getInstances(), predicates);
    return ImmutableList.copyOf(filtered);
}

From source file:org.sonar.server.component.DefaultComponentFinder.java

private static Collection<Component> search(ComponentQuery query, List<? extends Component> allComponents) {
    return newArrayList(Iterables.filter(allComponents, new MatchQuery(query)));
}

From source file:org.jclouds.rest.functions.ReturnEmptyIterableWithMarkerOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return IterableWithMarkers.EMPTY;
    } else if (rto404.apply(from)) {
        return IterableWithMarkers.EMPTY;
    }//from  ww  w  . j av a 2 s .c o  m
    throw Throwables.propagate(from);
}

From source file:org.cebolla.repositories.AbstractFakeRepository.java

/**
 * Filter all existing entries in the repository with the given predicate
 * and return the filtered entries in an @see java.lang.Iterable.
 *///from  w ww  .  j  a v  a  2  s.c  o  m
public Iterable<EntityType> filter(Predicate<? super EntityType> predicate) {
    return Iterables.filter(entities, predicate);
}

From source file:org.jnario.jnario.test.util.SpecExecutor.java

protected Result runExamples(EObject object) throws MalformedURLException, ClassNotFoundException {
    SpecFile spec = (SpecFile) object;//from  w ww.ja  va2  s  .co m
    CompositeResult result = new CompositeResult();
    String packageName = spec.getPackage();
    for (JnarioTypeDeclaration type : spec.getXtendTypes()) {
        if (!(type instanceof ExampleGroup)) {
            String className = type.getName();
            compileJavaFile(packageName, className);
            loadGeneratedClass(packageName, className);
        }
    }
    for (ExampleGroup exampleGroup : Iterables.filter(spec.getXtendTypes(), ExampleGroup.class)) {
        String specClassName = nameProvider.toJavaClassName(exampleGroup);
        result.add(runTestsInClass(specClassName, packageName));
    }
    return result;
}