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:pt.ist.fenixedu.integration.domain.accounting.events.export.SIBSOutgoingPaymentQueueJob.java

public static List<SIBSOutgoingPaymentQueueJob> readAllSIBSOutgoingPaymentQueueJobs() {
    return Lists.newArrayList(
            Iterables.filter(Bennu.getInstance().getJobsSet(), SIBSOutgoingPaymentQueueJob.class));
}

From source file:eu.numberfour.n4js.validation.validators.utils.MemberRedefinitionUtils.java

/**
 * Filters the given overridden members to only contain members which are metatype compatible with the overriding
 * member.//from   ww  w. j  av  a 2 s.co  m
 */
public static Iterable<TMember> getMetatypeCompatibleOverriddenMembers(TMember overridingMember,
        Iterable<TMember> overriddenMembers) {
    return Iterables.filter(overriddenMembers, member -> isMetaTypeCompatible(overridingMember, member));
}

From source file:de.cosmocode.commons.reflect.GetAllInterfaces.java

@Override
public Iterable<Class<?>> apply(@Nullable Class<?> from) {
    return Iterables.filter(Reflection.getAllSuperTypes(from), Reflection.isInterface());
}

From source file:org.apache.aurora.scheduler.filter.ConstraintMatcher.java

/**
 * Gets the veto (if any) for a scheduling constraint based on the {@link AttributeAggregate} this
 * filter was created with.// w w w  .  j ava2 s .  c o m
 *
 * @param constraint Scheduling filter to check.
 * @return A veto if the constraint is not satisfied based on the existing state of the job.
 */
static Optional<Veto> getVeto(AttributeAggregate cachedjobState, Iterable<IAttribute> hostAttributes,
        IConstraint constraint) {

    Iterable<IAttribute> sameNameAttributes = Iterables.filter(hostAttributes,
            new NameFilter(constraint.getName()));
    Optional<IAttribute> attribute;
    if (Iterables.isEmpty(sameNameAttributes)) {
        attribute = Optional.absent();
    } else {
        Set<String> attributeValues = ImmutableSet
                .copyOf(Iterables.concat(Iterables.transform(sameNameAttributes, GET_VALUES)));
        attribute = Optional.of(IAttribute.build(new Attribute(constraint.getName(), attributeValues)));
    }

    ITaskConstraint taskConstraint = constraint.getConstraint();
    switch (taskConstraint.getSetField()) {
    case VALUE:
        boolean matches = AttributeFilter.matches(attribute.transform(GET_VALUES).or(ImmutableSet.of()),
                taskConstraint.getValue());
        return matches ? Optional.absent() : Optional.of(Veto.constraintMismatch(constraint.getName()));

    case LIMIT:
        if (!attribute.isPresent()) {
            return Optional.of(Veto.constraintMismatch(constraint.getName()));
        }

        boolean satisfied = AttributeFilter.matches(attribute.get(), taskConstraint.getLimit().getLimit(),
                cachedjobState);
        return satisfied ? Optional.absent() : Optional.of(Veto.unsatisfiedLimit(constraint.getName()));

    default:
        throw new SchedulerException(
                "Failed to recognize the constraint type: " + taskConstraint.getSetField());
    }
}

From source file:org.polarsys.reqcycle.export.transform.ScopeReqProvider.java

@Override
public Iterable<Requirement> getRequirements() {
    return Iterables.filter(scope.getRequirements(), Requirement.class);
}

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

public static <T extends JvmIdentifiableElement> T jvmElement(EObject sourceElement, Class<T> type) {
    IJvmModelAssociations associations = getLanguageService(sourceElement, IJvmModelAssociations.class);
    if (associations != null) {
        Set<EObject> jvmElements = associations.getJvmElements(sourceElement);
        Iterator<T> matchingElements = Iterables.filter(jvmElements, type).iterator();
        if (matchingElements.hasNext())
            return matchingElements.next();
    }//from   ww w  .ja v  a 2 s .  co  m
    return null;
}

From source file:org.isisaddons.module.fakedata.dom.IsisBlobs.java

private static List<String> fileNamesEndingWith(final String suffix) {
    return Lists.newArrayList(Iterables.filter(IsisBlobs.fileNames, endsWith(suffix)));
}

From source file:org.apache.hadoop.hive.metastore.datasource.DataSourceProvider.java

/**
 * @param hdpConfig// www  .jav a  2s.co m
 * @return subset of properties prefixed by a connection pool specific substring
 */
static Properties getPrefixedProperties(Configuration hdpConfig, String factoryPrefix) {
    Properties dataSourceProps = new Properties();
    Iterables.filter(hdpConfig, (entry -> entry.getKey() != null && entry.getKey().startsWith(factoryPrefix)))
            .forEach(entry -> dataSourceProps.put(entry.getKey(), entry.getValue()));
    return dataSourceProps;
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.part.DDiagramHelper.java

/**
 * Find the parent diagram.// www. j  ava2  s .co m
 * 
 * @param element
 *            Edit part.
 * @return The parent diagram or <code>null</code> if not found.
 */
public static IDDiagramEditPart findParentDiagram(final EditPart element) {
    IDDiagramEditPart result = null;
    if (element instanceof IDDiagramEditPart) {
        result = (IDDiagramEditPart) element;
    } else if (element instanceof DDiagramRootEditPart) {
        Iterable<IDDiagramEditPart> ddiagramChildren = Iterables.filter(element.getChildren(),
                IDDiagramEditPart.class);
        if (!Iterables.isEmpty(ddiagramChildren)) {
            result = ddiagramChildren.iterator().next();
        }
    } else if (element != null) {
        result = DDiagramHelper.findParentDiagram(element.getParent());
    }
    return result;
}

From source file:org.apache.hadoop.metrics2.impl.MetricsRecords.java

private static AbstractMetric getFirstMetricByName(MetricsRecord record, String name) {
    return Iterables.getFirst(Iterables.filter(record.metrics(), new AbstractMetricPredicate(name)), null);
}