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.tools.internal.validation.description.constraints.QualifiedTypeNameConstraint.java

/**
 * {@inheritDoc}//from w  w w. ja  va  2s . c  o  m
 * 
 */
@Override
public IStatus validate(final IValidationContext ctx) {
    final EObject eObj = ctx.getTarget();
    final EMFEventType eventType = ctx.getEventType();
    // In the case of batch mode.
    if (eventType == EMFEventType.NULL && eObj != null) {
        for (EAttribute feat : Iterables.filter(eObj.eClass().getEAllStructuralFeatures(), EAttribute.class)) {
            if (DescriptionPackage.Literals.TYPE_NAME == feat.getEType()) {
                final Object value = eObj.eGet(feat);
                if (value instanceof String) {
                    final TypeName className = TypeName.fromString((String) value);
                    if (!className.getPackagePrefix().some()) { // $NON-NLS-1$
                        return ctx.createFailureStatus(new Object[] { value, feat.getName() });
                    }
                }
            }

        }
    }
    return ctx.createSuccessStatus();
}

From source file:org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter.java

public IOutlineNode[] filterAndSort(Iterable<IOutlineNode> nodes) {
    final Iterable<IFilter> enabledFilters = getEnabledFilters();
    Iterable<IOutlineNode> filteredNodes = null;
    if (Iterables.isEmpty(enabledFilters)) {
        filteredNodes = nodes;//from w w  w .  ja v a  2s. c  o  m
    } else {
        filteredNodes = Iterables.filter(nodes, new Predicate<IOutlineNode>() {
            @Override
            public boolean apply(final IOutlineNode node) {
                return Iterables.all(enabledFilters, new Predicate<IFilter>() {
                    @Override
                    public boolean apply(IFilter filter) {
                        return filter.apply(node);
                    }
                });
            }
        });
    }
    IOutlineNode[] nodesAsArray = Iterables.toArray(filteredNodes, IOutlineNode.class);
    if (comparator != null && isSortingEnabled())
        Arrays.sort(nodesAsArray, comparator);
    return nodesAsArray;
}

From source file:ch.fancytools.ballbotsche.push.AsyncPushBean.java

public void observe(@Observes EnoughPlayerEvent event) {
    for (final Push2Mobile pusher : pushers) {
        executePushersAsync(pusher,//from w w  w .j  a va 2  s.  c o m
                Lists.newArrayList(Iterables.filter(event.getGame().getPlayerList(), new Predicate<Player>() {
                    @Override
                    public boolean apply(Player player) {
                        return pusher.acceptPushNotficationForType(player.getDevice());
                    }
                })));
    }
}

From source file:org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404.java

public Boolean apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return false;
    } else {/*from  ww  w .jav a2 s.  c  o  m*/
        return !rto404.apply(from);
    }
}

From source file:org.obiba.opal.web.magma.ParticipantsResource.java

@GET
@Path("/count")
@NoAuthorization/*from   ww  w .j a v  a  2s.c  om*/
public Response getParticipantCount() {
    Set<Datasource> datasources = MagmaEngine.get().getDatasources();
    ImmutableSet.Builder<VariableEntity> participants = ImmutableSet.builder();
    for (Datasource ds : datasources) {
        for (ValueTable table : Iterables.filter(ds.getValueTables(),
                ParticipantEntityTypePredicate.INSTANCE)) {
            participants.addAll(table.getVariableEntities());
        }
    }
    return Response.ok(String.valueOf(participants.build().size())).build();
}

From source file:org.gradle.platform.base.internal.registry.ModelMapBasedRule.java

private static ImmutableList<ModelReference<?>> calculateInputs(final Class<?> baseType,
        final List<ModelReference<?>> references, List<ModelReference<?>> modelReferences) {
    Iterable<ModelReference<?>> filteredReferences = Iterables.filter(references,
            new Predicate<ModelReference<?>>() {
                @Override/*from  www .j a  v a 2 s .  c o m*/
                public boolean apply(ModelReference<?> element) {
                    return !element.getType().equals(ModelType.of(baseType));
                }
            });

    ImmutableList.Builder<ModelReference<?>> allInputs = ImmutableList.builder();
    allInputs.addAll(modelReferences);
    allInputs.addAll(filteredReferences);
    return allInputs.build();
}

From source file:cosmos.sql.call.ChildVisitor.java

public Iterable<?> visit(final Function<ChildVisitor, Iterable<?>> callbackFunction,
        final Predicate<ChildVisitor> childFilter) {
    Collection<ChildVisitor> equalities = children.values();
    return Iterables.concat(Iterables.transform(Iterables.filter(equalities, childFilter), callbackFunction));
}

From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java

/**
 * Return processors matching a supplied processor type matching {@link ProcessorDTO#getType()} against the supplied {@code type}
 *
 * @param processors a collection of processors
 * @param type       a type to match against
 * @return a list of processors that are of the supplied type
 *//* ww w  . j  a  v  a2s.co  m*/
public static List<ProcessorDTO> findProcessorsByType(Collection<ProcessorDTO> processors, String type) {
    Predicate<ProcessorDTO> byType = new ProcessorByTypePredicate(type);
    return Lists.newArrayList(Iterables.filter(processors, byType));
}

From source file:eu.numberfour.n4js.JSLibSingleTestConfigProvider.java

/**
 * Merges several blacklists into one, may be used in custom {@link JSLibSingleTestConfigProvider} implementation.
 *//*w w  w  . ja v a 2 s .  c o  m*/
protected static Set<String> readModifierFiles(String... blacklistFileNames) throws IOException {
    Set<String> blacklist = new HashSet<>();
    if (blacklistFileNames != null) {
        for (String blacklistFileName : blacklistFileNames) {
            Iterable<String> entries = Iterables.filter(getFileLines(blacklistFileName),
                    new Predicate<String>() {
                        @Override
                        public boolean apply(String s) {
                            return !s.startsWith(BLACKLIST_LINECOMMENT) && !s.trim().isEmpty();
                        }
                    });
            for (String entry : entries) {
                if (!blacklist.add(entry)) {
                    System.err.println("Duplicate blacklist entry: " + entry);
                }
            }
        }
    }
    return blacklist;
}

From source file:eu.interedition.collatex.simple.SimpleToken.java

public static String toString(Iterable<? extends Token> tokens) {
    final StringBuilder normalized = new StringBuilder();
    for (SimpleToken token : Iterables.filter(tokens, SimpleToken.class)) {
        normalized.append(token.getNormalized()).append(" ");
    }/*  ww w  .  j av a2  s.co m*/
    return normalized.toString().trim();
}