Example usage for com.google.common.collect FluentIterable limit

List of usage examples for com.google.common.collect FluentIterable limit

Introduction

In this page you can find the example usage for com.google.common.collect FluentIterable limit.

Prototype

@CheckReturnValue
public final FluentIterable<E> limit(int maxSize) 

Source Link

Document

Creates a fluent iterable with the first size elements of this fluent iterable.

Usage

From source file:org.obm.imap.sieve.commands.SieveGetScript.java

@Override
public void responseReceived(List<SieveResponse> rs) {
    if (commandSucceeded(rs)) {
        String data = rs.get(0).getData();
        Iterable<String> splitData = Splitter.on(SieveConstants.SPLIT_EXPR).split(data);
        FluentIterable<String> splitDataNoByteCount = FluentIterable.from(splitData).skip(1);
        FluentIterable<String> splitDataNoByteCountAndNoReturnCode = splitDataNoByteCount
                .limit(splitDataNoByteCount.size() - 1);
        if (!splitDataNoByteCountAndNoReturnCode.isEmpty()) {
            this.retVal = Joiner.on(SieveConstants.SEP).join(splitDataNoByteCountAndNoReturnCode) + "\r\n";
        } else {//from w w  w  .  j  av a  2 s .c om
            this.retVal = "";
        }
    } else {
        reportErrors(rs);
    }
    logger.info("returning a sieve script");
}

From source file:org.grouplens.lenskit.knn.item.DefaultItemScoreAlgorithm.java

@Override
public void scoreItems(ItemItemModel model, SparseVector userData, MutableSparseVector scores,
        NeighborhoodScorer scorer) {//from  www . j  a va 2 s. c om
    Predicate<ScoredId> usable = new VectorKeyPredicate(userData);

    // Create a channel for recording the neighborhoodsize
    MutableSparseVector sizeChannel = scores.getOrAddChannelVector(ItemItemScorer.NEIGHBORHOOD_SIZE_SYMBOL);
    sizeChannel.fill(0);
    // for each item, compute its prediction
    for (VectorEntry e : scores.fast(VectorEntry.State.EITHER)) {
        final long item = e.getKey();

        // find all potential neighbors
        FluentIterable<ScoredId> nbrIter = FluentIterable.from(model.getNeighbors(item)).filter(usable);
        if (neighborhoodSize > 0) {
            nbrIter = nbrIter.limit(neighborhoodSize);
        }
        List<ScoredId> neighbors = nbrIter.toList();

        // compute score & place in vector
        ScoredId score = null;

        if (neighbors.size() >= minNeighbors) {
            score = scorer.score(item, neighbors, userData);
        }

        if (score != null) {
            scores.set(e, score.getScore());
            for (TypedSymbol sym : score.getChannelSymbols()) {
                scores.getOrAddChannel(sym).put(e.getKey(), score.getChannelValue(sym));
            }
        }

        sizeChannel.set(e, neighbors.size());
    }
}

From source file:com.google.gerrit.server.project.RefFilter.java

public List<T> filter(List<T> refs) throws BadRequestException {
    FluentIterable<T> results = FluentIterable.from(refs);
    if (!Strings.isNullOrEmpty(matchSubstring)) {
        results = results.filter(new SubstringPredicate(matchSubstring));
    } else if (!Strings.isNullOrEmpty(matchRegex)) {
        results = results.filter(new RegexPredicate(matchRegex));
    }//from   w w w.j  a  va2  s .c o m
    if (start > 0) {
        results = results.skip(start);
    }
    if (limit > 0) {
        results = results.limit(limit);
    }
    return results.toList();
}