本文整理匯總了Java中java.util.stream.Stream.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.iterator方法的具體用法?Java Stream.iterator怎麽用?Java Stream.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.iterator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getBounds
import java.util.stream.Stream; //導入方法依賴的package包/類
public static Rectangle getBounds(Stream<Node> nodes) {
final Iterator<Node> i = nodes.iterator();
if (i.hasNext()) {
float xMin = Float.MAX_VALUE;
float xMax = Float.MIN_VALUE;
float yMin = Float.MAX_VALUE;
float yMax = Float.MIN_VALUE;
while (i.hasNext()) {
final Node n = i.next();
xMin = Math.min(xMin, n.getX());
yMin = Math.min(yMin, n.getY());
xMax = Math.max(xMax, n.getX() + n.getWidth());
yMax = Math.max(yMax, n.getY() + n.getHeight());
}
return new Rectangle(xMin, yMin, xMax - xMin, yMax - yMin);
} else
return Rectangle.EMPTY;
}
示例2: intersperse
import java.util.stream.Stream; //導入方法依賴的package包/類
public static <T> Stream<T> intersperse(Stream<T> s, T e) {
final Iterator<T> inner = s.iterator();
final AtomicBoolean returnE = new AtomicBoolean(false);
final Iterator<T> it = new Iterator<T>() {
@Override
public boolean hasNext() {
return inner.hasNext();
}
@Override
public T next() {
final T ret = returnE.get() ? e : inner.next();
returnE.set(!returnE.get());
return ret;
}
};
return StreamSupport.stream(
Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED),
false);
}
示例3: listResources
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Method to obtain the paths to all files in a directory specified
* by a path. This should work in an ordinary file system
* as well as a (possibly nested) JAR file.
*
* @param path path to a directory (may be contained in a JAR file)
* @return a sequence of paths or {@code null} if the specified path
* is not a directory
*/
public static Path[] listResources(Path path) {
// with help from http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-file, #10
if (!Files.isDirectory(path)) {
throw new IllegalArgumentException("path is not a directory: " + path.toString());
}
List<Path> pathList = new ArrayList<Path>();
Stream<Path> walk = null;
try {
walk = Files.walk(path, 1);
} catch (IOException e) {
e.printStackTrace();
}
for (Iterator<Path> it = walk.iterator(); it.hasNext();){
Path p = it.next();
if (Files.isRegularFile(p) && Files.isReadable(p)) {
pathList.add(p);
}
}
walk.close();
return pathList.toArray(new Path[0]);
}
示例4: sequence
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Variation of {@link Reader#sequence(IList)} for {@link Stream}.
* @param sfu the stream of {@code F} values
* @param <T> the error type
* @param <U> the return type of the {@code F}s in the stream
* @return a {@code F} which wraps an {@link Stream} of values
*/
static <T, U> Reader<T, Stream<U>> sequence(Stream<Reader<T, U>> sfu) {
final Iterator<Reader<T, U>> iter = sfu.iterator();
Reader<T, IList<U>> flu = pure(IList.nil());
while (iter.hasNext()) {
final Reader<T, U> fu = iter.next();
flu = fu.app(flu.map(lt -> lt::add));
}
return flu.map(IList::stream);
}
示例5: doLayoutSubtrees
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Lay out given subtrees side by side.
*/
private void doLayoutSubtrees(@SuppressWarnings("hiding") Stream<Node> nodes) {
float px = 0;
final Iterator<Node> i = nodes.iterator();
while (i.hasNext()) {
final Node n = i.next();
doLayoutSubtree(n);
final Rectangle b = GraphUtils.getBounds(getTree(n));
moveTree(n, px - b.x, 0);
px += b.width + GAP_X;
}
}
示例6: getMultipleChoiceImageResources
import java.util.stream.Stream; //導入方法依賴的package包/類
public List<String> getMultipleChoiceImageResources(){
final URI uri;
final ArrayList<String> resourceList;
final PathMatcher matcher;
final Path myPath;
final Stream<Path> walk;
resourceList = new ArrayList<String>();
matcher = FileSystems.getDefault().getPathMatcher(GlobFactoryHelper.getCaseInsensitiveExtensionGlob("PNG","JPG"));
try {
uri = ResourceHelper.getResource(isFromGameResourceInput(), gamePath, setPath).toURI();
myPath= Paths.get(uri);
walk = Files.walk(myPath, 3, FileVisitOption.FOLLOW_LINKS);
for (Iterator<Path> it = walk.iterator(); it.hasNext();){
Path currentPath =it.next();
if (matcher.matches(currentPath))
{ resourceList.add(currentPath.toString().substring(currentPath.toString().indexOf("game-resources-input/")));
}
}
} catch (IOException | URISyntaxException e1) {
log.error("Fail",e1);
}
return resourceList;
/* final String pattern;
final String resourcePath;
final List<String> resourceList;
pattern=GlobFactoryHelper.getCaseInsensitiveExtensionGlob("PNG","JPG");
resourcePath= ResourceHelper.getResourceAddress( isFromGameResourceInput(),getGamePath(), getSetPath());
resourceList= ImageFilesLoaderHelper.getImageResources(pattern, resourcePath, 3, log);
return resourceList;
*/
}
示例7: sequence
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Variation of {@link State#sequence(IList)} for {@link Stream}.
* @param sst the stream of {@code State} values
* @param <S> the state type
* @param <T> the result type of the {@code State}s in the stream
* @return a {@code State} which wraps an {@link Stream} of values
*/
static <S, T> State<S, Stream<T>> sequence(Stream<State<S, T>> sst) {
final Iterator<State<S, T>> iter = sst.iterator();
State<S, IList<T>> slt = pure(IList.nil());
while (iter.hasNext()) {
final State<S, T> st = iter.next();
slt = st.apply(slt.map(lt -> lt::add));
}
return slt.map(IList::stream);
}
示例8: sequence
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Variation of {@link StateR#sequence(IList)} for {@link Stream}.
* @param sst the stream of {@code StateR} values
* @param <S> the state type
* @param <T> the result type of the {@code StateR}s in the stream
* @return a {@code StateR} which wraps an {@link Stream} of values
*/
static <S, T> StateR<S, Stream<T>> sequence(Stream<StateR<S, T>> sst) {
final Iterator<StateR<S, T>> iter = sst.iterator();
StateR<S, IList<T>> slt = pure(IList.nil());
while (iter.hasNext()) {
final StateR<S, T> st = iter.next();
slt = st.apply(slt.map(lt -> lt::add));
}
return slt.map(IList::stream);
}
示例9: testInterlacedRead
import java.util.stream.Stream; //導入方法依賴的package包/類
public void testInterlacedRead() throws IOException {
MockLineReader r = new MockLineReader(10);
BufferedReader br = new BufferedReader(r);
char[] buf = new char[5];
Stream<String> s = br.lines();
Iterator<String> it = s.iterator();
br.read(buf);
assertEquals(new String(buf), "Line ");
assertEquals(it.next(), "1");
try {
s.iterator().next();
fail("Should failed on second attempt to get iterator from s");
} catch (IllegalStateException ise) {}
br.read(buf, 0, 2);
assertEquals(new String(buf, 0, 2), "Li");
// Get stream again should continue from where left
// Only read remaining of the line
br.lines().limit(1L).forEach(line -> assertEquals(line, "ne 2"));
br.read(buf, 0, 2);
assertEquals(new String(buf, 0, 2), "Li");
br.read(buf, 0, 2);
assertEquals(new String(buf, 0, 2), "ne");
assertEquals(it.next(), " 3");
// Line 4
br.readLine();
// interator pick
assertEquals(it.next(), "Line 5");
// Another stream instantiated by lines()
AtomicInteger line_no = new AtomicInteger(6);
br.lines().forEach(l -> assertEquals(l, "Line " + line_no.getAndIncrement()));
// Read after EOL
assertFalse(it.hasNext());
}
示例10: asIterable
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Returns a new Iterable wrapper of the stream
* @param stream the stream to wrap
* @param <T> the entity type
* @return the newly created iterable
*/
public static <T> Iterable<T> asIterable(Stream<T> stream) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return stream.iterator();
}
};
}
示例11: tryScalarXMap
import java.util.stream.Stream; //導入方法依賴的package包/類
public static <T, R> boolean tryScalarXMap(FolyamPublisher<T> source, FolyamSubscriber<? super R> s, CheckedFunction<? super T, ? extends Stream<? extends R>> mapper) {
if (source instanceof FusedDynamicSource) {
FusedDynamicSource<T> f = (FusedDynamicSource<T>) source;
Stream<? extends R> e = null;
Iterator<? extends R> it = null;
boolean hasValue = false;
try {
T v = f.value();
if (v != null) {
e = Objects.requireNonNull(mapper.apply(v), "The mapper returned a null Stream");
it = e.iterator();
hasValue = it.hasNext();
}
} catch (Throwable ex) {
FolyamPlugins.handleFatal(ex);
EmptySubscription.error(s, ex);
return true;
}
if (e == null) {
EmptySubscription.complete(s);
return true;
}
if (hasValue) {
if (s instanceof ConditionalSubscriber) {
s.onSubscribe(new FolyamStream.StreamConditionalSubscription<>((ConditionalSubscriber<? super R>)s, it, e));
} else {
s.onSubscribe(new FolyamStream.StreamSubscription<>(s, it, e));
}
} else {
EmptySubscription.complete(s);
}
return true;
}
return false;
}
示例12: chunkBy
import java.util.stream.Stream; //導入方法依賴的package包/類
private static <T> Stream<Stream<T>> chunkBy(int chunkSize, Stream<T> stream) {
Iterator<T> elements = stream.iterator();
Stream.Builder<Stream<T>> b1 = Stream.builder();
while (elements.hasNext()) {
Stream.Builder<T> b2 = Stream.builder();
for (int i = 0; i < chunkSize && elements.hasNext(); i++) {
b2.accept(elements.next());
}
b1.accept(b2.build());
}
return b1.build();
}
示例13: assertValue
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
void assertValue(List<T> value, Supplier<Stream<T>> source, boolean ordered)
throws ReflectiveOperationException {
if (!List.class.isAssignableFrom(value.getClass()))
fail(String.format("Class mismatch in ListAssertion: %s", value.getClass()));
Stream<T> stream = source.get();
List<T> result = new ArrayList<>();
for (Iterator<T> it = stream.iterator(); it.hasNext(); ) // avoid capturing result::add
result.add(it.next());
if (StreamOpFlagTestHelper.isStreamOrdered(stream) && ordered)
assertContents(value, result);
else
assertContentsUnordered(value, result);
}
示例14: identityMatch
import java.util.stream.Stream; //導入方法依賴的package包/類
private <T extends Snippet> void identityMatch(Stream<T> got, T expected) {
Iterator<T> it = got.iterator();
assertTrue(it.hasNext(), "expected exactly one");
assertTrue(expected == it.next(), "Identity must not change");
assertFalse(it.hasNext(), "expected exactly one");
}
示例15: forEachThrows
import java.util.stream.Stream; //導入方法依賴的package包/類
public static <T, E extends Throwable> void forEachThrows(Stream<T> stream, ThrowingConsumer<? super T, E> consumer) throws E {
for(final Iterator<T> it = stream.iterator(); it.hasNext();) {
consumer.acceptThrows(it.next());
}
}