本文整理匯總了Java中java.util.stream.Stream.forEachOrdered方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.forEachOrdered方法的具體用法?Java Stream.forEachOrdered怎麽用?Java Stream.forEachOrdered使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.forEachOrdered方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cmdList
import java.util.stream.Stream; //導入方法依賴的package包/類
private boolean cmdList(String arg) {
if (arg.length() >= 2 && "-history".startsWith(arg)) {
return cmdHistory();
}
Stream<Snippet> stream = argsOptionsToSnippets(state::snippets,
this::mainActive, arg, "/list");
if (stream == null) {
return false;
}
// prevent double newline on empty list
boolean[] hasOutput = new boolean[1];
stream.forEachOrdered(sn -> {
if (!hasOutput[0]) {
cmdout.println();
hasOutput[0] = true;
}
cmdout.printf("%4s : %s\n", sn.id(), sn.source().replace("\n", "\n "));
});
return true;
}
示例2: cmdMethods
import java.util.stream.Stream; //導入方法依賴的package包/類
private boolean cmdMethods(String arg) {
Stream<MethodSnippet> stream = argsOptionsToSnippets(this::allMethodSnippets,
this::isActive, arg, "/methods");
if (stream == null) {
return false;
}
stream.forEachOrdered(meth -> {
String sig = meth.signature();
int i = sig.lastIndexOf(")") + 1;
if (i <= 0) {
hard(" %s", meth.name());
} else {
hard(" %s %s%s", sig.substring(i), meth.name(), sig.substring(0, i));
}
printSnippetStatus(meth, true);
});
return true;
}
示例3: read
import java.util.stream.Stream; //導入方法依賴的package包/類
static RunManifest read(Path manifestPath) throws IOException {
final Stream<String> lines = Files.lines(manifestPath);
final RunManifestBuilder builder = new RunManifestBuilder();
lines.forEachOrdered(line -> {
if (line.trim().isEmpty()) {
return;
}
final String[] split = line.trim().split(" ", 2);
if (split.length != 2) {
throw new IllegalArgumentException("Malformed manifest line '" + line + "'");
}
switch (split[0].charAt(0)) {
case LAMBDA:
builder.continuation(split[1]);
break;
case CLASSPATH_FILE:
builder.addClassPathFile(split[1]);
break;
case REGULAR_FILE:
builder.addFile(split[1]);
break;
default:
LOG.warn("Unrecognized manifest entry '" + line + "'");
}
});
return builder.build();
}
示例4: cmdVars
import java.util.stream.Stream; //導入方法依賴的package包/類
private boolean cmdVars(String arg) {
Stream<VarSnippet> stream = argsOptionsToSnippets(this::allVarSnippets,
this::isActive, arg, "/vars");
if (stream == null) {
return false;
}
stream.forEachOrdered(vk ->
{
String val = state.status(vk) == Status.VALID
? state.varValue(vk)
: getResourceString("jshell.msg.vars.not.active");
hard(" %s %s = %s", vk.typeName(), vk.name(), val);
});
return true;
}
示例5: cmdMethods
import java.util.stream.Stream; //導入方法依賴的package包/類
private boolean cmdMethods(String arg) {
Stream<MethodSnippet> stream = argsOptionsToSnippets(this::allMethodSnippets,
this::isActive, arg, "/methods");
if (stream == null) {
return false;
}
stream.forEachOrdered(mk
-> hard(" %s %s", mk.name(), mk.signature())
);
return true;
}
示例6: flatten
import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<String> flatten(String delimiter, Stream<Stream<String>> bumpy) {
final List<String> flat = new ArrayList<>();
bumpy.forEachOrdered(lines -> {
if(!flat.isEmpty()) {
final int last = flat.size() - 1;
flat.set(last, flat.get(last) + delimiter);
}
lines.forEachOrdered(flat::add);
});
return flat.stream();
}
示例7: reduce
import java.util.stream.Stream; //導入方法依賴的package包/類
public static <T, R> R reduce(Stream<T> stream, R identity, BiFunction<R, T, R> accumulator) {
class Result { R v; }
Result result = new Result();
result.v = identity;
stream.forEachOrdered(t -> result.v = accumulator.apply(result.v, t));
return result.v;
}
示例8: cmdVars
import java.util.stream.Stream; //導入方法依賴的package包/類
private boolean cmdVars(String arg) {
Stream<VarSnippet> stream = argsOptionsToSnippets(this::allVarSnippets,
this::isActive, arg, "/vars");
if (stream == null) {
return false;
}
stream.forEachOrdered(vk ->
{
String val = state.status(vk) == Status.VALID
? feedback.truncateVarValue(state.varValue(vk))
: getResourceString("jshell.msg.vars.not.active");
hard(" %s %s = %s", vk.typeName(), vk.name(), val);
});
return true;
}
示例9: forEachWithIndex
import java.util.stream.Stream; //導入方法依賴的package包/類
public static <T> void forEachWithIndex(Stream<T> stream, IndexedConsumer<T> consumer) {
final Counter index = new Counter();
stream.forEachOrdered(t -> consumer.accept(t, index.next()));
}