List of usage examples for com.google.common.collect Iterables filter
@GwtIncompatible("Class.isInstance") @CheckReturnValue public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType)
From source file:net.freifunk.autodeploy.firmware.FirmwareServiceImpl.java
@Override public Firmware findSupportedFirmware(final String firmwareString) { final Iterable<Firmware> matches = Iterables.filter(_configurators.keySet(), new Predicate<Firmware>() { @Override/*from w ww. j a v a 2 s . c o m*/ public boolean apply(final Firmware firmware) { return firmware != null && firmware.getName().equals(firmwareString); } }); if (Iterables.size(matches) > 1) { throw new IllegalStateException("More than one firmware found: " + firmwareString); } return Iterables.getFirst(matches, null); }
From source file:uk.org.ukfederation.mda.validate.AbstractValidationStage.java
/** * Set the list of validators to apply to each item. * /*from www. ja v a 2s.c o m*/ * @param newValidators the list of validators to set */ public void setValidators(@Nonnull final List<Validator<T>> newValidators) { ComponentSupport.ifDestroyedThrowDestroyedComponentException(this); ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); validators = ImmutableList.copyOf(Iterables.filter(newValidators, Predicates.notNull())); }
From source file:org.eclipse.etrice.core.scoping.FilteringScope.java
protected Iterable<IEObjectDescription> filter(Iterable<IEObjectDescription> unfiltered) { return Iterables.filter(unfiltered, filter); }
From source file:com.axemblr.provisionr.core.activities.KillMachineSetUpProcesses.java
@Override public void execute(DelegateExecution execution) throws Exception { @SuppressWarnings("unchecked") List<String> processIds = (List<String>) execution.getVariable(variableWithProcessIds); List<String> forceEnded = Lists.newArrayList(Iterables.filter(processIds, new Predicate<String>() { @Override//from w w w . j av a 2 s . co m public boolean apply(String processInstanceId) { ProcessInstance instance = runtimeService.createProcessInstanceQuery() .processInstanceId(processInstanceId).singleResult(); if (instance != null && !instance.isEnded()) { runtimeService.deleteProcessInstance(processInstanceId, "Pending process needs to be killed"); return true; } return false; } })); LOG.info("Killed pending machine setup processes: {}", forceEnded); }
From source file:org.apache.beam.runners.dataflow.worker.graph.RemoveFlattenInstructionsFunction.java
@Override public MutableNetwork<Node, Edge> apply(MutableNetwork<Node, Edge> network) { for (Node node : ImmutableList.copyOf(Iterables.filter(network.nodes(), IsFlatten.INSTANCE))) { // For each successor instruction after the Flatten, connect it directly to the // predecessor PCollections of Flatten. Node flattenPCollection = Iterables.getOnlyElement(network.successors(node)); for (Node successorInstruction : ImmutableList.copyOf(network.successors(flattenPCollection))) { for (Edge edge : ImmutableList .copyOf(network.edgesConnecting(flattenPCollection, successorInstruction))) { for (Node predecessorPCollection : ImmutableList.copyOf(network.predecessors(node))) { network.addEdge(predecessorPCollection, successorInstruction, edge.clone()); }/*w ww .j a va 2s.com*/ } } // Remove the Flatten instruction and its output PCollection. network.removeNode(flattenPCollection); network.removeNode(node); } return network; }
From source file:fr.xebia.workshop.monitoring.InfrastructureTopologyScanner.java
public Collection<TeamInfrastructure> scan() { Filter filter = new Filter("tag:Workshop", newArrayList("monitoring")); List<Reservation> reservations = ec2.describeInstances(new DescribeInstancesRequest().withFilters(filter)) .getReservations();// w w w. ja v a2 s.c o 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) { // not a per team server (e.g. Nexus server) } else { TeamInfrastructure teamInfrastructure = teamInfrastructureByTeamIdentifier.get(teamIdentifier); teamInfrastructure.addInstance(instance, instanceTags); } } Collection<TeamInfrastructure> teamInfrastructures = teamInfrastructureByTeamIdentifier.values(); return teamInfrastructures; }
From source file:com.pingcap.tikv.util.TiFluentIterable.java
public final TiFluentIterable<E> filter(Predicate<? super E> predicate) { return from(Iterables.filter(iter, predicate)); }
From source file:org.eclipse.papyrus.uml.diagram.common.palette.customaction.utils.ConditionalElementListDialog.java
public ConditionalElementListDialog(Shell parent, Predicate<T> condition, Collection<T> elements) { super(parent, new AdapterFactoryLabelProvider( new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE))); setMultipleSelection(false);/*from w w w.j a va2 s. c o m*/ List<T> result = Lists.newArrayList(Iterables.filter(elements, condition)); setTitle("Choose Elements"); setElements(result.toArray()); }
From source file:org.jclouds.ec2.options.internal.BaseEC2RequestOptions.java
protected Set<String> getFormValuesWithKeysPrefixedBy(final String prefix) { Builder<String> values = ImmutableSet.builder(); for (String key : Iterables.filter(formParameters.keySet(), Predicates2.startsWith(prefix))) { values.add(Iterables.get(formParameters.get(key), 0)); }// ww w. ja v a2 s. c o m return values.build(); }
From source file:com.j2swift.ast.TreeUtil.java
public static Iterable<Annotation> getRuntimeAnnotations(Iterable<Annotation> annotations) { return Iterables.filter(annotations, IS_RUNTIME_PREDICATE); }