Pretty code; though the part about creating an array to create a BitSet
is a bit non-obvious.
But how much garbage does it create and extra runtime doing all that
fancy stuff.
Now if BitSet had a constructor from the bits in a long...
Roger
On 6/29/2017 3:25 AM, Langer, Christoph wrote:
Looks good.
Best regards
Christoph
-----Original Message-----
From: core-libs-dev [mailto:core-libs-dev-boun...@openjdk.java.net] On
Behalf Of Brian Burkhalter
Sent: Mittwoch, 28. Juni 2017 19:49
To: core-libs-dev <core-libs-dev@openjdk.java.net>
Subject: Re: JDK 10 RFR of 8182710: File.listRoots() always returns the root of
CD drive
I rather like that. How about this (without "ds")?
public File[] listRoots() {
return BitSet
.valueOf(new long[] {listRoots0()})
.stream()
.mapToObj(i -> new File((char)('A' + i) + ":" + slash))
.filter(f -> access(f.getPath()) && f.exists())
.toArray(File[]::new);
}
Thanks,
Brian
On Jun 27, 2017, at 10:54 PM, Tagir Valeev <amae...@gmail.com> wrote:
Just an alternative which looks more readable to me (no explicit bit
twiddling):
- int ds = listRoots0();
- return IntStream
- .range(0, 26)
- .filter(i -> ((ds >> i) & 1) != 0)
+ long[] ds = {listRoots0()};
+ return BitSet
+ .valueOf(ds)
+ .stream()
Probably a matter of taste though.