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:models.web.ModuleModel.java

public ModuleModel(Module module) {
    super(module);

    if (module != null) {
        this.id = UuidUtils.normalize(module.getId());
        this.baseName = module.getBaseDisplayName();
        this.name = module.getDisplayName();
        this.url = module.getRoute();
        this.canPartiallyRender = module.canPartiallyRender();
        this.allowSelfOutput = module.allowSelfOutput();
        this.relevancyScore = 1.0;

        if (module.getSubModules() != null) {
            this.subModules = Lists.transform(
                    Lists.newArrayList(Iterables.filter(module.getSubModules(), Predicates.notNull())),
                    new Function<Module, ModuleModel>() {
                        @Override
                        @Nullable/*from w ww .  j  a  v a  2s .c o m*/
                        public ModuleModel apply(@Nullable Module input) {
                            return new ModuleModel(input);
                        }
                    });
        }
    }
}

From source file:org.eclipse.sirius.diagram.tools.internal.validation.description.constraints.EdgeMappingCycleConstraint.java

@Override
public IStatus validate(IValidationContext ctx) {
    EObject eObj = ctx.getTarget();/* w  ww .  j av  a 2  s  . c o m*/
    EMFEventType eventType = ctx.getEventType();
    // In the case of batch mode.
    if (eventType == EMFEventType.NULL) {
        Resource eObjResource = eObj.eResource();
        if (eObjResource != null && eObjResource.getResourceSet() != null && eObj instanceof EdgeMapping) {
            EdgeMapping edgeMapping = (EdgeMapping) eObj;
            boolean findCycle = hasCycle(edgeMapping, Sets.<EdgeMapping>newLinkedHashSet(),
                    Sets.<EdgeMapping>newLinkedHashSet(Iterables.concat(
                            Iterables.filter(edgeMapping.getSourceMapping(), EdgeMapping.class),
                            Iterables.filter(edgeMapping.getTargetMapping(), EdgeMapping.class))));
            if (findCycle) {
                return ctx.createFailureStatus(new Object[] { edgeMapping, edgeMapping.getName() });
            }
        }
    }
    return ctx.createSuccessStatus();
}

From source file:org.jclouds.hpcloud.compute.HPCloudComputeServiceAdapter.java

@Override
public Iterable<ImageInZone> listImages() {
    return Iterables.filter(super.listImages(), new Predicate<ImageInZone>() {

        @Override/*  w  w  w .j a v a  2s  .c o  m*/
        public boolean apply(ImageInZone arg0) {
            String imageName = arg0.getImage().getName();
            return imageName.indexOf("Kernel") == -1 && imageName.indexOf("Ramdisk") == -1;
        }

        @Override
        public String toString() {
            return "notKernelOrRamdisk";
        }
    });
}

From source file:com.facebook.presto.sql.analyzer.TupleDescriptor.java

public TupleDescriptor(List<Field> fields) {
    checkNotNull(fields, "fields is null");
    this.allFields = ImmutableList.copyOf(fields);
    this.visibleFields = ImmutableList.copyOf(Iterables.filter(fields, not(Field::isHidden)));

    int index = 0;
    ImmutableMap.Builder<Field, Integer> builder = ImmutableMap.builder();
    for (Field field : fields) {
        builder.put(field, index++);//from   w w  w.j  a  v a 2 s .c  o  m
    }
    fieldIndexes = builder.build();
}

From source file:brooklyn.location.docker.strategy.GroupPlacementStrategy.java

@Override
public boolean apply(DockerHostLocation input) {
    boolean requireExclusive = config().get(REQUIRE_EXCLUSIVE);
    String dockerApplicationId = input.getOwner().getApplicationId();
    Iterable<Entity> deployed = Iterables.filter(input.getDockerContainerList(),
            Predicates.not(EntityPredicates.applicationIdEqualTo(dockerApplicationId)));
    Entity parent = entity.getParent();
    String applicationId = entity.getApplicationId();
    Iterable<Entity> sameApplication = Iterables.filter(deployed,
            EntityPredicates.applicationIdEqualTo(applicationId));
    if (requireExclusive && Iterables.size(deployed) > Iterables.size(sameApplication)) {
        LOG.debug("Found entities not in {}; required exclusive. Reject: {}", applicationId, input);
        return false;
    }//  w  w w.  j a v  a2s  .  c o  m
    if (Iterables.isEmpty(sameApplication)) {
        LOG.debug("No entities present from {}. Accept: {}", applicationId, input);
        return true;
    } else {
        Iterable<Entity> sameParent = Iterables.filter(sameApplication, EntityPredicates.isChildOf(parent));
        if (Iterables.isEmpty(sameParent)) {
            LOG.debug("All entities from {} have different parent. Reject: {}", applicationId, input);
            return false;
        } else {
            LOG.debug("All entities from {} have same parent. Accept: {}", applicationId, input);
            return true;
        }
    }
}

From source file:com.ning.metrics.collector.processing.feed.FeedRollUpProcessor.java

public Feed applyRollUp(final Feed feed, final Map<String, Object> filterMap) {
    final List<FeedEvent> compiledFeedEventList = Lists.newArrayList();

    // filter out all events which do not match "any" of the provided key value pair
    List<FeedEvent> feedEventList = (filterMap == null || filterMap.isEmpty())
            ? Lists.newArrayList(feed.getFeedEvents())
            : Lists.newArrayList(//  w w  w  .  j  a  v  a  2s  . c o m
                    Iterables.filter(feed.getFeedEvents(), FeedEvent.isAnyKeyValuMatching(filterMap)));

    if (feedEventList.isEmpty()) {
        return new Feed(compiledFeedEventList);
    }

    ArrayListMultimap<String, FeedEvent> rolledEventMultiMap = ArrayListMultimap.create();
    Iterator<FeedEvent> iterator = feedEventList.iterator();
    Set<String> removalTargetSet = new HashSet<String>();

    while (iterator.hasNext()) {
        FeedEvent feedEvent = iterator.next();

        // Do not include suppress types of events
        if (Objects.equal(FeedEventData.EVENT_TYPE_SUPPRESS, feedEvent.getEvent().getEventType())) {
            List<String> removalTargets = feedEvent.getEvent().getRemovalTargets();

            // add non-null entries to set of removal targets
            if (removalTargets != null) {
                for (String removalTarget : removalTargets) {
                    if (!Strings.isNullOrEmpty(removalTarget)) {
                        removalTargetSet.add(removalTarget);
                    }
                }
            }

            continue;
        }

        // If any of the removal targets are matching then the specific event is to be suppressed
        if (containsAnyRemovalTargets(removalTargetSet, feedEvent.getEvent().getRemovalTargets())) {
            continue;
        }

        if (feedEvent.getEvent() != null && !Strings.isNullOrEmpty(feedEvent.getEvent().getRollupKey())) {

            String rollupKey = feedEvent.getEvent().getRollupKey();
            List<FeedEvent> rolledUpEventList = rolledEventMultiMap.get(rollupKey);
            FeedEvent compareFeedEvent = null;

            // a null rolled event build indicates a new rollup key
            if (rolledUpEventList.isEmpty()) {
                RolledUpFeedEvent rolledEvent = RolledUpFeedEvent.createForAssembly(rollupKey,
                        rolledUpEventList);
                compiledFeedEventList.add(rolledEvent);
            } else {
                compareFeedEvent = rolledUpEventList.get(0);
            }

            // If there is an event to compare this one to, only roll up
            // this event if it is within 24 hours from the most recent
            // and if
            if (compareFeedEvent == null || feedEvent.getEvent().getCreatedDate().plusHours(24)
                    .isAfter(compareFeedEvent.getEvent().getCreatedDate())) {
                // event been iterated upon is a candidate for roll up
                rolledUpEventList.add(feedEvent);
            }

            // otherwise ignore the old, would-be-rolled event
            continue;
        }

        // An event that makes it through to the bottom of the while loop
        // should be added to the compiled list of events
        compiledFeedEventList.add(feedEvent);
    }

    // return a new unprocessed feed using the given list of feed events
    return new Feed(compiledFeedEventList, true);
}

From source file:com.metamx.druid.index.v1.RowboatFilteringIndexAdapter.java

@Override
public Iterable<Rowboat> getRows() {
    return Iterables.filter(baseAdapter.getRows(), filter);
}

From source file:org.zeroturnaround.jenkins.reporter.model.JenkinsView.java

public Collection<Job> getPassedJobs() {
    return Lists.newArrayList(Iterables.filter(getJobs(), new GoodJobPredicate()));
}

From source file:org.yakindu.base.expressions.scoping.AbstractLibraryGlobalScopeProvider.java

protected Iterable<URI> getValidLibraries(Resource context) {
    return Iterables.filter(getLibraries(context), new Predicate<URI>() {
        @Override//from w  w w. ja v  a  2s.  c om
        public boolean apply(URI input) {
            return URIConverter.INSTANCE.exists(input, Collections.EMPTY_MAP);
        }
    });
}

From source file:edu.umd.cs.psl.evaluation.statistics.SimpleResultComparison.java

@Override
public Iterable<Entry<Atom, Double>> getFalseNegatives() {
    return Iterables.filter(errors.entrySet(), new Predicate<Entry<Atom, Double>>() {

        @Override//from   w  w  w.ja  va 2 s  .c  o  m
        public boolean apply(Entry<Atom, Double> e) {
            if (e.getValue() < 0.0)
                return true;
            else
                return false;
        }
    });
}