When providing "/" as the path to use with saveTo() we end up with a final location that contains /// on it.
Solution
Use Optional to make sure we fall back to absent when providing a null or root path (using filterNot).
Then, when we compile the final path, we map to path + '/' or an empty string if absent.
Rational for other changes
Removed the use of StringBuilder as the compiler replaces + with it's own StringBuilder and since we are not looping (only case where there is a performance gain) it removes noice.
Use File.separator instead of File.separatorCharbecause it's shorter and the effective code of append for char and String is the same with the diference of calling length() on the string. Minimal impact, with easier readability.
Added a couple of basic Optional operators. Why not.
Problem
When providing
"/"
as the path to use withsaveTo()
we end up with a final location that contains///
on it.Solution
Use
Optional
to make sure we fall back toabsent
when providing a null or root path (usingfilterNot
).Then, when we compile the final path, we map to
path + '/'
or an empty string if absent.Rational for other changes
StringBuilder
as the compiler replaces+
with it's ownStringBuilder
and since we are not looping (only case where there is a performance gain) it removes noice.File.separator
instead ofFile.separatorChar
because it's shorter and the effective code ofappend
for char and String is the same with the diference of callinglength()
on the string. Minimal impact, with easier readability.Optional
operators. Why not.