record TimeSpan()

in sources/src/main/java/com/google/solutions/jitaccess/catalog/legacy/TimeSpan.java [30:63]


record TimeSpan(
  @NotNull Instant start,
  @NotNull Instant end
) implements Comparable<TimeSpan> {
  public TimeSpan {
    assert !start.isAfter(end);
  }

  public TimeSpan(@NotNull Instant start, @NotNull Duration duration) {
    this(start, start.plus(duration));
  }

  @Override
  public int compareTo(@NotNull TimeSpan o) {
    return (int)(this.end.getEpochSecond() - o.end.getEpochSecond());
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    TimeSpan timeSpan = (TimeSpan) o;
    return this.start.equals(timeSpan.start) && this.end.equals(timeSpan.end);
  }

  @Override
  public int hashCode() {
    return Objects.hash(this.start, this.end);
  }
}