RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v7]
Roger Riggs
rriggs at openjdk.java.net
Tue May 3 16:45:29 UTC 2022
On Tue, 3 May 2022 16:28:14 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> src/java.base/share/classes/java/nio/file/Path.java line 328:
>>
>>> 326: String thisExtension = getExtension().orElse(null);
>>> 327: if (thisExtension == null)
>>> 328: return Optional.empty();
>>
>> Maybe keep around the Optional holding the extension to return if it is empty or matches; saving creating a new one.
>
>> Maybe keep around the Optional holding the extension to return if it is empty or matches; saving creating a new one.
>
> I don't understand this comment. I think that this could be done in the implementation classes but I do not see how to do it here.
Something like:
default Optional<String> hasExtension(String ext, String... extensions) {
requireNonNull(ext);
Optional<String> extension = getExtension();
String thisExtension = null;
if (extension.isEmpty() || (thisExtension = extension.get()).equals(ext))
return extension;
...
-------------
PR: https://git.openjdk.java.net/jdk/pull/8066
More information about the nio-dev
mailing list