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:io.joynr.messaging.bounceproxy.controller.directory.inmemory.InMemoryBounceProxyDirectory.java

@Override
public List<BounceProxyRecord> getAssignableBounceProxies() {

    Predicate<BounceProxyRecord> statusIsAssignablePredicate = new Predicate<BounceProxyRecord>() {

        @Override/*from w  w  w  .j  av a 2s .  c  om*/
        public boolean apply(BounceProxyRecord record) {
            if (record == null)
                return false;
            return record.getStatus().isAssignable();
        }
    };
    Collection<BounceProxyRecord> assignableBounceProxies = Collections2.filter(directory.values(),
            statusIsAssignablePredicate);

    return new LinkedList<BounceProxyRecord>(assignableBounceProxies);
}

From source file:net.pterodactylus.sone.fcp.GetPostFeedCommand.java

/**
 * {@inheritDoc}/*from   w  ww .  jav  a 2s.c o  m*/
 */
@Override
public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Sone sone = getSone(parameters, "Sone", true);
    int startPost = getInt(parameters, "StartPost", 0);
    int maxPosts = getInt(parameters, "MaxPosts", -1);

    Collection<Post> allPosts = new HashSet<Post>();
    allPosts.addAll(sone.getPosts());
    for (String friendSoneId : sone.getFriends()) {
        Optional<Sone> friendSone = getCore().getSone(friendSoneId);
        if (!friendSone.isPresent()) {
            continue;
        }
        allPosts.addAll(friendSone.get().getPosts());
    }
    allPosts.addAll(getCore().getDirectedPosts(sone.getId()));
    allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);

    List<Post> sortedPosts = new ArrayList<Post>(allPosts);
    Collections.sort(sortedPosts, Post.TIME_COMPARATOR);

    if (sortedPosts.size() < startPost) {
        return new Response("PostFeed", encodePosts(Collections.<Post>emptyList(), "Posts.", false));
    }

    return new Response("PostFeed",
            encodePosts(
                    sortedPosts
                            .subList(startPost,
                                    (maxPosts == -1) ? sortedPosts.size()
                                            : Math.min(startPost + maxPosts, sortedPosts.size())),
                    "Posts.", true));
}

From source file:org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.java

public static State findState(Statechart sc, final String name) {
    Collection<EObject> states = Collections2.filter(EcoreUtil2.eAllContentsAsList(sc),
            new Predicate<Object>() {

                public boolean apply(Object obj) {
                    // TODO Auto-generated method stub
                    return obj != null && obj instanceof State && name.equals(((State) obj).getName());
                }//w  ww .  ja  va2  s  .c  o m
            });

    return (states.size() > 0) ? (State) states.iterator().next() : null;
}

From source file:com.madvay.tools.android.perf.common.Table.java

public void matching(FilterSpec spec) {
    final FilterSpec filterSpec = spec;
    rows = Lists.newArrayList(Collections2.filter(rows, new RowFilter(filterSpec)));
}

From source file:org.tzi.use.gui.views.diagrams.classdiagram.ClassNode.java

ClassNode(MClass cls, DiagramOptions opt) {
    super(cls, opt);

    fAttributes = cls.attributes();/*w ww .jav  a 2  s .  c  o m*/
    fAttrValues = new String[fAttributes.size()];
    fAttrColors = new Color[fAttributes.size()];

    fOperations = new ArrayList<>(Collections2.filter(cls.operations(), new Predicate<MOperation>() {
        @Override
        public boolean apply(MOperation input) {
            return !input.getAnnotationValue("View", "hideInDiagram").equals("true");
        }
    }));

    fOprSignatures = new String[fOperations.size()];
    fOperationColors = new Color[fOperations.size()];

    copyDisplayedValues();
}

From source file:org.eclipse.incquery.viewers.runtime.model.IncQueryViewerDataModel.java

public Collection<IQuerySpecification<?>> getPatterns(final String annotation) {
    return Collections2.filter(patterns, new Predicate<IQuerySpecification<?>>() {

        @Override/*from  w  ww  .  jav  a2  s.  c  o  m*/
        public boolean apply(IQuerySpecification<?> pattern) {
            return !pattern.getAnnotationsByName(annotation).isEmpty();
        }
    });
}

From source file:org.killbill.billing.entitlement.dao.MockBlockingStateDao.java

@Override
public BlockingState getBlockingStateForService(final UUID blockableId,
        final BlockingStateType blockingStateType, final String serviceName,
        final InternalTenantContext context) {
    final List<BlockingState> states = blockingStates.get(blockableId);
    if (states == null) {
        return null;
    }/*  w ww  . j  a v  a  2 s. com*/
    final ImmutableList<BlockingState> filtered = ImmutableList
            .<BlockingState>copyOf(Collections2.filter(states, new Predicate<BlockingState>() {
                @Override
                public boolean apply(@Nullable final BlockingState input) {
                    return input.getService().equals(serviceName);
                }
            }));
    return filtered.size() == 0 ? null : filtered.get(filtered.size() - 1);
}

From source file:org.apache.ctakes.assertion.attributes.features.selection.FeatureSelection.java

public List<Feature> transform(List<Feature> features) {
    List<Feature> results = Lists.newArrayList();
    if (this.isTrained) {
        results.addAll(Collections2.filter(features, this));
    } else {//from   ww w. j a va 2s  .c  o  m
        results.add(new TransformableFeature(this.name, features));
    }
    return results;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.CandidacyProcessSelectDegreesBean.java

protected Collection<Degree> filterDegrees(Collection<Degree> degrees) {
    final Set<AcademicProgram> programs = AcademicAuthorizationGroup.getProgramsForOperation(
            AccessControl.getPerson(), AcademicOperationType.MANAGE_CANDIDACY_PROCESSES);
    return Collections2.filter(degrees, new Predicate<Degree>() {
        @Override//from   ww w.j a  v a 2s.c  o  m
        public boolean apply(Degree degree) {
            return programs.contains(degree);
        }
    });
}

From source file:org.paltest.pal.junit.runner.PalRunner.java

@Override
protected List<FrameworkMethod> computeTestMethods() {
    return new ArrayList<FrameworkMethod>(
            Collections2.filter(super.computeTestMethods(), isNotEvaluateMethod()));
}