Example usage for com.google.common.collect Collections2 filter

List of usage examples for com.google.common.collect Collections2 filter

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 filter.

Prototype



@CheckReturnValue
public static <E> Collection<E> filter(Collection<E> unfiltered, Predicate<? super E> predicate) 

Source Link

Document

Returns the elements of unfiltered that satisfy a predicate.

Usage

From source file:org.napile.idea.plugin.caches.NapileGotoSymbolContributor.java

@NotNull
@Override/*w w  w .j  a  v a 2 s .c  o  m*/
public NavigationItem[] getItemsByName(String name, String pattern, Project project,
        boolean includeNonProjectItems) {
    final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project)
            : GlobalSearchScope.projectScope(project);

    final Collection<? extends NavigationItem> it1 = StubIndex.getInstance()
            .get(NapileIndexKeys.METHODS_SHORT_NAME_KEY, name, project, scope);
    final Collection<? extends NavigationItem> it2 = StubIndex.getInstance()
            .get(NapileIndexKeys.MACROS_SHORT_NAME_KEY, name, project, scope);
    final Collection<? extends NavigationItem> it3 = StubIndex.getInstance()
            .get(NapileIndexKeys.VARIABLES_SHORT_NAME_KEY, name, project, scope);

    List<NavigationItem> symbols = new ArrayList<NavigationItem>(it1.size() + it2.size() + it3.size());
    symbols.addAll(it1);
    symbols.addAll(it2);
    symbols.addAll(it3);

    final List<NavigationItem> items = new ArrayList<NavigationItem>(
            Collections2.filter(symbols, Predicates.notNull()));
    return ArrayUtil.toObjectArray(items, NavigationItem.class);
}

From source file:com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaClass.java

public Collection<MetaProperty> getPropertiesFilteredByCategory(final Category category) {
    return Collections2.filter(getProperties(), new Predicate<MetaProperty>() {
        @Override//  ww  w  .  j a v a  2 s.c  o m
        public boolean apply(@Nullable MetaProperty input) {
            if (input != null && category != null) {
                CategoryAttribute categoryAttribute = attributes.get(input.getName());
                return category.equals(categoryAttribute.getCategory());
            } else {
                return false;
            }
        }
    });
}

From source file:se.crafted.chrisb.ecoCreature.drops.categories.AbstractDropCategory.java

public Collection<AbstractDropSource> getDropSources(final Event event) {
    Collection<AbstractDropSource> dropSources = Collections.emptyList();

    if (isValidEvent(event)) {
        dropSources = Collections2.filter(getDropSources(extractType(event)),
                new Predicate<AbstractDropSource>() {

                    @Override/*from   w ww  .  jav  a  2 s. c  o  m*/
                    public boolean apply(AbstractDropSource source) {
                        return source.hasPermission(extractPlayer(event)) && isNotRuleBroken(event, source);
                    }

                });
    }

    return dropSources;
}

From source file:pt.ist.maidSyncher.domain.activeCollab.ACTaskCategory.java

public static Collection<ACTaskCategory> getByName(final String name) {
    checkArgument(StringUtils.isBlank(name) == false, "Name mustn't be blank");
    MaidRoot maidRoot = MaidRoot.getInstance();

    Collection<ACObject> existingACTaskCategories = Collections2.filter(maidRoot.getAcObjectsSet(),
            new Predicate<ACObject>() {
                @Override//  w w  w .  jav  a2s.c o m
                public boolean apply(ACObject acObject) {
                    if (acObject == null)
                        return false;
                    if (acObject instanceof ACTaskCategory) {
                        ACTaskCategory acTaskCategory = (ACTaskCategory) acObject;
                        if (acTaskCategory.getName().equalsIgnoreCase(name))
                            return true;
                        return false;
                    } else
                        return false;

                }
            });
    return Collections2.transform(existingACTaskCategories, new Function<ACObject, ACTaskCategory>() {
        @Override
        public ACTaskCategory apply(ACObject acObject) {
            return (ACTaskCategory) acObject;
        }
    });

}

From source file:ru.crazyproger.plugins.webtoper.nls.codeinsight.NlsCompletionContributor.java

@NotNull
public static Collection<NlsFileImpl> getNlsFiles(Project project) {
    Collection<VirtualFile> files = getNlsVirtualFiles(project);
    if (files.isEmpty())
        return Collections.emptyList();
    final PsiManager psiManager = PsiManager.getInstance(project);
    Collection<NlsFileImpl> nlsFiles = Collections2.transform(files, new Function<VirtualFile, NlsFileImpl>() {
        @Override/*from  www  .j av  a2 s  .com*/
        public NlsFileImpl apply(@Nullable VirtualFile virtualFile) {
            if (virtualFile != null) {
                return (NlsFileImpl) psiManager.findFile(virtualFile);
            }
            return null;
        }
    });
    return Collections2.filter(nlsFiles, Predicates.notNull());
}

From source file:org.ow2.play.governance.dcep.PatternServiceImpl.java

@Override
@WebMethod/* w w w .  ja  v  a  2 s.  c  o m*/
public String deploy(String id, String pattern) throws GovernanceExeption {
    String result = "";
    List<Metadata> out = complexPatternService.deploy(id, pattern, null);

    // get the endpoint to subscribe to from the metadata
    List<Metadata> endpoints = Lists.newArrayList(Collections2.filter(out, new Predicate<Metadata>() {
        public boolean apply(Metadata md) {
            return md != null && md.getName() != null && md.getName().equals("endpoint");
        };
    }));

    result = endpoints.get(0) != null && endpoints.get(0).getData() != null
            && endpoints.get(0).getData().get(0) != null ? endpoints.get(0).getData().get(0).getValue() : "";
    return result;
}

From source file:vars.annotation.ui.imagepanel.Measurement.java

/**
 *
 * @param observation//from   ww w  . j  a v  a 2 s  .  c  o m
 * @return
 */
public static Collection<Measurement> fromObservation(Observation observation) {
    Collection<Association> associations = Collections2.filter(observation.getAssociations(),
            IS_MEASUREMENT_PREDICATE);
    Collection<Measurement> measurements = Collections2.transform(associations, LINK_TO_MEASUREMENT_TRANSFORM);

    return new ArrayList<Measurement>(measurements);
}

From source file:org.richfaces.demo.autocomplete.AutoCompleteBean.java

public Object autocomplete(FacesContext facesContext, UIComponent component, String value) {
    AutocompleteMode mode = (AutocompleteMode) component.getAttributes().get("mode");
    boolean isClient = mode == AutocompleteMode.client || mode == AutocompleteMode.lazyClient;
    String v = isClient || value == null ? "" : value;

    return Collections2.filter(countriesBean.getCountries(),
            new CountryNamePredicate(v.toLowerCase(Locale.US)));
}

From source file:dynamicrefactoring.domain.AbstractRefactoringsCatalog.java

@Override
public final boolean hasRefactoring(final String name) {
    return !Collections2.filter(ImmutableSet.copyOf(refactorings), new SameNamePredicate(name)).isEmpty();
}

From source file:com.shigengyu.hyperion.core.TransitionExecutionResult.java

public final Collection<TransitionExecutionLog> getWarnings() {
    return Collections2.filter(logs, new Predicate<TransitionExecutionLog>() {

        @Override/*  www. j  a  v a 2s  .  co m*/
        public boolean apply(TransitionExecutionLog item) {
            return item.getType() == Type.WARNING;
        }
    });
}