List of usage examples for com.google.common.collect FluentIterable FluentIterable
protected FluentIterable()
From source file:com.github.rconner.anansi.Traversals.java
/** * Returns a pre-order iterable with <strong>NO</strong> cycle detection. This differs from {@link * TreeTraverser#preOrderTraversal(Object)} in that the created Iterators implement {@link PruningIterator} and * support the remove() operation if the Iterators produced by the argument adjacency TreeTraverser do. The root * vertex of the traversal cannot be removed. * * @param adjacency the adjacency function to use * @param <T> the vertex type// w w w .ja v a 2s . c o m * * @return a pre-order iterable with <strong>NO</strong> cycle detection. */ public static <T> FluentIterable<T> preOrder(final T root, final TreeTraverser<T> adjacency) { Preconditions.checkNotNull(adjacency); return new FluentIterable<T>() { @Override public Iterator<T> iterator() { return new PreOrderIterator<T>(root, Lazy.traverser(adjacency)); } }; }
From source file:org.sosy_lab.cpachecker.util.CFAUtils.java
/** * Return an {@link Iterable} that contains all entering edges of a given CFANode, * including the summary edge if the node as one. *//*ww w . jav a 2s .c om*/ public static FluentIterable<CFAEdge> allEnteringEdges(final CFANode node) { checkNotNull(node); return new FluentIterable<CFAEdge>() { @Override public Iterator<CFAEdge> iterator() { return new UnmodifiableIterator<CFAEdge>() { // the index of the next edge (-1 means the summary edge) private int i = (node.getEnteringSummaryEdge() != null) ? -1 : 0; @Override public boolean hasNext() { return i < node.getNumEnteringEdges(); } @Override public CFAEdge next() { if (i == -1) { i = 0; return node.getEnteringSummaryEdge(); } return node.getEnteringEdge(i++); } }; } }; }
From source file:ivorius.ivtoolkit.tools.Pairs.java
public static <L, R> Iterable<Pair<L, R>> of(final Iterable<L> left, final Iterable<R> right) { return new FluentIterable<Pair<L, R>>() { @Override//from w w w . ja v a 2 s . co m public Iterator<Pair<L, R>> iterator() { return new PairIterator<>(left.iterator(), right.iterator()); } }; }
From source file:com.googlecode.wmbutil.XPathIterator.java
private Iterable<MbElement> createMbIterable(final List<?> untypedList) { final Iterator<?> iterator = ImmutableList.copyOf(untypedList).iterator(); return new FluentIterable<MbElement>() { @Override/*from ww w . j ava 2s . c o m*/ public Iterator<MbElement> iterator() { return new AbstractIterator<MbElement>() { @Override protected MbElement computeNext() { while (iterator.hasNext()) { Object o = iterator.next(); if (o != null && o instanceof MbElement) { return (MbElement) o; } } return endOfData(); } }; } }; }
From source file:com.google.cloud.dataflow.sdk.util.ZipFiles.java
/** * Returns a {@link FluentIterable} of all the entries in the given zip file. *///from w w w . ja va 2 s . co m // unmodifiable Iterator<? extends ZipEntry> can be safely cast // to Iterator<ZipEntry> @SuppressWarnings("unchecked") static FluentIterable<ZipEntry> entries(final ZipFile file) { checkNotNull(file); return new FluentIterable<ZipEntry>() { @Override public Iterator<ZipEntry> iterator() { return (Iterator<ZipEntry>) Iterators.forEnumeration(file.entries()); } }; }
From source file:com.github.rconner.anansi.Traversals.java
/** * Returns a post-order iterable with <strong>NO</strong> cycle detection. If a cycle is present, some call to * next() will infinitely loop (most likely resulting in an OutOfMemoryError). This differs from {@link * TreeTraverser#postOrderTraversal(Object)} in that the created Iterators support the remove() operation if the * Iterators produced by the argument adjacency TreeTraverser do. The root vertex of the traversal cannot be * removed.//from w w w.ja v a 2 s. c o m * * @param adjacency the adjacency function to use * @param <T> the vertex type * * @return a post-order iterable with <strong>NO</strong> cycle detection. */ public static <T> FluentIterable<T> postOrder(final T root, final TreeTraverser<T> adjacency) { Preconditions.checkNotNull(adjacency); return new FluentIterable<T>() { @Override public Iterator<T> iterator() { return new PostOrderIterator<T>(root, Lazy.traverser(adjacency)); } }; }
From source file:org.sosy_lab.cpachecker.util.CFAUtils.java
/** * Return an {@link Iterable} that contains the entering edges of a given CFANode, * excluding the summary edge.//from ww w. jav a 2 s. c om */ public static FluentIterable<CFAEdge> enteringEdges(final CFANode node) { checkNotNull(node); return new FluentIterable<CFAEdge>() { @Override public Iterator<CFAEdge> iterator() { return new UnmodifiableIterator<CFAEdge>() { // the index of the next edge private int i = 0; @Override public boolean hasNext() { return i < node.getNumEnteringEdges(); } @Override public CFAEdge next() { return node.getEnteringEdge(i++); } }; } }; }
From source file:org.jclouds.collect.PagedIterable.java
/** * Combines all the pages into a single unmodifiable iterable. ex. * //from w w w . j a v a 2 s . c om * <pre> * FluentIterable<StorageMetadata> blobs = blobstore.list(...).concat(); * for (StorageMetadata blob : blobs) { * process(blob); * } * </pre> * * @see Iterators#concat */ public FluentIterable<E> concat() { final Iterator<IterableWithMarker<E>> iterator = iterator(); final UnmodifiableIterator<Iterator<E>> unmodifiable = new UnmodifiableIterator<Iterator<E>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Iterator<E> next() { return iterator.next().iterator(); } }; return new FluentIterable<E>() { @Override public Iterator<E> iterator() { return Iterators.concat(unmodifiable); } }; }
From source file:com.github.rconner.anansi.Traversals.java
/** * Returns a breadth-first iterable with <strong>NO</strong> cycle detection. This differs from {@link * TreeTraverser#breadthFirstTraversal(Object)} in that the created Iterators implement {@link PruningIterator} and * support the remove() operation if the Iterators produced by the argument adjacency TreeTraverser do. The root * vertex of the traversal cannot be removed. * * @param adjacency the adjacency function to use * @param <T> the vertex type// w w w . j a v a 2 s . c o m * * @return a breadth-first iterable with <strong>NO</strong> cycle detection. */ public static <T> FluentIterable<T> breadthFirst(final T root, final TreeTraverser<T> adjacency) { Preconditions.checkNotNull(adjacency); return new FluentIterable<T>() { @Override public Iterator<T> iterator() { return new BreadthFirstIterator<T>(root, Lazy.traverser(adjacency)); } }; }
From source file:org.sosy_lab.cpachecker.util.CFAUtils.java
/** * Return an {@link Iterable} that contains all leaving edges of a given CFANode, * including the summary edge if the node as one. *//*w ww .j a va 2s .c o m*/ public static FluentIterable<CFAEdge> allLeavingEdges(final CFANode node) { checkNotNull(node); return new FluentIterable<CFAEdge>() { @Override public Iterator<CFAEdge> iterator() { return new UnmodifiableIterator<CFAEdge>() { // the index of the next edge (-1 means the summary edge) private int i = (node.getLeavingSummaryEdge() != null) ? -1 : 0; @Override public boolean hasNext() { return i < node.getNumLeavingEdges(); } @Override public CFAEdge next() { if (i == -1) { i = 0; return node.getLeavingSummaryEdge(); } return node.getLeavingEdge(i++); } }; } }; }