Class Interval

java.lang.Object
de.oliver.fancynpcs.api.utils.Interval

@Internal public final class Interval extends Object
Interval is simple (but not very extensible) object that provides methods for unit conversion and creation of human-readable 'elapsed time' strings.

This API is for internal use only and can change at any time.

  • Constructor Details

    • Interval

      public Interval(long value)
  • Method Details

    • now

      @NotNull public static @NotNull Interval now()
      Returns Interval object of current time.
    • of

      @NotNull public static @NotNull Interval of(long interval, @NotNull @NotNull Interval.Unit unit)
      Returns Interval object constructed from provided long (interval). It is expected that provided value is already a difference between two timestamps.
    • of

      @NotNull public static @NotNull Interval of(double interval, @NotNull @NotNull Interval.Unit unit)
      Returns Interval object constructed from provided double (interval). It is expected that provided value is already a difference between two timestamps.
    • between

      @NotNull public static @NotNull Interval between(long n, long m, @NotNull @NotNull Interval.Unit unit)
      Returns Interval of time between n and m.
    • between

      @NotNull public static @NotNull Interval between(double n, double m, @NotNull @NotNull Interval.Unit unit)
      Returns Interval of time between n and m.
    • as

      public double as(@NotNull @NotNull Interval.Unit unit)
      Returns interval converted to specified Interval.Unit (unit).
      Interval.of(1500, Interval.Unit.MILLISECONDS).as(Interval.Unit.SECONDS) // 1.5F
      Interval.of(300, Interval.Unit.SECONDS).as(Interval.Unit.MINUTES) // 5F
      
    • add

      @NotNull public @NotNull Interval add(@NotNull @NotNull Interval other)
      Returns a copy of (this) Interval with n of Interval.Unit added.
    • add

      @NotNull public @NotNull Interval add(long n, @NotNull @NotNull Interval.Unit unit)
      Returns a copy of (this) Interval with n of Interval.Unit added.
    • remove

      @NotNull public @NotNull Interval remove(@NotNull @NotNull Interval other)
      Returns a copy of (this) Interval with n of Interval.Unit removed.
    • remove

      @NotNull public @NotNull Interval remove(long n, @NotNull @NotNull Interval.Unit unit)
      Returns a copy of (this) Interval with n of Interval.Unit removed.
    • toDate

      @NotNull public @NotNull Date toDate()
      Returns new Date created from (this) Interval.
    • toInstant

      @NotNull public @NotNull Instant toInstant()
      Returns new Instant created from (this) Interval.
    • toString

      @NotNull public @NotNull String toString()
      Returns formatted String expressing this Interval.
      final Interval i = Interval.between(lastJoinedMillis, currentTimeMillis, Interval.Unit.MILLISECONDS);
      System.out.println(i.toString()) + " ago"; // eg. '1d 7h 32min 10s ago'
      
      Overrides:
      toString in class Object