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.business.internal.session.danalysis.MovidaSupport.java

void updatePhysicalVSMResourceURIs(Collection<Viewpoint> selectedViewpoints) {
    Set<URI> selected = Sets.newHashSet(
            Iterables.filter(Iterables.transform(selectedViewpoints, new Function<Viewpoint, URI>() {
                public URI apply(Viewpoint from) {
                    return new ViewpointQuery(from).getViewpointURI().get();
                }// w w  w  . j  av  a 2s .  c o  m
            }), Predicates.notNull()));
    vsmResources = new VSMResolver(
            (org.eclipse.sirius.business.internal.movida.registry.ViewpointRegistry) ViewpointRegistry
                    .getInstance()).resolve(selected);
}

From source file:com.google.cloud.dataflow.sdk.util.DirectSideInputReader.java

@Override
public <T> T get(PCollectionView<T> view, final BoundedWindow window) {
    final TupleTag<Iterable<WindowedValue<?>>> tag = view.getTagInternal();
    if (!sideInputValues.has(tag)) {
        throw new IllegalArgumentException("calling getSideInput() with unknown view");
    }/*  w  w  w .j av  a  2  s.c  o  m*/

    if (view.getWindowingStrategyInternal().getWindowFn() instanceof GlobalWindows) {
        return view.fromIterableInternal(sideInputValues.get(tag));
    } else {
        return view.fromIterableInternal(
                Iterables.filter(sideInputValues.get(tag), new Predicate<WindowedValue<?>>() {
                    @Override
                    public boolean apply(WindowedValue<?> element) {
                        return element.getWindows().contains(window);
                    }
                }));
    }
}

From source file:com.b2international.snowowl.identity.MultiIdentityProvider.java

@Override
public Promise<Users> searchUsers(Collection<String> usernames, int limit) {
    return Promise.all(providers.stream().map(provider -> provider.searchUsers(usernames, limit))
            .collect(Collectors.toList())).then(responses -> {
                final ImmutableList.Builder<User> users = ImmutableList.builder();
                int total = 0;
                for (Users matches : Iterables.filter(responses, Users.class)) {
                    users.addAll(matches);
                    total += matches.getTotal();
                }/*from  w  w w . ja  v a2s . c o m*/
                return new Users(users.build(), limit, total);
            });
}

From source file:org.opendaylight.netvirt.openstack.netvirt.impl.ProviderNetworkManagerImpl.java

@Override
public NetworkingProvider getProvider(Node node) {
    if (nodeToProviderMapping.get(node) != null) {
        return nodeToProviderMapping.get(node);
    }/*from w  w w . ja  va 2s .co  m*/

    final String targetVersion = Constants.OPENFLOW13;
    Predicate<ProviderEntry> providerEntryPredicate = new Predicate<ProviderEntry>() {
        @Override
        public boolean apply(ProviderEntry providerEntry) {
            //ToDo: This should match on southboundProtocol and providerType too
            return providerEntry.getProperties().get(Constants.OPENFLOW_VERSION_PROPERTY).equals(targetVersion);
        }
    };

    Iterable<ProviderEntry> matchingProviders = Iterables.filter(providers.values(), providerEntryPredicate);
    if (!matchingProviders.iterator().hasNext()) {
        LOG.error("No providers matching {} found", targetVersion);
    }

    // Return the first match as only have one matching provider today
    // ToDo: Tie-breaking logic
    NetworkingProvider provider = matchingProviders.iterator().next().getProvider();
    nodeToProviderMapping.put(node, provider);
    return provider;
}

From source file:org.spongepowered.api.command.args.PatternMatchingCommandElement.java

@Nullable
@Override//ww  w . jav  a2  s  . com
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    final String unformattedPattern = args.next();
    Pattern pattern = getFormattedPattern(unformattedPattern);
    Iterable<String> filteredChoices = Iterables.filter(getChoices(source),
            element -> pattern.matcher(element).find());
    for (String el : filteredChoices) { // Match a single value
        if (el.equalsIgnoreCase(unformattedPattern)) {
            return Collections.singleton(getValue(el));
        }
    }
    Iterable<Object> ret = Iterables.transform(filteredChoices, this::getValue);

    if (!ret.iterator().hasNext()) {
        throw args.createError(t("No values matching pattern '%s' present for %s!", unformattedPattern,
                getKey() == null ? nullKeyArg : getKey()));
    }
    return ret;
}

From source file:com.isotrol.impe3.connectors.device.DeviceResolverByWidth.java

@Override
ResolvedDevice resolve(DeviceResolutionParams params, Iterable<DeviceInPortal> devices) {
    final DeviceCapabilities caps = params.getCapabilities();
    if (caps == null || devices == null) {
        return null;
    }// w  ww.  j  a v a  2s  .  c  o  m
    List<DeviceInPortal> ordered = ORDER.sortedCopy(Iterables.filter(devices, WITH_WIDTH));
    if (ordered == null || ordered.isEmpty()) {
        return null;
    }
    int width = caps.getWidth();
    for (DeviceInPortal dip : ordered) {
        if (width <= dip.getDevice().getWidth()) {
            return params.resolve(dip.getDevice());
        }
    }
    return params.resolve(ordered.get(ordered.size() - 1).getDevice());
}

From source file:org.eclipse.emf.compare.ide.ui.internal.actions.group.DifferenceGrouper.java

/**
 * This will be called internally by the ComparisonNode in order to know how it should group its
 * differences.//from   w  w  w . ja  va 2 s.c  o m
 * 
 * @param comparison
 *            The comparison which differences need to be grouped.
 * @return The collection of groups we could retrieve from the currently selected group provider. Empty
 *         {@link Iterable} if we have no group provider set.
 */
public Iterable<? extends DifferenceGroup> getGroups(final Comparison comparison) {
    if (provider == null) {
        return ImmutableList.of();
    }

    final Iterable<? extends DifferenceGroup> groups = provider.getGroups(comparison);
    final Iterable<? extends DifferenceGroup> filteredGroups = Iterables.filter(groups, new NonEmptyGroup());
    return filteredGroups;
}

From source file:at.ac.univie.isc.asio.security.ExpandAuthoritiesContainer.java

/**
 * Map all {@link org.springframework.security.core.authority.GrantedAuthoritiesContainer authority container}
 * to themselves and their contained authorities.
 * Only first level members are expanded, i.e. nested containers are not supported.
 *
 * @param authorities source authorities
 * @return authorities plus all contained ones
 *//*from   w  w w  .j a  v a2 s.  c om*/
@Override
public Set<GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) {
    final ImmutableSet.Builder<GrantedAuthority> mapped = ImmutableSet.builder();
    mapped.addAll(authorities);
    for (final GrantedAuthoritiesContainer container : Iterables.filter(authorities,
            GrantedAuthoritiesContainer.class)) {
        for (final GrantedAuthority each : container.getGrantedAuthorities()) {
            mapped.add(each);
        }
    }
    final ImmutableSet<GrantedAuthority> result = mapped.build();
    log.debug("mapped source authority containers {} to contained authorities {}", authorities, result);
    return result;
}

From source file:cc.recommenders.evaluation.io.TypeStore.java

private List<Usage> filterAndMapUsages(Predicate<ProjectFoldedUsage> pred) {
    Iterable<ProjectFoldedUsage> filtered = Iterables.filter(allUsages, pred);
    Iterable<Usage> usages = Iterables.transform(filtered, usageTransformation());
    return Lists.newLinkedList(usages);
}

From source file:eu.esdihumboldt.hale.ui.views.mapping.AlignmentViewContentProvider.java

/**
 * @see eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider#getEdges(java.lang.Iterable)
 *///w w w. jav  a2 s .  c  o  m
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Object[] getEdges(Iterable<?> cells) {
    return super.getEdges(Iterables.filter(cells, new Predicate() {

        @Override
        public boolean apply(Object input) {
            if (input instanceof Cell) {
                return select((Cell) input);
            } else
                return false;
        }
    }));
}