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:net.shibboleth.idp.authn.impl.ExtractRemoteUser.java

/**
 * Set the list of request attributes to check for an identity.
 * /*w w  w .  j ava2 s.c  om*/
 * @param attributes    list of request attributes to check
 */
public void setCheckAttributes(@Nonnull @NonnullElements final Collection<String> attributes) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);

    checkAttributes = Lists.newArrayList(Collections2.filter(attributes, Predicates.notNull()));
}

From source file:com.ning.billing.util.tag.dao.DefaultTagDao.java

@Override
public List<TagModelDao> getTagsForAccountType(final UUID accountId, final ObjectType objectType,
        final InternalTenantContext internalTenantContext) {

    final List<TagModelDao> allTags = getTagsForAccount(accountId, internalTenantContext);
    return ImmutableList.<TagModelDao>copyOf(Collections2.filter(allTags, new Predicate<TagModelDao>() {
        @Override/*from w ww  .j a va 2  s  .  c o  m*/
        public boolean apply(@Nullable final TagModelDao input) {
            return input.getObjectType() == objectType;
        }
    }));
}

From source file:net.pterodactylus.sone.web.ajax.GetStatusAjaxPage.java

/**
 * {@inheritDoc}// ww w .  ja v  a  2 s  .  c  o m
 */
@Override
protected JsonReturnObject createJsonObject(FreenetRequest request) {
    final Sone currentSone = getCurrentSone(request.getToadletContext(), false);
    /* load Sones. always return the status of the current Sone. */
    Set<Sone> sones = new HashSet<Sone>(
            Collections.singleton(getCurrentSone(request.getToadletContext(), false)));
    String loadSoneIds = request.getHttpRequest().getParam("soneIds");
    if (loadSoneIds.length() > 0) {
        String[] soneIds = loadSoneIds.split(",");
        for (String soneId : soneIds) {
            /* just add it, we skip null further down. */
            sones.add(webInterface.getCore().getSone(soneId).orNull());
        }
    }
    ArrayNode jsonSones = new ArrayNode(instance);
    for (Sone sone : sones) {
        if (sone == null) {
            continue;
        }
        jsonSones.add(createJsonSone(sone));
    }
    /* load notifications. */
    List<Notification> notifications = ListNotificationFilters
            .filterNotifications(webInterface.getNotifications().getNotifications(), currentSone);
    Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
    /* load new posts. */
    Collection<Post> newPosts = webInterface.getNewPosts();
    if (currentSone != null) {
        newPosts = Collections2.filter(newPosts, new Predicate<Post>() {

            @Override
            public boolean apply(Post post) {
                return ListNotificationFilters.isPostVisible(currentSone, post);
            }

        });
    }
    ArrayNode jsonPosts = new ArrayNode(instance);
    for (Post post : newPosts) {
        ObjectNode jsonPost = new ObjectNode(instance);
        jsonPost.put("id", post.getId());
        jsonPost.put("sone", post.getSone().getId());
        jsonPost.put("recipient", post.getRecipientId().orNull());
        jsonPost.put("time", post.getTime());
        jsonPosts.add(jsonPost);
    }
    /* load new replies. */
    Collection<PostReply> newReplies = webInterface.getNewReplies();
    if (currentSone != null) {
        newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {

            @Override
            public boolean apply(PostReply reply) {
                return ListNotificationFilters.isReplyVisible(currentSone, reply);
            }

        });
    }
    /* remove replies to unknown posts. */
    newReplies = Collections2.filter(newReplies, PostReply.HAS_POST_FILTER);
    ArrayNode jsonReplies = new ArrayNode(instance);
    for (PostReply reply : newReplies) {
        ObjectNode jsonReply = new ObjectNode(instance);
        jsonReply.put("id", reply.getId());
        jsonReply.put("sone", reply.getSone().getId());
        jsonReply.put("post", reply.getPostId());
        jsonReply.put("postSone", reply.getPost().get().getSone().getId());
        jsonReplies.add(jsonReply);
    }
    return createSuccessJsonObject().put("loggedIn", currentSone != null)
            .put("options", createJsonOptions(currentSone)).put("sones", jsonSones)
            .put("notificationHash", notifications.hashCode()).put("newPosts", jsonPosts)
            .put("newReplies", jsonReplies);
}

From source file:org.sonar.server.metric.persistence.MetricDao.java

public List<String> selectDomains(DbSession session) {
    return newArrayList(Collections2.filter(mapper(session).selectDomains(), new NotEmptyPredicate()));
}

From source file:org.apache.drill.exec.server.options.SessionOptionManager.java

@Override
Iterable<OptionValue> optionIterable() {
    final Collection<OptionValue> liveOptions = Collections2.filter(options.values(), isLive);
    return liveOptions;
}

From source file:org.apache.isis.core.commons.lang.ListExtensions.java

public static <T> Collection<T> filtered(final List<Object> extendee, final Class<T> type) {
    return Collections2.transform(Collections2.filter(extendee, ClassPredicates.isOfType(type)),
            ClassFunctions.castTo(type));
}

From source file:org.yakindu.sct.model.sgraph.naming.SGraphNameProvider.java

public QualifiedName qualifiedName(Choice ele) {

    // first get order number of choice node
    List<Vertex> choiceList = new ArrayList<Vertex>();
    choiceList.addAll(Collections2.filter(((Region) ele.eContainer()).getVertices(), new Predicate<Vertex>() {
        public boolean apply(Vertex input) {
            return input instanceof Choice;
        }// ww w.  j  av a  2s . c om
    }));
    int index = choiceList.indexOf(ele);

    QualifiedName qualifiedNameFromConverter = QualifiedName.create(_CHOICE_NAME + index);

    return getParentQualifiedName(ele, qualifiedNameFromConverter);
}

From source file:org.opensaml.saml.metadata.resolver.ChainingMetadataResolver.java

/**
 * Set the registered metadata resolvers.
 * //from w w  w .  j ava  2 s . c  o m
 * @param newResolvers the metadata resolvers to use
 * 
 * @throws ResolverException thrown if there is a problem adding the metadata resolvers
 */
public void setResolvers(@Nonnull @NonnullElements final List<? extends MetadataResolver> newResolvers)
        throws ResolverException {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);

    if (newResolvers == null || newResolvers.isEmpty()) {
        resolvers = Collections.emptyList();
        return;
    }

    resolvers = new ArrayList<>(Collections2.filter(newResolvers, Predicates.notNull()));
}

From source file:com.cubeia.poker.rounds.ante.AnteRoundHelper.java

int numberOfPendingPlayers(Collection<PokerPlayer> players) {
    Collection<PokerPlayer> hasActed = Collections2.filter(players, new Predicate<PokerPlayer>() {
        @Override//from w w w. jav a 2  s. co m
        public boolean apply(PokerPlayer player) {
            return !player.hasActed();
        }
    });
    return hasActed.size();
}

From source file:net.sourceforge.atunes.kernel.actions.RepairAlbumNamesAction.java

/**
 * Returns files without album//from ww  w .  j a  v a  2  s  . c  o m
 * @param audioFiles
 * @return
 */
private Collection<ILocalAudioObject> getFilesWithEmptyAlbum(final Collection<ILocalAudioObject> audioFiles) {
    return Collections2.filter(audioFiles, new FilesWithEmptyAlbumFilter());
}