Skip to content

Preconditions for validating Duration instances #151

@kluever

Description

@kluever

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 validate Duration parameters like RPC timeouts or cache expirations. E.g.,

public final class Frobber {
  private final Duration timeout;
  public Frobber(Duration timeout) {
    this.timeout = checkPositive(timeout);
  }
}

Any chance we could find a home for these in threeten-extra?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions