Hello!
Small nitpick:
versionsMap.keySet().forEach(v -> {
Stream<String> names = versionsMap.get(v).stream().map(nm -> nm.name);
if (v == versionMajor) {
// add all entries of the version we are interested in
finalNames.addAll(names.collect(Collectors.toSet()));
} else {
// add resource entries found in lower versioned directories
finalNames.addAll(names.filter(nm -> nm.endsWith(".class") ? false
: true)
.collect(Collectors.toSet()));
}
});
I suggest to replace with
versionsMap.forEach((v, list) -> {
Stream<String> names = list.stream().map(nm -> nm.name);
if (v != versionMajor) {
names = names.filter(nm -> !nm.endsWith(".class"));
}
names.forEach(finalNames::add);
});
This is cleaner and somewhat faster to use Map.forEach as you don't need to
lookup every map entry.
Also I don't see why "nm -> nm.endsWith(".class") ? false : true" could be
better than
"nm -> !nm.endsWith(".class")". Probably a matter of style though.
Finally there's no need to collect into intermediate set just to add this
set into finalNames.
Instead you can drain the stream directly to finalNames via forEach.
Probably it should be explicitly noted in spec that the resulting stream is
unordered (or at least may
be unordered) as it's created from the Set.
With best regards,
Tagir Valeev
On Fri, Aug 26, 2016 at 2:30 AM, Steve Drach <[email protected]> wrote:
> Hi,
>
> Please review this changeset that adds a versionedStream method to JarFile.
>
> webrev: http://cr.openjdk.java.net/~sdrach/8163798/webrev.00/ <
> http://cr.openjdk.java.net/~sdrach/8163798/webrev.00/>
> issue: https://bugs.openjdk.java.net/browse/JDK-8163798 <
> https://bugs.openjdk.java.net/browse/JDK-8163798>
>
> Thanks
> Steve
>
>
>