|
24 | 24 |
|
25 | 25 | import java.io.File; |
26 | 26 | import java.io.IOException; |
| 27 | +import java.util.Optional; |
27 | 28 | import java.util.concurrent.TimeUnit; |
28 | 29 | import java.util.regex.Matcher; |
29 | 30 | import java.util.regex.Pattern; |
@@ -150,7 +151,7 @@ public static long timeStringAs(String str, TimeUnit unit) { |
150 | 151 | } |
151 | 152 |
|
152 | 153 | // If suffix is valid use that, otherwise none was provided and use the default passed |
153 | | - return unit.convert(val, suffix != null ? TIME_SUFFIXES.get(suffix) : unit); |
| 154 | + return unit.convert(val, suffix != null ? Optional.ofNullable(TIME_SUFFIXES.get(suffix)).orElse(unit) : unit); |
154 | 155 | } catch (NumberFormatException e) { |
155 | 156 | String timeError = "Time must be specified as seconds (s), " + |
156 | 157 | "milliseconds (ms), microseconds (us), minutes (m or min), hour (h), or day (d). " + |
@@ -228,7 +229,7 @@ public static long byteStringAs(String str, ByteUnit unit) { |
228 | 229 | } |
229 | 230 |
|
230 | 231 | // If suffix is valid use that, otherwise none was provided and use the default passed |
231 | | - return unit.convertFrom(val, suffix != null ? BYTE_SUFFIXES.get(suffix) : unit); |
| 232 | + return unit.convertFrom(val, suffix != null ? Optional.ofNullable(BYTE_SUFFIXES.get(suffix)).orElse(unit) : unit); |
232 | 233 | } else if (fractionMatcher.matches()) { |
233 | 234 | throw new NumberFormatException("Fractional values are not supported. Input was: " + |
234 | 235 | fractionMatcher.group(1)); |
|
0 commit comments