Merge pull request #11362 from izeye:assert-state-supplier

* pr/11362:
  Use Supplier version of Assert.state()
pull/11362/merge
Stephane Nicoll 7 years ago
commit 8f793eaf33

@ -90,7 +90,7 @@ class DurationConverter implements GenericConverter {
return Duration.parse(source); return Duration.parse(source);
} }
Matcher matcher = SIMPLE.matcher(source); Matcher matcher = SIMPLE.matcher(source);
Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); Assert.state(matcher.matches(), () -> "'" + source + "' is not a valid duration");
long amount = Long.parseLong(matcher.group(1)); long amount = Long.parseLong(matcher.group(1));
ChronoUnit unit = getUnit(matcher.group(2), defaultUnit); ChronoUnit unit = getUnit(matcher.group(2), defaultUnit);
return Duration.of(amount, unit); return Duration.of(amount, unit);
@ -106,7 +106,7 @@ class DurationConverter implements GenericConverter {
return (defaultUnit != null ? defaultUnit.value() : ChronoUnit.MILLIS); return (defaultUnit != null ? defaultUnit.value() : ChronoUnit.MILLIS);
} }
ChronoUnit unit = UNITS.get(value.toLowerCase()); ChronoUnit unit = UNITS.get(value.toLowerCase());
Assert.state(unit != null, "Unknown unit '" + value + "'"); Assert.state(unit != null, () -> "Unknown unit '" + value + "'");
return unit; return unit;
} }

@ -51,9 +51,13 @@ class SessionStoreDirectory {
if (!dir.exists() && mkdirs) { if (!dir.exists() && mkdirs) {
dir.mkdirs(); dir.mkdirs();
} }
Assert.state(!mkdirs || dir.exists(), "Session dir " + dir + " does not exist"); assertDirectory(mkdirs, dir);
Assert.state(!dir.isFile(), "Session dir " + dir + " points to a file");
return dir; return dir;
} }
private void assertDirectory(boolean mkdirs, File dir) {
Assert.state(!mkdirs || dir.exists(), () -> "Session dir " + dir + " does not exist");
Assert.state(!dir.isFile(), () -> "Session dir " + dir + " points to a file");
}
} }

Loading…
Cancel
Save