Class TimeValue

java.lang.Object
com.linkedin.alpini.base.misc.TimeValue
All Implemented Interfaces:
Cloneable, Comparable<TimeValue>

public final class TimeValue extends Object implements Cloneable, Comparable<TimeValue>
A class to encapsulate time values along with their measurement units Works for both timestamps as well as time durations. Similar to org.xeril.clock.Timespan but supports nanosecond resolution as well.
  • Constructor Details

    • TimeValue

      public TimeValue()
    • TimeValue

      public TimeValue(long rawValue, @Nonnull TimeUnit unit)
  • Method Details

    • setRawValue

      public void setRawValue(long rawValue)
    • getRawValue

      public long getRawValue()
      Get the raw value for this TimeValue using the TimeUnit used during creation
      Returns:
      the raw value for this TimeValue
    • getRawValue

      public long getRawValue(@Nonnull TimeUnit unit)
      Get the raw value for this TimeValue using the TimeUnit supplied.
      Parameters:
      unit - The TimeUnit to be converted to a raw value.
      Returns:
      The raw value for this TimeValue, in the TimeUnit supplied.
    • setUnit

      public void setUnit(TimeUnit unit)
    • getUnit

      public TimeUnit getUnit()
    • parse

      public static TimeValue parse(String timevalueSerialized) throws IOException
      Parse a TimeValue from a serialized string
      Parameters:
      timevalueSerialized - A Serialized TimeValue represented as a String.
      Returns:
      The TimeValue parsed from the inputted string.
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException - When there is a problem parsing the input, such as an invalid string.
      IOException
    • toString

      public String toString()
      Emits a json serialized string that represents this TimeValue.
      Overrides:
      toString in class Object
    • convertTo

      @Nonnull public TimeValue convertTo(@Nonnull TimeUnit unit)
      Converts this TimeValue to another TimeValue with a different TimeUnit. Useful if you know which unit you want to get values in, irrespective of which unit they were measured in.
      Parameters:
      unit - The TimeUnit to be converted.
      Returns:
      The converted value
    • difference

      @Nonnull public TimeValue difference(@Nonnull TimeValue timevalue)
      Computes the difference between this timevalue and the supplied timevalue. The difference is not absolute, so it is the caller's responsibility to ensure that (this) is newer than the timevalue passed in.
      Parameters:
      timevalue - The other TimeValue needed for the difference operation.
      Returns:
      The difference between this time and the time provided timevalue.
    • add

      @Nonnull public TimeValue add(TimeValue other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(@Nonnull TimeValue o)
      Specified by:
      compareTo in interface Comparable<TimeValue>
    • clone

      public TimeValue clone()
      Overrides:
      clone in class Object