TimeRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$).*
as compiler argument.
Table of contents
- ClockInstant
- UtcConstant
- LocalDateOfInstant
- LocalDateTimeOfInstant
- LocalTimeOfInstant
- OffsetDateTimeOfInstant
- InstantAtOffset
- OffsetTimeOfInstant
- InstantAtZone
- UtcClock
- EpochInstant
- InstantIsBefore
- InstantIsAfter
- LocalTimeMin
- LocalDateAtStartOfDay
- ChronoLocalDateIsBefore
- ChronoLocalDateIsAfter
- ChronoLocalDateTimeIsBefore
- ChronoLocalDateTimeIsAfter
- ChronoZonedDateTimeIsBefore
- ChronoZonedDateTimeIsAfter
- OffsetDateTimeIsAfter
- OffsetDateTimeIsBefore
- ZeroDuration
- DurationOfDays
- DurationOfHours
- DurationOfMillis
- DurationOfMinutes
- DurationOfNanos
- DurationOfSeconds
- DurationBetweenInstants
- DurationBetweenOffsetDateTimes
- DurationIsZero
- ZeroPeriod
ClockInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ClockInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ClockInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Instant testClockInstant() {
- return Instant.now(Clock.systemUTC());
+ return Clock.systemUTC().instant();
}
UtcConstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("UtcConstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$UtcConstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<ZoneId> testUtcConstant() {
return ImmutableSet.of(
- ZoneId.of("GMT"),
- ZoneId.of("UTC"),
- ZoneId.of("+0"),
- ZoneId.of("-0"),
ZoneOffset.UTC,
- ZoneId.from(ZoneOffset.UTC));
+ ZoneOffset.UTC,
+ ZoneOffset.UTC,
+ ZoneOffset.UTC,
+ ZoneOffset.UTC,
+ ZoneOffset.UTC);
}
LocalDateOfInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("LocalDateOfInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$LocalDateOfInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<LocalDate> testLocalDateOfInstant() {
return ImmutableSet.of(
- Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toLocalDate(),
- Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalDate(),
- LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalDate(),
- OffsetDateTime.ofInstant(Instant.EPOCH, ZoneOffset.MIN).toLocalDate());
+ LocalDate.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
+ LocalDate.ofInstant(Instant.EPOCH, ZoneOffset.UTC),
+ LocalDate.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")),
+ LocalDate.ofInstant(Instant.EPOCH, ZoneOffset.MIN));
}
LocalDateTimeOfInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("LocalDateTimeOfInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$LocalDateTimeOfInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<LocalDateTime> testLocalDateTimeOfInstant() {
return ImmutableSet.of(
- Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toLocalDateTime(),
- Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalDateTime(),
- OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalDateTime());
+ LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
+ LocalDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC),
+ LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")));
}
LocalTimeOfInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("LocalTimeOfInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$LocalTimeOfInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<LocalTime> testLocalTimeOfInstant() {
return ImmutableSet.of(
- Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toLocalTime(),
- Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalTime(),
- LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalTime(),
- OffsetDateTime.ofInstant(Instant.EPOCH, ZoneOffset.MIN).toLocalTime(),
- OffsetTime.ofInstant(Instant.EPOCH, ZoneOffset.MAX).toLocalTime());
+ LocalTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
+ LocalTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC),
+ LocalTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")),
+ LocalTime.ofInstant(Instant.EPOCH, ZoneOffset.MIN),
+ LocalTime.ofInstant(Instant.EPOCH, ZoneOffset.MAX));
}
OffsetDateTimeOfInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("OffsetDateTimeOfInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$OffsetDateTimeOfInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
OffsetDateTime testOffsetDateTimeOfInstant() {
- return Instant.EPOCH.atZone(ZoneOffset.UTC).toOffsetDateTime();
+ return OffsetDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);
}
InstantAtOffset
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("InstantAtOffset")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$InstantAtOffset).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
OffsetDateTime testInstantAtOffset() {
- return OffsetDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);
+ return Instant.EPOCH.atOffset(ZoneOffset.UTC);
}
OffsetTimeOfInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("OffsetTimeOfInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$OffsetTimeOfInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<OffsetTime> testOffsetTimeOfInstant() {
return ImmutableSet.of(
- OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")).toOffsetTime(),
- Instant.EPOCH.atOffset(ZoneOffset.UTC).toOffsetTime());
+ OffsetTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
+ OffsetTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC));
}
InstantAtZone
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("InstantAtZone")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$InstantAtZone).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ZonedDateTime testInstantAtZone() {
- return ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);
+ return Instant.EPOCH.atZone(ZoneOffset.UTC);
}
UtcClock
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("UtcClock")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$UtcClock).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Clock testUtcClock() {
- return Clock.system(ZoneOffset.UTC);
+ return Clock.systemUTC();
}
EpochInstant
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("EpochInstant")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$EpochInstant).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Instant> testEpochInstant() {
- return ImmutableSet.of(
- Instant.ofEpochMilli(0),
- Instant.ofEpochMilli(0L),
- Instant.ofEpochSecond(0),
- Instant.ofEpochSecond(0, 0));
+ return ImmutableSet.of(Instant.EPOCH, Instant.EPOCH, Instant.EPOCH, Instant.EPOCH);
}
InstantIsBefore
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("InstantIsBefore")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$InstantIsBefore).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testInstantIsBefore() {
- return ImmutableSet.of(
- Instant.MIN.compareTo(Instant.MAX) < 0, Instant.MIN.compareTo(Instant.MAX) >= 0);
+ return ImmutableSet.of(Instant.MIN.isBefore(Instant.MAX), !Instant.MIN.isBefore(Instant.MAX));
}
InstantIsAfter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("InstantIsAfter")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$InstantIsAfter).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testInstantIsAfter() {
- return ImmutableSet.of(
- Instant.MIN.compareTo(Instant.MAX) > 0, Instant.MIN.compareTo(Instant.MAX) <= 0);
+ return ImmutableSet.of(Instant.MIN.isAfter(Instant.MAX), !Instant.MIN.isAfter(Instant.MAX));
}
LocalTimeMin
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("LocalTimeMin")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$LocalTimeMin).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<LocalTime> testLocalTimeMin() {
return ImmutableSet.of(
- LocalTime.MIDNIGHT,
- LocalTime.of(0, 0),
- LocalTime.of(0, 0, 0),
- LocalTime.of(0, 0, 0, 0),
- LocalTime.ofNanoOfDay(0),
- LocalTime.ofSecondOfDay(0));
+ LocalTime.MIN, LocalTime.MIN, LocalTime.MIN, LocalTime.MIN, LocalTime.MIN, LocalTime.MIN);
}
LocalDateAtStartOfDay
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("LocalDateAtStartOfDay")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$LocalDateAtStartOfDay).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
LocalDateTime testLocalDateAtStartOfDay() {
- return LocalDate.EPOCH.atTime(LocalTime.MIN);
+ return LocalDate.EPOCH.atStartOfDay();
}
ChronoLocalDateIsBefore
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ChronoLocalDateIsBefore")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ChronoLocalDateIsBefore).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testChronoLocalDateIsBefore() {
return ImmutableSet.of(
- LocalDate.MIN.compareTo(LocalDate.MAX) < 0, LocalDate.MIN.compareTo(LocalDate.MAX) >= 0);
+ LocalDate.MIN.isBefore(LocalDate.MAX), !LocalDate.MIN.isBefore(LocalDate.MAX));
}
ChronoLocalDateIsAfter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ChronoLocalDateIsAfter")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ChronoLocalDateIsAfter).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testChronoLocalDateIsAfter() {
return ImmutableSet.of(
- LocalDate.MIN.compareTo(LocalDate.MAX) > 0, LocalDate.MIN.compareTo(LocalDate.MAX) <= 0);
+ LocalDate.MIN.isAfter(LocalDate.MAX), !LocalDate.MIN.isAfter(LocalDate.MAX));
}
ChronoLocalDateTimeIsBefore
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ChronoLocalDateTimeIsBefore")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ChronoLocalDateTimeIsBefore).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testChronoLocalDateTimeIsBefore() {
return ImmutableSet.of(
- LocalDateTime.MIN.compareTo(LocalDateTime.MAX) < 0,
- LocalDateTime.MIN.compareTo(LocalDateTime.MAX) >= 0);
+ LocalDateTime.MIN.isBefore(LocalDateTime.MAX),
+ !LocalDateTime.MIN.isBefore(LocalDateTime.MAX));
}
ChronoLocalDateTimeIsAfter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ChronoLocalDateTimeIsAfter")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ChronoLocalDateTimeIsAfter).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testChronoLocalDateTimeIsAfter() {
return ImmutableSet.of(
- LocalDateTime.MIN.compareTo(LocalDateTime.MAX) > 0,
- LocalDateTime.MIN.compareTo(LocalDateTime.MAX) <= 0);
+ LocalDateTime.MIN.isAfter(LocalDateTime.MAX),
+ !LocalDateTime.MIN.isAfter(LocalDateTime.MAX));
}
ChronoZonedDateTimeIsBefore
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ChronoZonedDateTimeIsBefore")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ChronoZonedDateTimeIsBefore).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testChronoZonedDateTimeIsBefore() {
return ImmutableSet.of(
- ZonedDateTime.now().compareTo(ZonedDateTime.now()) < 0,
- ZonedDateTime.now().compareTo(ZonedDateTime.now()) >= 0);
+ ZonedDateTime.now().isBefore(ZonedDateTime.now()),
+ !ZonedDateTime.now().isBefore(ZonedDateTime.now()));
}
ChronoZonedDateTimeIsAfter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ChronoZonedDateTimeIsAfter")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ChronoZonedDateTimeIsAfter).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testChronoZonedDateTimeIsAfter() {
return ImmutableSet.of(
- ZonedDateTime.now().compareTo(ZonedDateTime.now()) > 0,
- ZonedDateTime.now().compareTo(ZonedDateTime.now()) <= 0);
+ ZonedDateTime.now().isAfter(ZonedDateTime.now()),
+ !ZonedDateTime.now().isAfter(ZonedDateTime.now()));
}
OffsetDateTimeIsAfter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("OffsetDateTimeIsAfter")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$OffsetDateTimeIsAfter).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testOffsetDateTimeIsAfter() {
return ImmutableSet.of(
- OffsetDateTime.MIN.compareTo(OffsetDateTime.MAX) > 0,
- OffsetDateTime.MIN.compareTo(OffsetDateTime.MAX) <= 0);
+ OffsetDateTime.MIN.isAfter(OffsetDateTime.MAX),
+ !OffsetDateTime.MIN.isAfter(OffsetDateTime.MAX));
}
OffsetDateTimeIsBefore
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("OffsetDateTimeIsBefore")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$OffsetDateTimeIsBefore).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testOffsetDateTimeIsBefore() {
return ImmutableSet.of(
- OffsetDateTime.MIN.compareTo(OffsetDateTime.MAX) < 0,
- OffsetDateTime.MIN.compareTo(OffsetDateTime.MAX) >= 0);
+ OffsetDateTime.MIN.isBefore(OffsetDateTime.MAX),
+ !OffsetDateTime.MIN.isBefore(OffsetDateTime.MAX));
}
ZeroDuration
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ZeroDuration")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ZeroDuration).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Duration> testZeroDuration() {
return ImmutableSet.of(
- Duration.ofNanos(0),
- Duration.ofMillis(0),
- Duration.ofSeconds(0),
- Duration.ofSeconds(0, 0),
- Duration.ofMinutes(0),
- Duration.ofHours(0),
- Duration.ofDays(0),
- Duration.of(0, ChronoUnit.MILLIS));
+ Duration.ZERO,
+ Duration.ZERO,
+ Duration.ZERO,
+ Duration.ZERO,
+ Duration.ZERO,
+ Duration.ZERO,
+ Duration.ZERO,
+ Duration.ZERO);
}
DurationOfDays
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationOfDays")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationOfDays).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationOfDays() {
- return Duration.of(1, ChronoUnit.DAYS);
+ return Duration.ofDays(1);
}
DurationOfHours
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationOfHours")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationOfHours).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationOfHours() {
- return Duration.of(1, ChronoUnit.HOURS);
+ return Duration.ofHours(1);
}
DurationOfMillis
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationOfMillis")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationOfMillis).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationOfMillis() {
- return Duration.of(1, ChronoUnit.MILLIS);
+ return Duration.ofMillis(1);
}
DurationOfMinutes
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationOfMinutes")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationOfMinutes).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationOfMinutes() {
- return Duration.of(1, ChronoUnit.MINUTES);
+ return Duration.ofMinutes(1);
}
DurationOfNanos
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationOfNanos")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationOfNanos).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationOfNanos() {
- return Duration.of(1, ChronoUnit.NANOS);
+ return Duration.ofNanos(1);
}
DurationOfSeconds
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationOfSeconds")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationOfSeconds).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationOfSeconds() {
- return Duration.of(1, ChronoUnit.SECONDS);
+ return Duration.ofSeconds(1);
}
DurationBetweenInstants
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationBetweenInstants")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationBetweenInstants).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationBetweenInstants() {
- return Duration.ofMillis(Instant.MAX.toEpochMilli() - Instant.MIN.toEpochMilli());
+ return Duration.between(Instant.MIN, Instant.MAX);
}
DurationBetweenOffsetDateTimes
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationBetweenOffsetDateTimes")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationBetweenOffsetDateTimes).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Duration testDurationBetweenOffsetDateTimes() {
- return Duration.between(OffsetDateTime.MIN.toInstant(), OffsetDateTime.MAX.toInstant())
- .plus(
- Duration.ofSeconds(
- OffsetDateTime.MAX.toEpochSecond() - OffsetDateTime.MIN.toEpochSecond()));
+ return Duration.between(OffsetDateTime.MIN, OffsetDateTime.MAX)
+ .plus(Duration.between(OffsetDateTime.MIN, OffsetDateTime.MAX));
}
DurationIsZero
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("DurationIsZero")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$DurationIsZero).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testDurationIsZero() {
- return ImmutableSet.of(
- Duration.ofDays(1).equals(Duration.ZERO), Duration.ZERO.equals(Duration.ofDays(2)));
+ return ImmutableSet.of(Duration.ofDays(1).isZero(), Duration.ofDays(2).isZero());
}
ZeroPeriod
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ZeroPeriod")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!TimeRules\$ZeroPeriod).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Period> testZeroPeriod() {
- return ImmutableSet.of(
- Period.ofDays(0),
- Period.ofWeeks(0),
- Period.ofMonths(0),
- Period.ofYears(0),
- Period.of(0, 0, 0));
+ return ImmutableSet.of(Period.ZERO, Period.ZERO, Period.ZERO, Period.ZERO, Period.ZERO);
}