List of usage examples for java.lang Iterable Iterable
Iterable
From source file:org.novelang.common.tree.ImmutableTree.java
/** * Convenience method (not a part of {@link Tree} contract). * * @return a non-null iterable returning non-null iterators, which iterate on non-null objects. *//*from w w w. java 2s .c o m*/ public Iterable<? extends T> getChildren() { return new Iterable() { @Override public Iterator<T> iterator() { return new ChildrenIterator(); } }; }
From source file:org.jsonman.node.MapNode.java
public Iterable<Pair<String, Node>> getChildrenWithName() { return new Iterable<Pair<String, Node>>() { @Override/*from w w w. java 2 s . co m*/ public Iterator<Pair<String, Node>> iterator() { return new Iterator<Pair<String, Node>>() { @Override public boolean hasNext() { return entries.hasNext(); } @Override public Pair<String, Node> next() { Map.Entry<String, Object> e = entries.next(); return Pair.of(e.getKey(), NodeFactory.create(e.getValue())); } @Override public void remove() { entries.remove(); } private Iterator<Map.Entry<String, Object>> entries = map.entrySet().iterator(); }; } }; }
From source file:com.steffi.model.Cell.java
public Iterable<String> getAttributeKeys() { return new Iterable<String>() { @SuppressWarnings("unchecked") @Override/*from ww w . j a v a 2s. c o m*/ public Iterator<String> iterator() { if (attributes != null) { final List<String> keys = new ArrayList<String>(); final SteffiGraph graph = SteffiGraph.getInstance(); attributes.forEachKey(new TIntProcedure() { @Override public boolean execute(int keyIndex) { keys.add(graph.getItemName(keyIndex)); return true; } }); return keys.iterator(); } else return IteratorUtils.emptyIterator(); } }; }
From source file:hudson.matrix.AxisList.java
/** * List up all the possible combinations of this list. *///from www . j a va2 s. co m public Iterable<Combination> list() { final int[] base = new int[size()]; if (base.length == 0) return Collections.<Combination>emptyList(); int b = 1; for (int i = size() - 1; i >= 0; i--) { base[i] = b; b *= get(i).size(); } final int total = b; // number of total combinations return new Iterable<Combination>() { public Iterator<Combination> iterator() { return new Iterator<Combination>() { private int counter = 0; public boolean hasNext() { return counter < total; } public Combination next() { String[] data = new String[size()]; int x = counter++; for (int i = 0; i < data.length; i++) { data[i] = get(i).value(x / base[i]); x %= base[i]; } assert x == 0; return new Combination(AxisList.this, data); } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:org.grouplens.lenskit.vectors.Vectors.java
/** * Iterate over the intersection of two vectors - they keys they have in common. * @param v1 The first vector./* w w w . ja v a 2s . c o m*/ * @param v2 The second vector. * @return An iterator over the common pairs. This iterator will never contain null entries. */ public static Iterable<ImmutablePair<VectorEntry, VectorEntry>> intersect(final SparseVector v1, final SparseVector v2) { return new Iterable<ImmutablePair<VectorEntry, VectorEntry>>() { @Override public Iterator<ImmutablePair<VectorEntry, VectorEntry>> iterator() { return Iterators.transform(new FastIntersectIterImpl(v1, v2), IMMUTABLE_PAIR_COPY); } }; }
From source file:uk.gov.gchq.gaffer.function.MultiFilterFunction.java
protected Iterable<Boolean> executeFilters(final Object[] input) { return new Iterable<Boolean>() { @Override//from ww w . j a va 2 s.c om public Iterator<Boolean> iterator() { final Iterator<ConsumerFunctionContext<Integer, FilterFunction>> funcItr = getFunctions() .iterator(); return new Iterator<Boolean>() { @Override public boolean hasNext() { return funcItr.hasNext(); } @Override public Boolean next() { return executeFunction(input, funcItr.next()); } @Override public void remove() { throw new UnsupportedOperationException("Cannot remove from items from this iterator"); } private boolean executeFunction(final Object[] input, final ConsumerFunctionContext<Integer, FilterFunction> function) { final Object[] selection; if (null == function.getSelection()) { selection = input; } else { selection = function.select(new ArrayTuple(input)); } return function.getFunction().isValid(selection); } }; } }; }
From source file:org.vafer.jdependency.Clazzpath.java
public ClazzpathUnit addClazzpathUnit(final File pFile, final String pId) throws IOException { if (pFile.isFile()) { return addClazzpathUnit(new FileInputStream(pFile), pId); }/*from w ww.ja v a 2 s . c o m*/ if (pFile.isDirectory()) { final String prefix = FilenameUtils.separatorsToUnix(FilenameUtils .normalize(new StringBuilder(pFile.getAbsolutePath()).append(File.separatorChar).toString())); final boolean recursive = true; @SuppressWarnings("unchecked") final Iterator<File> files = FileUtils.iterateFiles(pFile, new String[] { "class" }, recursive); return addClazzpathUnit(new Iterable<Resource>() { public Iterator<Resource> iterator() { return new Iterator<Clazzpath.Resource>() { public boolean hasNext() { return files.hasNext(); } public Resource next() { final File file = files.next(); return new Resource(file.getAbsolutePath().substring(prefix.length())) { @Override InputStream getInputStream() throws IOException { return new FileInputStream(file); } }; } public void remove() { throw new UnsupportedOperationException(); } }; } }, pId, true); } throw new IllegalArgumentException(); }
From source file:com.clxcommunications.xms.PagedFetcher.java
/** * Returns an iterable object that traverses all fetched elements across all * associated pages. This is done by iterating over fetched pages and, when * necessary, fetching new pages./*from w w w . j av a2 s.com*/ * <p> * Since multiple fetches may be necessary to iterate over all batches it is * possible that concurrent changes on the server will cause the same batch * to be iterated over twice. * <p> * ALso, since the returned iterator will perform asynchronous network * traffic it is possible that the {@link Iterator#hasNext()} and * {@link Iterator#next()} methods throws {@link RuntimeException} having as * cause an {@link ExecutionException}. * * @return a non-null iterable * @throws RuntimeException * if the background page fetching failed */ @Nonnull public Iterable<T> elements() { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<Page<T>> pageIt = pages().iterator(); return new Iterator<T>() { Iterator<T> pageElemIt = pageIt.next().iterator(); @Override public boolean hasNext() { if (!pageElemIt.hasNext()) { if (!pageIt.hasNext()) { return false; } else { pageElemIt = pageIt.next().iterator(); return pageElemIt.hasNext(); } } else { return true; } } @Override public T next() { if (!pageElemIt.hasNext()) { pageElemIt = pageIt.next().iterator(); } return pageElemIt.next(); } }; } }; }
From source file:it.unibo.alchemist.language.protelis.datatype.FieldTroveMapImpl.java
@Override public Iterable<Object> valIterator() { return new Iterable<Object>() { @Override/* w ww.j av a 2 s . com*/ public Iterator<Object> iterator() { List<Object> list = new ArrayList<>(); for (Pair<DeviceUID, Object> e : fld.valueCollection()) { list.add(e.getSecond()); } return list.iterator(); } }; }
From source file:de.tudarmstadt.ukp.dkpro.core.performance.PerformanceTestUtil.java
public static <T> Iterable<T> repeat(final T aObject, final int aCount) { return new Iterable<T>() { @Override//www . j ava 2 s .c o m public Iterator<T> iterator() { return new Iterator<T>() { private int i = 0; @Override public boolean hasNext() { return i < aCount; } @Override public T next() { i++; return aObject; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }