-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preconditions for validating Duration instances #151
Comments
And yes, this is an ideal addition. The ThreeTen-Extra home for utilities is (If you can think of other validation-type things, then perhaps a |
We have other things in our public static Duration ofMicros(long micros) { }
public static Duration ofSeconds(double seconds) { } // for legacy reasons, we have a *lot* of `double seconds` floating around inside of Google...yuck
public static Duration of(long value, TimeUnit timeUnit) { } // this is obsolete as of JDK9
public static long toMicros(Duration duration) { }
public static long toMicrosSaturated(Duration duration) { }
public static long toMillisSaturated(Duration duration) { }
public static long toNanosSaturated(Duration duration) { }
public static double toSecondsAsDouble(Duration duration) { }
public static DiscreteDomain<Duration> domain() { } Makes Kotlin's extension-method feature look really appetizing, huh? Also, minor thing, but we (Java Core Libs team) are generally -1 on the |
So, |
Actually, those 5 methods are on a branch (not master), so we do have naming room. Would you want another class named |
We have the following precondition-style utilities inside of google:
Durations.checkNotNegative(duration)
Durations.checkPositive(duration)
They throw
IllegalArgumentException
if the duration is negative or not positive (respectively). Negative durations often are a bug, so it's nice to validateDuration
parameters like RPC timeouts or cache expirations. E.g.,Any chance we could find a home for these in threeten-extra?
The text was updated successfully, but these errors were encountered: