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:com.google.template.soy.soytree.SoyFileSetNode.java

/** Returns all child {@link SoyFileNode} that have {@link SoyFileKind#SRC}. */
public ImmutableList<SoyFileNode> getSourceFiles() {
    return ImmutableList.copyOf(Iterables.filter(getChildren(), SoyFileNode.MATCH_SRC_FILENODE));
}

From source file:io.druid.query.datasourcemetadata.DataSourceQueryQueryToolChest.java

@Override
public <T extends LogicalSegment> List<T> filterSegments(DataSourceMetadataQuery query, List<T> segments) {
    if (segments.size() <= 1) {
        return segments;
    }//from w  ww.j  a va  2s.  co m

    final T max = segments.get(segments.size() - 1);

    return Lists.newArrayList(Iterables.filter(segments, new Predicate<T>() {
        @Override
        public boolean apply(T input) {
            return max != null && input.getInterval().overlaps(max.getInterval());
        }
    }));
}

From source file:com.threerings.tools.gxlate.spreadsheet.Folder.java

/**
 * Gets the documents in the folder that are spreadsheets.
 */
public Iterable<DocumentListEntry> getSpreadsheets() {
    return Iterables.filter(_docs, IS_SPREADSHEET);
}

From source file:todoapp.dom.similarto.SimilarToContributions.java

@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
@Action(semantics = SemanticsOf.SAFE)
public List<ToDoItem> similarTo(final ToDoItem toDoItem) {
    final List<ToDoItem> similarToDoItems = toDoItemRepository.findByAtPathAndCategory(currentUsersAtPath(),
            toDoItem.getCategory());// w w w  .j  a v a2s .  co m
    return Lists.newArrayList(Iterables.filter(similarToDoItems, $_ -> $_ != toDoItem));
}

From source file:objstore.jdo.todo.ToDoItemsJdo.java

@Override
public List<ToDoItem> similarTo(final ToDoItem thisToDoItem) {
    final List<ToDoItem> similarToDoItems = allMatches(
            new QueryDefault<ToDoItem>(ToDoItem.class, 
                    "todo_similarTo", 
                    "ownedBy", currentUserName(), 
                    "category", thisToDoItem.getCategory()));
    return Lists.newArrayList(Iterables.filter(similarToDoItems, excluding(thisToDoItem)));
}

From source file:com.isotrol.impe3.core.engine.CategoryRoutingMap.java

CategoryRoutingMap(final Categories categories) {
    final CacheLoader<CRKey, ImmutableMap<String, Category>> computer = new CacheLoader<CRKey, ImmutableMap<String, Category>>() {
        public ImmutableMap<String, Category> load(CRKey from) {
            try {
                final List<Category> children = categories.getChildren(from.getId());
                if (children == null || children.isEmpty()) {
                    return ImmutableMap.of();
                }/*from   w ww . ja  v a  2 s  . c o m*/
                // No builder to avoid errors because of duplicates.
                final Map<String, Category> map = Maps.newHashMap();
                final Locale locale = from.getLocale();
                for (Category c : Iterables.filter(children, IS_ROUTABLE)) {
                    try {
                        final String segment = c.getName().get(locale).getPath();
                        if (segment != null) {
                            map.put(segment, c);
                        }
                    } catch (RuntimeException e) {
                        Loggers.core().error("Unable to compute CRMap segment for category [{}]: {}",
                                new Object[] { c.getId(), e.getMessage() });
                    }
                }
                return ImmutableMap.copyOf(map);
            } catch (RuntimeException e) {
                Loggers.core().error("Unable to compute CRMap value map for category [{}]: {}",
                        new Object[] { from.getId(), e.getMessage() });
                return ImmutableMap.of();
            }
        }
    };
    this.cache = CacheBuilder.newBuilder().build(computer);
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.java

public Iterable<KbaChangeSet> getKeyBindingsChangeSetsWith(Action action) {
    return Iterables.filter(kbaChangeSetList, matches(action));
}

From source file:org.eclipse.sirius.diagram.ui.business.internal.command.ViewDeleteCommand.java

@Override
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
        throws ExecutionException {
    // Prevents GMF to install its CrossReferencerAdapter by not calling
    // ViewUtil.destroy(View)

    // Remove incoming or outgoing NoteAttachment links
    for (Edge edge : Iterables.filter(Iterables.concat(getView().getSourceEdges(), getView().getTargetEdges()),
            Edge.class)) {
        if (ViewType.NOTEATTACHMENT.equals(edge.getType())) {
            EcoreUtil.remove(edge);/*from  w  w  w. j a  v a 2 s .c o m*/
        }
    }
    EcoreUtil.remove(getView());
    return CommandResult.newOKCommandResult();
}

From source file:fr.xebia.workshop.continuousdelivery.InfrastructureTopologyScanner.java

public Collection<TeamInfrastructure> scan() {
    Filter filter = new Filter("tag:Workshop", newArrayList("continuous-delivery-workshop"));
    List<Reservation> reservations = ec2.describeInstances(new DescribeInstancesRequest().withFilters(filter))
            .getReservations();//from   w  w  w  .ja v a  2  s .  co m

    Iterable<Instance> instances = AmazonAwsUtils.toEc2Instances(reservations);

    Iterable<Instance> runningInstances = Iterables.filter(instances,
            AmazonAwsUtils.PREDICATE_RUNNING_OR_PENDING_INSTANCE);
    runningInstances = AmazonAwsUtils.awaitForEc2Instances(runningInstances, ec2);

    Map<String, Instance> runningInstancesByInstanceId = Maps.uniqueIndex(runningInstances,
            AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID);

    List<String> runningInstanceIds = newArrayList(
            Iterables.transform(runningInstances, AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID));

    List<TagDescription> tags = ec2
            .describeTags(new DescribeTagsRequest().withFilters(new Filter("resource-id", runningInstanceIds)))
            .getTags();
    Map<String, Map<String, String>> tagsByInstanceId = new MapMaker()
            .makeComputingMap(new Function<String, Map<String, String>>() {
                @Override
                public Map<String, String> apply(String instanceId) {
                    return Maps.newHashMap();
                }
            });

    for (TagDescription tag : tags) {
        tagsByInstanceId.get(tag.getResourceId()).put(tag.getKey(), tag.getValue());
    }

    Map<String, TeamInfrastructure> teamInfrastructureByTeamIdentifier = new MapMaker()
            .makeComputingMap(new Function<String, TeamInfrastructure>() {
                @Override
                public TeamInfrastructure apply(String teamIdentifier) {
                    return new TeamInfrastructure(workshopInfrastructure, teamIdentifier);
                }
            });

    Instance nexusServer = null;

    for (Map.Entry<String, Map<String, String>> entry : tagsByInstanceId.entrySet()) {
        Map<String, String> instanceTags = entry.getValue();
        String instanceId = entry.getKey();
        Instance instance = runningInstancesByInstanceId.get(instanceId);
        String teamIdentifier = instanceTags.get("TeamIdentifier");

        if (teamIdentifier == null) {
            if (TeamInfrastructure.ROLE_NEXUS.equals(instanceTags.get("Role"))) {
                nexusServer = instance;
            } else {
                // not a per team server (e.g. Nexus server)
            }
        } else {

            TeamInfrastructure teamInfrastructure = teamInfrastructureByTeamIdentifier.get(teamIdentifier);
            teamInfrastructure.addInstance(instance, instanceTags);
        }
    }
    Collection<TeamInfrastructure> teamInfrastructures = teamInfrastructureByTeamIdentifier.values();
    for (TeamInfrastructure teamInfrastructure : teamInfrastructures) {
        teamInfrastructure.setNexus(nexusServer);
    }
    return teamInfrastructures;
}

From source file:org.polymap.core.project.ui.util.SelectionAdapter.java

public <T> Iterable<T> elementsOfType(Class<T> type) {
    return Iterables.filter(this, type);
}