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.eclipse.sirius.diagram.business.internal.migration.NoteAttachmentWithoutSourceOrTargetMigrationParticipant.java

@Override
protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) {
    if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) {
        for (DView dView : dAnalysis.getOwnedViews()) {
            for (DDiagram dDiagram : Iterables.filter(new DViewQuery(dView).getLoadedRepresentations(),
                    DDiagram.class)) {
                DiagramCreationUtil diagramCreationUtil = new DiagramCreationUtil(dDiagram);
                if (diagramCreationUtil.findAssociatedGMFDiagram()) {
                    Diagram gmfDiagram = diagramCreationUtil.getAssociatedGMFDiagram();
                    deleteNoteAttachmentWithoutSourceOrTarget(gmfDiagram);
                }// www . j  a v  a 2s  .c o m
            }
        }
        super.postLoad(dAnalysis, loadedVersion);
    }
}

From source file:org.eclipse.xtext.ui.editor.StatefulResourceDescription.java

protected ImmutableList<IEObjectDescription> copyExportedObjects(IResourceDescription original) {
    return ImmutableList.copyOf(Iterables.filter(Iterables.transform(original.getExportedObjects(),
            new Function<IEObjectDescription, IEObjectDescription>() {
                @Override/*from   w  w  w .j av a  2s .  c  o m*/
                public IEObjectDescription apply(IEObjectDescription from) {
                    if (from == null)
                        return null;
                    EObject proxy = from.getEObjectOrProxy();
                    if (proxy == null)
                        return null;
                    if (proxy.eIsProxy())
                        return from;
                    InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
                    result.eSetProxyURI(EcoreUtil.getURI(from.getEObjectOrProxy()));
                    Map<String, String> userData = null;
                    for (String key : from.getUserDataKeys()) {
                        if (userData == null) {
                            userData = Maps.newHashMapWithExpectedSize(2);
                        }
                        userData.put(key, from.getUserData(key));
                    }
                    return EObjectDescription.create(from.getName(), result, userData);
                }
            }), Predicates.notNull()));
}

From source file:brooklyn.entity.trait.StartableMethods.java

private static <T extends Entity> Iterable<T> filterStartableManagedEntities(Iterable<T> contenders) {
    return Iterables.filter(contenders,
            Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.isManaged()));
}

From source file:org.apache.brooklyn.util.core.xstream.ImmutableSetConverter.java

public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Collection<?> collection = Lists.newArrayList();
    populateCollection(reader, context, collection);
    return ImmutableSet.copyOf(Iterables.filter(collection, Predicates.notNull()));
}

From source file:org.eclipse.sirius.ui.debug.ShowEditPartsHierarchy.java

private void showEditParts(EditPart part, int level, StringBuilder out) {
    addLevel(level, out);//ww w.java 2  s.c om
    addEditPart(part, level, out);
    out.append("\n");
    for (EditPart child : Iterables.filter(part.getChildren(), EditPart.class)) {
        showEditParts(child, level + 1, out);
    }
}

From source file:com.ge.research.sadl.scoping.SadlLocalScopeProvider.java

@Override
protected IScope getGlobalScope(Resource context, EReference reference) {
    IScope globalScope = super.getGlobalScope(context, reference);

    // Create a filtered view on all ResourceNames from the global scope that have a 2 segment qualified name (namespace:name)
    Iterable<IEObjectDescription> resourceNameDescriptions = Iterables.filter(globalScope.getAllElements(),
            new Predicate<IEObjectDescription>() {
                @Override/*  w w w . j  ava2  s. c  o m*/
                public boolean apply(IEObjectDescription input) {
                    return input.getEClass() == SadlPackage.Literals.RESOURCE_NAME
                            && input.getQualifiedName().getSegmentCount() == 2;
                }
            });
    // Map these object descriptions to their simple name
    Iterable<IEObjectDescription> aliasedResourceNameDescriptions = Iterables
            .transform(resourceNameDescriptions, new Function<IEObjectDescription, IEObjectDescription>() {
                @Override
                public IEObjectDescription apply(IEObjectDescription input) {
                    return new AliasedEObjectDescription(
                            QualifiedName.create(input.getQualifiedName().getLastSegment()), input);
                }
            });

    return new SimpleScope(globalScope, aliasedResourceNameDescriptions);
}

From source file:kn.uni.gis.dataimport.FormatStrangeFlickrFormat.java

License:asdf

private static Iterable<String> filterNulls(Iterable<String> concatLines) {
    return Iterables.filter(concatLines, new Predicate<String>() {

        @Override/* w ww . ja v  a  2 s .  c  om*/
        public boolean apply(String input) {
            return !!!input.startsWith("0");
        }

    });
}

From source file:org.apache.brooklyn.util.core.xstream.ImmutableListConverter.java

public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Collection<?> collection = Lists.newArrayList();
    populateCollection(reader, context, collection);
    return ImmutableList.copyOf(Iterables.filter(collection, Predicates.notNull()));
}

From source file:org.jclouds.azureblob.blobstore.functions.ResourceToListBlobsResponse.java

public ListBlobsResponse apply(PageSet<? extends StorageMetadata> list) {

    Iterable<BlobProperties> contents = Iterables
            .transform(Iterables.filter(list, new Predicate<StorageMetadata>() {

                public boolean apply(StorageMetadata input) {
                    return input.getType() == StorageType.BLOB;
                }/*from w w  w.  j av a  2 s  . c  om*/

            }), new Function<StorageMetadata, BlobProperties>() {

                public MutableBlobProperties apply(StorageMetadata from) {
                    return blob2ObjectMd.apply((BlobMetadata) from);
                }

            });

    SortedSet<String> commonPrefixes = Sets
            .newTreeSet(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 HashSetListBlobsResponse(contents, null, null, null, null, list.getNextMarker(), "/",
            commonPrefixes);
}

From source file:com.netflix.exhibitor.core.config.filesystem.FileSystemPseudoLock.java

@Override
protected List<String> getFileNames(String lockPrefix) throws Exception {
    File[] files = directory.listFiles();
    if (files != null) {
        Iterable<File> filtered = Iterables.filter(Arrays.asList(files), new Predicate<File>() {
            @Override/*  w  ww  .  ja  va  2  s. co m*/
            public boolean apply(File f) {
                return f.getName().startsWith(getLockPrefix());
            }
        });

        Iterable<String> transformed = Iterables.transform(filtered, new Function<File, String>() {
            @Override
            public String apply(File f) {
                return f.getName();
            }
        });

        return Lists.newArrayList(transformed);
    }
    return Lists.newArrayList();
}