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:com.streamreduce.util.HashtagUtil.java

/**
 * Normalizes a Collection of potential hashtags by filtering out all
 * empty/null Strings in the collection and then calls normalizeTag(String) on each remaining String.
 *
 * @param tags a collection of potential tags to normalize.
 * @return a List of normalized Strings from the passed in list, or a modifiable empty List if tags was null.
 *///w w  w. j  a va2s . co  m
public static List<String> normalizeTags(Collection<String> tags) {
    if (tags == null) {
        return Lists.newArrayList();
    }

    //First filter out null and empty strings
    return Lists.newArrayList(Iterables.transform(Iterables.filter(tags, new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String input) {
            return !StringUtils.isBlank(input);
        }
    }), new Function<String, String>() {
        @Override
        public String apply(@Nullable String input) {
            return normalizeTag(input);
        }
    }));
}

From source file:org.eclipse.sirius.business.internal.movida.registry.DefaultViewpointResourceHandler.java

/**
 * {@inheritDoc}//from   w  w  w . java  2  s . c om
 */
public Set<Viewpoint> collectViewpointDefinitions(Resource res) {
    Set<Viewpoint> viewpoints = Sets.newHashSet();
    for (Group group : Iterables.filter(res.getContents(), Group.class)) {
        for (Viewpoint viewpoint : group.getOwnedViewpoints()) {
            viewpoints.add(viewpoint);
        }
    }
    return ImmutableSet.copyOf(Iterables.filter(viewpoints, Predicates.notNull()));
}

From source file:org.robotframework.ide.eclipse.main.plugin.tableeditor.settings.SettingsEditorPageSelectionProvider.java

public SettingsEditorPageSelectionProvider(final ISettingsFormFragment... formFragments) {
    this.formFragments = newArrayList(Iterables.filter(Arrays.asList(formFragments), Predicates.notNull()));
    for (final ISettingsFormFragment formFragment : formFragments) {
        addFocusListener(formFragment);//ww w  .ja  va2  s . c  o  m
    }
}

From source file:edu.harvard.med.screensaver.model.libraries.LibraryPlate.java

public LibraryPlate(Integer plateNumber, Library library, Set<AssayPlate> assayPlates) {
    super(plateNumber);

    _library = library;//from  w  w  w .  j a v a2  s  . c om
    _assayPlateCount = assayPlates.size();
    Iterable<AssayPlate> assayPlatesUniqueAttempts = Iterables.filter(assayPlates, AssayPlate.IsFirstReplicate);
    _copiesScreened = Sets
            .newTreeSet(Iterables.transform(Iterables.filter(assayPlates, AssayPlate.HasLibraryScreening),
                    Functions.compose(Plate.ToCopy, AssayPlate.ToPlate)));
    _libraryScreenings = Sets.newTreeSet(
            Iterables.filter(Iterables.transform(assayPlatesUniqueAttempts, AssayPlate.ToLibraryScreening),
                    Predicates.notNull()));
    if (!_libraryScreenings.isEmpty()) {
        _firstDateScreened = _libraryScreenings.first().getDateOfActivity();
        _lastDateScreened = _libraryScreenings.last().getDateOfActivity();
    }
    SortedSet<AdministrativeActivity> dataLoadings = Sets.newTreeSet(Iterables.filter(
            Iterables.transform(assayPlatesUniqueAttempts, AssayPlate.ToScreenResultDataLoading),
            Predicates.notNull()));
    _dataLoadingCount = dataLoadings.size();
    if (_dataLoadingCount > 0) {
        _firstDateDataLoaded = dataLoadings.first().getDateOfActivity();
        _lastDateDataLoaded = dataLoadings.last().getDateOfActivity();
    }
}

From source file:edu.umd.cs.psl.application.groundkernelstore.MemoryGroundKernelStore.java

@Override
public Iterable<GroundCompatibilityKernel> getCompatibilityKernels() {
    return Iterables.filter(evidences.filterIterable(Filters.ProbabilisticEvidence),
            GroundCompatibilityKernel.class);
}

From source file:org.eclipse.xtext.scoping.impl.FilteringScope.java

@Override
public Iterable<IEObjectDescription> getElements(QualifiedName name) {
    return Iterables.filter(delegate.getElements(name), filter);
}

From source file:org.obiba.opal.web.datashield.DataShieldPackagesResource.java

@GET
public List<OpalR.RPackageDto> getPackages() throws REXPMismatchException {
    RScriptROperation rop = getInstalledPackages();
    REXP rexp = rop.getResult();/*  www .ja  v a  2  s .c  o m*/
    RStringMatrix matrix = new RStringMatrix(rexp);
    Iterable<OpalR.RPackageDto> dtos = Iterables.filter(
            Iterables.transform(matrix.iterateRows(), new StringsToRPackageDto(matrix)),
            new DataShieldPackagePredicate());
    return Lists.newArrayList(dtos);
}

From source file:com.google.gerrit.server.extensions.webui.UiCommands.java

public static <R extends RestResource> Iterable<UiCommandDetail> from(DynamicMap<RestView<R>> views,
        final R resource, final EnumSet<UiCommand.Place> places) {
    return Iterables
            .filter(Iterables.transform(views, new Function<DynamicMap.Entry<RestView<R>>, UiCommandDetail>() {
                @Override//w  w  w. java 2s .c  o m
                @Nullable
                public UiCommandDetail apply(DynamicMap.Entry<RestView<R>> e) {
                    int d = e.getExportName().indexOf('.');
                    if (d < 0) {
                        return null;
                    }

                    String method = e.getExportName().substring(0, d);
                    String name = e.getExportName().substring(d + 1);
                    RestView<R> view;
                    try {
                        view = e.getProvider().get();
                    } catch (RuntimeException err) {
                        log.error(String.format("error creating view %s.%s", e.getPluginName(),
                                e.getExportName()), err);
                        return null;
                    }

                    if (!(view instanceof UiCommand)) {
                        return null;
                    }

                    UiCommand<R> cmd = (UiCommand<R>) view;
                    if (Sets.intersection(cmd.getPlaces(), places).isEmpty() || !cmd.isVisible(resource)) {
                        return null;
                    }

                    UiCommandDetail dsc = new UiCommandDetail();
                    dsc.id = e.getPluginName() + '~' + name;
                    dsc.method = method;
                    dsc.label = cmd.getLabel(resource);
                    dsc.title = cmd.getTitle(resource);
                    dsc.enabled = cmd.isEnabled(resource);
                    dsc.confirmationMessage = cmd.getConfirmationMessage(resource);
                    return dsc;
                }
            }), Predicates.notNull());
}

From source file:org.eclipse.sirius.diagram.ui.internal.edit.policies.DNodeListItemSemanticEditPolicy.java

/**
 * @was-generated/*from  w  w  w  .j  av a 2 s .c  o m*/
 */
protected void addDestroyChildNodesCommand(CompoundCommand cmd) {
    View view = (View) getHost().getModel();
    EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
    if (annotation != null) {
        return;
    }
    for (Node node : Iterables.filter(view.getChildren(), Node.class)) {
        switch (SiriusVisualIDRegistry.getVisualID(node)) {
        case DNode4EditPart.VISUAL_ID:
            cmd.add(getDestroyElementCommand(node));
            break;
        case DNodeListViewNodeListCompartmentEditPart.VISUAL_ID:
        case DNodeListViewNodeListCompartment2EditPart.VISUAL_ID:
            for (Node cnode : Iterables.filter(node.getChildren(), Node.class)) {
                switch (SiriusVisualIDRegistry.getVisualID(cnode)) {
                case DNodeListElementEditPart.VISUAL_ID:
                    cmd.add(getDestroyElementCommand(cnode));
                    break;
                }
            }
            break;
        default:
            break;
        }
    }
}

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

public Object apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return ImmutableSet.of();
    } else if (rto404.apply(from)) {
        return ImmutableSet.of();
    }//from www.jav a2  s  .c  o m
    return Set.class.cast(propagateOrNull(from));
}