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:org.eclipse.sirius.ext.emf.EClassQuery.java
/** * Returns all the containment features of the queried {@link EClass}. * /*w w w.j a v a 2 s.c o m*/ * @return all the containment features of the {@link EClass}. */ public Collection<EStructuralFeature> getAllContainmentFeatures() { return ImmutableList .copyOf(Iterables.filter(eClass.getEAllStructuralFeatures(), new IsContaintmentFeature())); }
From source file:pharmacy.Add.java
private void test() { for (int i = 0; i < 10; i++) { testList.add("Test" + (i + 1)); }/*from w w w . ja v a2 s . c om*/ String s = Joiner.on(", ").join(testList); List<Medicine> medicines = Lists.newArrayList(); for (int i = 0; i < 10; i++) { Medicine m = new Medicine(); m.setIllnessCode(i); m.setName("Medicine " + (i + 1)); m.setPrice(100); medicines.add(m); } Iterable<Medicine> onlyMod2 = Iterables.filter(medicines, new Predicate<Medicine>() { @Override public boolean apply(Medicine t) { return t.getIllnessCode() % 2 == 0; } }); List<Medicine> filtered = ImmutableList.copyOf(onlyMod2); Iterable<String> names = Iterables.transform(medicines, new Function<Medicine, String>() { @Override public String apply(Medicine f) { return f.getName(); } }); String namesStr = Joiner.on(", ").join(names); }
From source file:org.apache.aurora.scheduler.AcceptedOffer.java
public static AcceptedOffer create(Offer offer, ResourceSlot taskSlot, ResourceSlot executorSlot, Set<Integer> selectedPorts, TierInfo tierInfo) throws Resources.InsufficientResourcesException { List<Resource> reservedFirst = ImmutableList.<Resource>builder() .addAll(Iterables.filter(offer.getResourcesList(), RESERVED)) .addAll(Iterables.filter(offer.getResourcesList(), NOT_RESERVED)).build(); boolean revocable = tierInfo.isRevocable(); List<Resource.Builder> cpuResources = filterToBuilders(reservedFirst, ResourceType.CPUS.getName(), revocable ? Resources.REVOCABLE : Resources.NON_REVOCABLE); List<Resource.Builder> memResources = filterToBuilderNonRevocable(reservedFirst, ResourceType.RAM_MB.getName()); List<Resource.Builder> diskResources = filterToBuilderNonRevocable(reservedFirst, ResourceType.DISK_MB.getName()); List<Resource.Builder> portsResources = filterToBuilderNonRevocable(reservedFirst, ResourceType.PORTS.getName()); List<Resource> taskResources = ImmutableList.<Resource>builder() .addAll(allocateScalarType(cpuResources, taskSlot.getNumCpus(), revocable)) .addAll(allocateScalarType(memResources, taskSlot.getRam().as(Data.MB), false)) .addAll(allocateScalarType(diskResources, taskSlot.getDisk().as(Data.MB), false)) .addAll(allocateRangeType(portsResources, selectedPorts)).build(); List<Resource> executorResources = ImmutableList.<Resource>builder() .addAll(allocateScalarType(cpuResources, executorSlot.getNumCpus(), revocable)) .addAll(allocateScalarType(memResources, executorSlot.getRam().as(Data.MB), false)) .addAll(allocateScalarType(diskResources, executorSlot.getDisk().as(Data.MB), false)).build(); return new AcceptedOffer(taskResources, executorResources); }
From source file:org.caleydo.view.tourguide.internal.compute.AComputeJob.java
public AComputeJob(Collection<IScore> scores, Object receiver) { super("Compute LineUp Scores"); Set<IScore> flatten = Scores.flatten(scores); stratScores = Lists.newArrayList(Iterables.filter(flatten, IComputedStratificationScore.class)); groupScores = Lists.newArrayList(Iterables.filter(flatten, IComputedGroupScore.class)); this.receiver = receiver; }
From source file:com.marintek.tpm.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:org.jclouds.s3.blobstore.functions.ResourceToBucketList.java
public ListBucketResponse apply(PageSet<? extends StorageMetadata> list) { Iterable<ObjectMetadata> contents = Iterables .transform(Iterables.filter(list, new Predicate<StorageMetadata>() { public boolean apply(StorageMetadata input) { return input.getType() == StorageType.BLOB; }// w w w . j a v a2s. c o m }), new Function<StorageMetadata, ObjectMetadata>() { public MutableObjectMetadata apply(StorageMetadata from) { return blob2ObjectMd.apply((BlobMetadata) from); } }); Set<String> commonPrefixes = Sets .newLinkedHashSet(Iterables.transform(Iterables.filter(list, new Predicate<StorageMetadata>() { public boolean apply(StorageMetadata input) { return input.getType() == StorageType.RELATIVE_PATH; } }), new Function<StorageMetadata, String>() { public String apply(StorageMetadata from) { return from.getName(); } })); return new ListBucketResponseImpl(null, contents, null, null, list.getNextMarker(), 0, "/", list.getNextMarker() != null, commonPrefixes); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.repair.DEdgeDiagramElementState.java
/** * {@inheritDoc}/*from w ww .ja v a 2 s .c om*/ */ @Override public void storeElementState(EObject target, DiagramElementMapping mapping, DEdge element) { super.storeElementState(target, mapping, element); Iterable<ArrangeConstraint> existingArrangeConstraints = Iterables.filter(element.getArrangeConstraints(), ArrangeConstraint.class); if (!Iterables.isEmpty(existingArrangeConstraints)) { Iterables.addAll(arrangeConstraints, existingArrangeConstraints); } }
From source file:com.google.api.codegen.ServiceMessages.java
/** Inputs a list of methods and returns only those which are page streaming. */ public Iterable<Method> filterPageStreamingMethods(final InterfaceConfig config, List<Method> methods) { Predicate<Method> isPageStreaming = new Predicate<Method>() { @Override//from www . ja va2s .c om public boolean apply(Method method) { return config.getMethodConfig(method).isPageStreaming(); } }; return Iterables.filter(methods, isPageStreaming); }
From source file:org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy.java
@Override public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) { return Iterables.filter(Iterables.transform(client.listSlices(), sliceToNodeMetadata), filter); }
From source file:org.trancecode.xml.saxon.SaxonAxis.java
public static Iterable<XdmNode> childNodesNoAttributes(final XdmNode node) { return Iterables.filter(childNodes(node), Predicates.not(SaxonPredicates.isAttribute())); }