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

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

Introduction

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

Prototype

@CheckReturnValue
public final ImmutableList<E> toList() 

Source Link

Document

Returns an ImmutableList containing all of the elements from this fluent iterable in proper sequence.

Usage

From source file:see.exceptions.SeeRuntimeException.java

/**
 * Extract see stacktrace from a throwable
 * @param throwable target throwable/*from   w w  w.j ava  2s. com*/
 * @return extracted trace
 */
private static List<TraceElement> getTrace(Throwable throwable) {
    List<Throwable> causalChain = getCausalChain(throwable);
    FluentIterable<PropagatedException> stack = from(causalChain).filter(PropagatedException.class);
    FluentIterable<Node<?>> nodes = stack.transform(new Function<PropagatedException, Node<?>>() {
        @Override
        public Node<?> apply(PropagatedException input) {
            return input.getFailedNode();
        }
    });
    FluentIterable<TraceElement> trace = nodes.filter(Tracing.class)
            .transform(new Function<Tracing, TraceElement>() {
                @Nullable
                @Override
                public TraceElement apply(Tracing input) {
                    Option<TraceElement> position = input.position();
                    if (position.isDefined())
                        return position.get();
                    else
                        return null;
                }
            }).filter(notNull());
    return trace.toList().reverse();
}

From source file:org.codeseed.common.config.PropertySources.java

/**
 * Returns a source which returns the first non-{@code null} value from a
 * series of sources./* w ww.j  a v a2 s  .  c o m*/
 *
 * @param sources
 *            the ordered sources to combine
 * @return property source that considers multiple sources
 */
public static PropertySource compose(Iterable<PropertySource> sources) {
    FluentIterable<PropertySource> s = FluentIterable.from(sources)
            .filter(Predicates.not(Predicates.equalTo(empty())));
    if (s.isEmpty()) {
        return empty();
    } else if (s.size() == 1) {
        return s.first().get();
    } else {
        return new CompositionSource(s.toList());
    }
}

From source file:org.raml.jaxrs.parser.analyzers.JerseyBridgeImpl.java

@Override
public List<RuntimeResource> runtimeResourcesFrom(FluentIterable<Resource> resources) {
    RuntimeResourceModel resourceModel = new RuntimeResourceModel(resources.toList());
    return resourceModel.getRuntimeResources();
}

From source file:org.sosy_lab.cpachecker.core.algorithm.bmc.LocationFormulaInvariant.java

@Override
public BooleanFormula getAssertion(Iterable<AbstractState> pReachedSet, FormulaManagerView pFMGR,
        PathFormulaManager pPFMGR) throws CPATransferException, InterruptedException {
    Iterable<AbstractState> locationStates = AbstractStates.filterLocations(pReachedSet, locations);
    FluentIterable<BooleanFormula> assertions = FluentIterable
            .from(BMCHelper.assertAt(locationStates, getFormula(pFMGR, pPFMGR), pFMGR));
    return pFMGR.getBooleanFormulaManager().and(assertions.toList());
}

From source file:org.sosy_lab.cpachecker.core.algorithm.bmc.AbstractLocationFormulaInvariant.java

@Override
public BooleanFormula getAssertion(Iterable<AbstractState> pReachedSet, FormulaManagerView pFMGR,
        PathFormulaManager pPFMGR, int pDefaultIndex) throws CPATransferException, InterruptedException {
    Iterable<AbstractState> locationStates = AbstractStates.filterLocations(pReachedSet, locations);
    FluentIterable<BooleanFormula> assertions = FluentIterable
            .from(BMCHelper.assertAt(locationStates, this, pFMGR, pPFMGR, pDefaultIndex));
    return pFMGR.getBooleanFormulaManager().and(assertions.toList());
}

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

@Override
public void scoreItems(ItemItemModel model, SparseVector userData, MutableSparseVector scores,
        NeighborhoodScorer scorer) {//www.  ja va  2  s  .co  m
    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.wordpress.growworkinghard.riverNe3.composite.LocalNode.java

/**
 * {@inheritDoc}/* ww w .ja v a2  s.c  o  m*/
 *
 * @see Component#preOrderTraversal()
 */
public synchronized List<Component> preOrderTraversal() {
    FluentIterable<Component> iterator = traverser.preOrderTraversal(this);
    return iterator.toList();
}

From source file:com.wordpress.growworkinghard.riverNe3.composite.LocalNode.java

/**
 * {@inheritDoc}/*ww  w . ja v  a  2 s. co m*/
 *
 * @see Component#postOrderTraversal()
 */
public synchronized List<Component> postOrderTraversal() {
    FluentIterable<Component> iterator = traverser.postOrderTraversal(this);
    return iterator.toList();
}

From source file:at.ac.tuwien.infosys.jcloudscale.vm.openstack.OpenStackWrapper.java

String lookupImageId(String imgName) {
    if (imgName == null || imgName.length() == 0)
        return null;

    FluentIterable<? extends Resource> allImages = images.list().concat();

    for (Resource img : allImages.toList())
        if (img.getName().equals(imgName))
            return img.getId();

    return null;/*from w w w. ja  v a2 s  . co  m*/
}

From source file:at.ac.tuwien.infosys.jcloudscale.vm.openstack.OpenStackWrapper.java

String lookupFlavorId(String flavorName) {
    if (flavorName == null || flavorName.length() == 0)
        return null;

    FluentIterable<? extends Resource> flavs = flavors.list().concat();

    for (Resource flavor : flavs.toList())
        if (flavor.getName().equalsIgnoreCase(flavorName))
            return flavor.getId();

    return null;/*from  w w  w.  j av a  2s .  c o m*/
}