RFR 8143964: JShell API: convert query responses to Stream instead of List/Collection
ShinyaYoshida
bitterfoxc at gmail.com
Tue Aug 9 23:37:50 UTC 2016
Hi, Robert,
I have 2 comments:
1895 Stream<Snippet> sns = at.hasOption("-all")
1896 ? state.snippets()
1897 : state.snippets().filter(this::mainActive);
1898 Iterator<Snippet> it = sns.iterator();
1899 while (it.hasNext()) {
1900 Snippet sn = it.next();
1901 writer.write(sn.source());
1902 writer.write("\n");
1903 }
You can use .collect method like following even if write throws IOE:
String sources = (at.hasOption("-all")
? state.snippets()
: state.snippets().filter(this::mainActive))
.map(Snippet::source)
.collect(Collectors.joining("\n"));
writer.write(sources);
In src/jdk.jshell/share/classes/jdk/jshell/Unit.java:
// Look through all methods for a method of the same name, with the
// same computed qualified parameter types
Status overwrittenStatus = null;- for (MethodSnippet
sn : state.methods()) {+ for (MethodSnippet sn :
state.methods().collect(toList())) {
if (sn != null && sn != msi && sn.status().isActive() &&
sn.name().equals(msi.name())) {
if (qpt.equals(sn.qualifiedParameterTypes())) {
overwrittenStatus = sn.status();
SnippetEvent se = new SnippetEvent(
sn, overwrittenStatus, OVERWRITTEN,
I'd like to avoid the collect(toList())+for-each because it need 2
pass for each data and kill the advantage of the streamification.
Can you write this using StreamAPI or iterator from the stream?
Regards,
shinyafox(Shinya Yoshida)
2016-08-09 15:15 GMT+09:00 Robert Field <robert.field at oracle.com>:
> Please review this deferred API review request.
> Basically changing List<*> return to Stream<*> return for seven methods:
> Stream<Snippet> snippets()
> Stream<VarSnippet> variables()
> Stream<MethodSnippet> methods()
> Stream<TypeDeclSnippet> types()
> Stream<ImportSnippet> imports()
> Stream<Diag> diagnostics(Snippet snippet)
> Stream<String> unresolvedDependencies(DeclarationSnippet snippet)
>
> Bug:
> https://bugs.openjdk.java.net/browse/JDK-8143964
>
> Webrev:
> http://cr.openjdk.java.net/~rfield/8143964v0.webrev/
>
> Spec:
> http://cr.openjdk.java.net/~rfield/8143964v0.jshellAPI/jdk/
> jshell/JShell.html
>
> Specdiff:
> http://cr.openjdk.java.net/~rfield/8143964v0.specdiff/jdk/js
> hell/JShell.html
>
> Thanks,
> Robert
>
>
More information about the kulla-dev
mailing list