List of usage examples for java.util Spliterators spliterator
public static Spliterator.OfDouble spliterator(PrimitiveIterator.OfDouble iterator, long size, int characteristics)
From source file:com.simiacryptus.mindseye.lang.Tensor.java
/** * Coord stream stream./*from www.j a va2s.c om*/ * * @param parallel the safe * @return the stream */ @Nonnull public Stream<Coordinate> coordStream(boolean parallel) { //ConcurrentHashSet<Object> distinctBuffer = new ConcurrentHashSet<>(); //assert distinctBuffer.add(coordinate.copy()) : String.format("Duplicate: %s in %s", coordinate, distinctBuffer); return StreamSupport.stream(Spliterators.spliterator(new Iterator<Coordinate>() { int cnt = 0; @Nonnull Coordinate coordinate = new Coordinate(); @Nonnull int[] val = new int[dimensions.length]; @Nonnull int[] safeCopy = new int[dimensions.length]; @Override public boolean hasNext() { return cnt < length(); } @Nonnull @Override public synchronized Coordinate next() { if (0 < cnt) { for (int i = 0; i < val.length; i++) { if (++val[i] >= dimensions[i]) { val[i] = 0; } else { break; } } } System.arraycopy(val, 0, safeCopy, 0, val.length); coordinate.setIndex(cnt++); coordinate.setCoords(safeCopy); return parallel ? coordinate.copy() : coordinate; } }, length(), Spliterator.ORDERED), parallel); }
From source file:org.briljantframework.array.AbstractBooleanArray.java
@Override public Stream<Boolean> stream() { return StreamSupport.stream(Spliterators.spliterator(new Iterator<Boolean>() { int current = 0; @Override//from www. j a va 2s .c o m public boolean hasNext() { return current < size(); } @Override public Boolean next() { return get(current++); } }, size(), Spliterator.SIZED), false); }
From source file:org.briljantframework.array.AbstractComplexArray.java
@Override public Stream<Complex> stream() { return StreamSupport.stream(Spliterators.spliterator(new Iterator<Complex>() { int current = 0; @Override/*w w w . j av a 2 s.c o m*/ public boolean hasNext() { return current < size(); } @Override public Complex next() { return get(current++); } }, size(), Spliterator.SIZED), false); }
From source file:org.briljantframework.array.AbstractDoubleArray.java
@Override public DoubleStream stream() { PrimitiveIterator.OfDouble ofDouble = new PrimitiveIterator.OfDouble() { public int current = 0; @Override//from w w w . j av a2s . c om public double nextDouble() { return get(current++); } @Override public boolean hasNext() { return current < size(); } }; Spliterator.OfDouble spliterator = Spliterators.spliterator(ofDouble, size(), Spliterator.SIZED); return StreamSupport.doubleStream(spliterator, false); }
From source file:org.briljantframework.array.AbstractIntArray.java
@Override public IntStream stream() { PrimitiveIterator.OfInt ofInt = new PrimitiveIterator.OfInt() { private int current = 0; @Override// w w w . j a v a 2s . c o m public int nextInt() { return get(current++); } @Override public boolean hasNext() { return current < size(); } }; Spliterator.OfInt spliterator = Spliterators.spliterator(ofInt, size(), Spliterator.SIZED); return StreamSupport.intStream(spliterator, false); }
From source file:org.briljantframework.array.AbstractLongArray.java
@Override public LongStream stream() { PrimitiveIterator.OfLong ofLong = new PrimitiveIterator.OfLong() { public int current = 0; @Override//from w w w. j a v a2 s.c o m public long nextLong() { return get(current++); } @Override public boolean hasNext() { return current < size(); } }; Spliterator.OfLong spliterator = Spliterators.spliterator(ofLong, size(), Spliterator.SIZED); return StreamSupport.longStream(spliterator, false); }
From source file:org.dice_research.topicmodeling.io.test.AbstractCorpusIOTest.java
public void writeCorpus() { OutputStream out = null;/* ww w . j a v a2 s .c om*/ try { if (writer != null) { out = new BufferedOutputStream(new FileOutputStream(testFile)); writer.writeCorpus(corpus, out); } else if (consumer != null) { StreamSupport.stream(Spliterators.spliterator(corpus.iterator(), corpus.getNumberOfDocuments(), Spliterator.DISTINCT & Spliterator.NONNULL), false).forEach(consumer); } else { Assert.fail("Test is misconfigured since writer==null and consumer==null."); } } catch (Exception e) { e.printStackTrace(); Assert.fail("Got an Exception: " + e.getLocalizedMessage()); } finally { IOUtils.closeQuietly(out); if ((consumer != null) && (consumer instanceof Closeable)) { IOUtils.closeQuietly((Closeable) consumer); } } }