@Test void micros() { TimeInterval interval = new TimeInterval(2L, ChronoUnit.MICROS); Assertions.assertThat(interval.toString()).isEqualTo("2us"); }
@Override @SuppressWarnings("MagicNumber") public String toString() { String unit; Long calculatedInterval = interval; switch (chronoUnit) { case NANOS: unit = "ns"; break; case MICROS: unit = "us"; break; case MILLIS: unit = "ms"; break; case SECONDS: unit = "s"; break; case MINUTES: unit = "m"; break; case HOURS: unit = "h"; break; case HALF_DAYS: unit = "h"; calculatedInterval = Duration.of(interval, ChronoUnit.HALF_DAYS).toHours(); break; case DAYS: unit = "d"; break; case WEEKS: unit = "w"; break; case MONTHS: unit = "mo"; break; case YEARS: unit = "y"; break; case DECADES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 10); break; case CENTURIES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 100); break; case MILLENNIA: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000); break; case ERAS: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000_000_000); break; case FOREVER: default: String message = String.format("The ChronoUnit.%s is not supported.", chronoUnit); throw new IllegalArgumentException(message); } return String.valueOf(calculatedInterval) + unit; }
TimeInterval { @Override @SuppressWarnings("MagicNumber") public String toString() { String unit; Long calculatedInterval = interval; switch (chronoUnit) { case NANOS: unit = "ns"; break; case MICROS: unit = "us"; break; case MILLIS: unit = "ms"; break; case SECONDS: unit = "s"; break; case MINUTES: unit = "m"; break; case HOURS: unit = "h"; break; case HALF_DAYS: unit = "h"; calculatedInterval = Duration.of(interval, ChronoUnit.HALF_DAYS).toHours(); break; case DAYS: unit = "d"; break; case WEEKS: unit = "w"; break; case MONTHS: unit = "mo"; break; case YEARS: unit = "y"; break; case DECADES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 10); break; case CENTURIES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 100); break; case MILLENNIA: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000); break; case ERAS: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000_000_000); break; case FOREVER: default: String message = String.format("The ChronoUnit.%s is not supported.", chronoUnit); throw new IllegalArgumentException(message); } return String.valueOf(calculatedInterval) + unit; } }
TimeInterval { @Override @SuppressWarnings("MagicNumber") public String toString() { String unit; Long calculatedInterval = interval; switch (chronoUnit) { case NANOS: unit = "ns"; break; case MICROS: unit = "us"; break; case MILLIS: unit = "ms"; break; case SECONDS: unit = "s"; break; case MINUTES: unit = "m"; break; case HOURS: unit = "h"; break; case HALF_DAYS: unit = "h"; calculatedInterval = Duration.of(interval, ChronoUnit.HALF_DAYS).toHours(); break; case DAYS: unit = "d"; break; case WEEKS: unit = "w"; break; case MONTHS: unit = "mo"; break; case YEARS: unit = "y"; break; case DECADES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 10); break; case CENTURIES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 100); break; case MILLENNIA: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000); break; case ERAS: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000_000_000); break; case FOREVER: default: String message = String.format("The ChronoUnit.%s is not supported.", chronoUnit); throw new IllegalArgumentException(message); } return String.valueOf(calculatedInterval) + unit; } TimeInterval(@Nonnull final Long interval, @Nonnull final ChronoUnit chronoUnit); }
TimeInterval { @Override @SuppressWarnings("MagicNumber") public String toString() { String unit; Long calculatedInterval = interval; switch (chronoUnit) { case NANOS: unit = "ns"; break; case MICROS: unit = "us"; break; case MILLIS: unit = "ms"; break; case SECONDS: unit = "s"; break; case MINUTES: unit = "m"; break; case HOURS: unit = "h"; break; case HALF_DAYS: unit = "h"; calculatedInterval = Duration.of(interval, ChronoUnit.HALF_DAYS).toHours(); break; case DAYS: unit = "d"; break; case WEEKS: unit = "w"; break; case MONTHS: unit = "mo"; break; case YEARS: unit = "y"; break; case DECADES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 10); break; case CENTURIES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 100); break; case MILLENNIA: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000); break; case ERAS: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000_000_000); break; case FOREVER: default: String message = String.format("The ChronoUnit.%s is not supported.", chronoUnit); throw new IllegalArgumentException(message); } return String.valueOf(calculatedInterval) + unit; } TimeInterval(@Nonnull final Long interval, @Nonnull final ChronoUnit chronoUnit); @Override @SuppressWarnings("MagicNumber") String toString(); }
TimeInterval { @Override @SuppressWarnings("MagicNumber") public String toString() { String unit; Long calculatedInterval = interval; switch (chronoUnit) { case NANOS: unit = "ns"; break; case MICROS: unit = "us"; break; case MILLIS: unit = "ms"; break; case SECONDS: unit = "s"; break; case MINUTES: unit = "m"; break; case HOURS: unit = "h"; break; case HALF_DAYS: unit = "h"; calculatedInterval = Duration.of(interval, ChronoUnit.HALF_DAYS).toHours(); break; case DAYS: unit = "d"; break; case WEEKS: unit = "w"; break; case MONTHS: unit = "mo"; break; case YEARS: unit = "y"; break; case DECADES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 10); break; case CENTURIES: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 100); break; case MILLENNIA: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000); break; case ERAS: unit = "y"; calculatedInterval = Math.multiplyExact(interval, 1000_000_000); break; case FOREVER: default: String message = String.format("The ChronoUnit.%s is not supported.", chronoUnit); throw new IllegalArgumentException(message); } return String.valueOf(calculatedInterval) + unit; } TimeInterval(@Nonnull final Long interval, @Nonnull final ChronoUnit chronoUnit); @Override @SuppressWarnings("MagicNumber") String toString();  }