Class DurationValue

java.lang.Object
yearreview.app.util.value.Value
yearreview.app.util.value.DurationValue
All Implemented Interfaces:
Comparable<Value>

public class DurationValue extends Value
A Value that represents a Duration, internally using the Duration-Datatype.
Author:
ColdStone37
  • Field Details

    • DURATION_SHOW_PARTS

      private static final int DURATION_SHOW_PARTS
      Parts of the Duration to output in the toString()-function.
      See Also:
    • INTERVAL_SIZES

      private static final long[] INTERVAL_SIZES
      Amount of values in each Interval (e.g. 1000ms = 1s; 60s = 1min; ...).
    • INTERVAL_VALUE_LENGTHS

      private static final int[] INTERVAL_VALUE_LENGTHS
      Maximum amount of spaces needed for Values in each interval (equivalent to floor(log10(INTERVAL_SIZES))).
    • INTERVAL_NAMES

      private static final String[] INTERVAL_NAMES
      Abbreviations of the intervals.
    • duration

      private final Duration duration
      Duration stored in this object.
  • Constructor Details

    • DurationValue

      public DurationValue(Duration d)
      Constructs a new DurationValue from a Duration
      Parameters:
      d - duration
  • Method Details

    • getType

      public ValueType getType()
      Gets the Type of this Value.
      Specified by:
      getType in class Value
      Returns:
      ValueType.DURATION
    • toString

      public String toString()
      Formats the Duration to a String.
      Specified by:
      toString in class Value
      Returns:
      formatted duration (e.g. "2d 19h")
    • plus

      public Value plus(Value other)
      Gets a DurationValue that has to sum of this object and the other-object.
      Specified by:
      plus in class Value
      Parameters:
      other - Value to add
      Returns:
      DurationValue or null if the other Value is not of the same type
    • getValue

      protected Object getValue()
      Gets the internally used Value to measure the duration.
      Specified by:
      getValue in class Value
      Returns:
      Duration-object
    • compareTo

      public int compareTo(Value other)
      Compares to another Value-object.
      Parameters:
      other - Value-object to compare against
      Returns:
      comparison of durations or Integer.MAX_VALUE if the other Value isn't a DurationValue