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.ReturnEmptyMapOnNotFoundOr404.java

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return ImmutableMap.of();
    } else if (rto404.apply(from)) {
        return ImmutableMap.of();
    }/*from   ww w  .j ava 2s.c om*/
    return Map.class.cast(propagateOrNull(from));
}

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

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

From source file:org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404.java

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

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

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

From source file:org.sonar.batch.issue.DefaultProjectIssues.java

@Override
public Iterable<Issue> resolvedIssues() {
    return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(true)),
            new IssueTransformer());
}

From source file:org.isisaddons.app.kitchensink.dom.mixins.mixin.Person_firstLove.java

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public FoodStuff $$() {
    final List<FoodStuff> loves = Lists.newArrayList(Iterables.transform(
            Iterables.filter(preferences.listAllPreferences(),
                    Predicates.preferenceOf(person, Preference.PreferenceType.LOVE)),
            Preference.Functions.food()));
    return loves.isEmpty() ? null : loves.get(0);
}

From source file:com.google.api.codegen.config.ResourceNameOneofConfig.java

public Iterable<SingleResourceNameConfig> getSingleResourceNameConfigs() {
    return Iterables.filter(getResourceNameConfigs(), SingleResourceNameConfig.class);
}

From source file:org.eclipse.sirius.tree.business.internal.helper.TreeItemHelper.java

/**
 * Returns a DTreeItem referencing the given semantic element, if any
 * exists.//from  www.j  av a2s  .c o  m
 * 
 * @param semanticElement
 *            the semantic element
 * @return a DTreeItem referencing the given semantic element, or
 *         Options.none if no such TreeItem can be found.
 */
public static Option<DTreeItem> getTreeItem(EObject semanticElement) {
    Option<DTreeItem> treeItem = Options.newNone();
    Iterable<DTreeItem> filter = Iterables.filter(semanticElement.eCrossReferences(), DTreeItem.class);
    if (filter.iterator().hasNext()) {
        treeItem = Options.newSome(filter.iterator().next());
    }
    return treeItem;
}

From source file:brooklyn.location.docker.strategy.BasicDockerPlacementStrategy.java

@Override
public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity context) {
    if (locations == null || locations.isEmpty()) {
        return ImmutableList.of();
    }/*from  www .ja  v  a  2 s.c  o  m*/

    List<DockerHostLocation> available = MutableList.copyOf(locations);
    Collections.sort(available, this);
    return ImmutableList.copyOf(Iterables.filter(available, this));
}

From source file:org.jclouds.functions.ExceptionToValueOrPropagate.java

@SuppressWarnings("unchecked")
@Override//from w ww .  ja  v  a 2  s. com
public T apply(Exception from) {
    checkNotNull(from, "exception");
    List<Throwable> throwables = Throwables.getCausalChain(from);
    Iterable<E> matchingThrowables = Iterables.filter(throwables, matchingClass);
    if (Iterables.size(matchingThrowables) >= 1)
        return value;
    return (T) Throwables2.propagateOrNull(from);
}