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:brooklyn.location.affinity.EntityTypeAffinityRule.java

@Override
public boolean apply(@Nullable Location input) {
    Collection<Entity> all = getManagementContext().getEntityManager().getEntities();
    return Iterables.any(Iterables.filter(all, entityType), EntityPredicates.withLocation(input));
}

From source file:de.cosmocode.collections.AbstractUniqueList.java

@Override
public boolean addAll(int index, Collection<? extends E> c) {
    boolean changed = false;
    int i = index;
    for (E element : Iterables.filter(c, notContains)) {
        add(i++, element);/* ww w  .  ja  v  a  2 s  .  c  om*/
        changed = true;
    }
    return changed;
}

From source file:msi.gama.lang.gaml.resource.GamlResourceDescription.java

@Override
public Iterable<QualifiedName> getImportedNames() {
    final Iterable<QualifiedName> result = super.getImportedNames();
    return Iterables.filter(result, new Predicate<QualifiedName>() {

        @Override//  w ww.j ava 2  s . c  o m
        public boolean apply(final QualifiedName input) {
            return !provider.contains(input);
        }
    });
}

From source file:org.caleydo.view.entourage.GLEntourageWindow.java

@Override
protected void renderPickImpl(GLGraphics g, float w, float h) {
    if (w <= 1 || h <= 1) { // just render the SlideInElements
        g.incZ();//ww  w  . jav a  2 s  .  c  o  m
        for (SlideInElement child : Iterables.filter(this, SlideInElement.class))
            child.renderPick(g);
        g.decZ();
    } else {
        // render normally
        super.renderPickImpl(g, w, h);
    }
}

From source file:com.medvision360.medrecord.spi.base.BaseValidationReport.java

@Override
public Iterable<ValidationResult> getErrors() {
    return Iterables.filter(getReport(), new Predicate<ValidationResult>() {
        @Override//from  w ww .j  av a2  s .  c om
        public boolean apply(ValidationResult input) {
            return !input.isValid();
        }
    });
}

From source file:org.eclipse.sirius.diagram.ui.tools.api.figure.FigureQuery.java

/**
 * Return the label figure of this figure. Search in all chidren the first
 * figure of kind {@link Label}, {@link WrapLabel} or
 * {@link SiriusWrapLabel}.//from   w  w w .j  av a 2s  . co  m
 * 
 * @return the first label figure or null if any
 */
public Option<IFigure> getLabelFigure() {
    Option<IFigure> result = Options.newNone();
    if (figure instanceof SiriusWrapLabel || figure instanceof WrapLabel || figure instanceof Label) {
        result = Options.newSome(figure);
    } else {
        for (IFigure childFigure : Iterables.filter(figure.getChildren(), IFigure.class)) {
            Option<IFigure> temp = new FigureQuery(childFigure).getLabelFigure();
            if (temp.some()) {
                result = temp;
                break;
            }
        }
    }
    return result;
}

From source file:com.isotrol.impe3.pms.core.support.EntityFunctions.java

/** Filter not deleted. */
public static <T extends PublishableEntity<?, ?, ?>> Iterable<T> notDeleted(Iterable<T> entities) {
    return Iterables.filter(entities, NOT_DELETED);
}

From source file:org.axdt.avm.scoping.AvmPropertyScope.java

@Override
protected Iterable<IEObjectDescription> getCandidates() {
    AvmTypeAccess access = getQualifierType();
    if (access == null)
        return Collections.emptySet();
    Iterable<IEObjectDescription> dynDesc = null;
    if (access instanceof AvmTypeAccess.Builder) {
        AvmPackage pack = ((AvmTypeAccess.Builder) access).getPackage();
        if (pack instanceof AvmContainerPackage) {
            return ((AvmContainerPackage) pack).getChildren();
        }/*w ww.  ja  v a 2  s. co  m*/
        return Iterables.transform(Iterables.filter(pack.eContents(), AvmReferable.class), GetDesciption);
    } else if (access != AvmTypeAccess.NULL) {
        AvmType type = access.getType();
        type = resolveType(type, null);
        if (type.isDynamic()) {
            AvmReferable dynIdent = getDynamicIdentifiable(getReference());
            if (dynIdent != null)
                dynDesc = Collections.singleton(GetDesciption.apply(dynIdent));
        }
        if (type instanceof AvmDeclaredType) {
            AvmDeclaredType typeDec = (AvmDeclaredType) type;
            Iterable<IEObjectDescription> members = Iterables.transform(getAllMembers(typeDec, access),
                    GetDesciption);
            if (dynDesc != null)
                members = Iterables.concat(members, dynDesc);
            return members;
        }
    }
    if (dynDesc != null)
        return dynDesc;
    return Collections.emptySet();
}

From source file:org.eclipse.xtext.graphview.lib.extensions.JvmModelExtensions.java

public static <T extends EObject> T sourceElement(EObject jvmElement, Class<T> type) {
    // guard for https://bugs.eclipse.org/bugs/show_bug.cgi?id=460956
    if (!(jvmElement.eResource() instanceof TypeResource)) {
        IJvmModelAssociations associations = getLanguageService(jvmElement, IJvmModelAssociations.class);
        if (associations != null) {
            Set<EObject> sourceElements = associations.getSourceElements(jvmElement);
            Iterator<T> matchingElements = Iterables.filter(sourceElements, type).iterator();
            if (matchingElements.hasNext())
                return matchingElements.next();
        }/* w w w  .j  a  v a  2 s  . c o m*/
    }
    return null;
}

From source file:org.obeonetwork.dsl.uml2.design.internal.services.DependencyServices.java

/**
 * To avoid duplicate case Port to interface and Class/Component to interface we provide this service that
 * return only the required client to ui needs.
 *
 * @param dependency/*w w  w  . j  a v a2  s .  c o m*/
 *            the dependency context
 * @return needed clients to handle is the diagram ui
 */
public List<NamedElement> getClient(Dependency dependency) {
    final List<NamedElement> result = new ArrayList<NamedElement>();
    final List<NamedElement> clients = Lists
            .newArrayList(Iterables.filter(dependency.getClients(), new Predicate<EObject>() {
                public boolean apply(EObject input) {
                    return !(input instanceof Connector);
                }
            }));
    if (clients.size() == 1) {
        result.addAll(clients);
        return result;
    }
    for (final NamedElement client : clients) {
        if (client instanceof Property) {
            final Property property = (Property) client;
            if (property instanceof Port) {
                final Port port = (Port) property;
                if (port.getType() != null) {
                    if (port.eContainer() instanceof StructuredClassifier
                            && port.getType().equals(port.eContainer())) {
                        // when the port type is the container type, add
                        // directly the container.
                        result.add(port.getType());
                    } else if (port.isConjugated()) {
                        // if conjugated add the port type and the port.
                        result.add(port);
                        result.add(port.getType());
                    } else {
                        // Else add the port
                        result.add(port);
                    }
                } else {
                    // Else add the port
                    result.add(port);
                }
            } else {
                // Else add the property
                result.add(property);
            }
        }
    }
    return result;
}