Class TimeValue

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<TimeValue>

    public final class TimeValue
    extends java.lang.Object
    implements java.lang.Cloneable, java.lang.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 Summary

      Constructors 
      Constructor Description
      TimeValue()  
      TimeValue​(long rawValue, java.util.concurrent.TimeUnit unit)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TimeValue add​(TimeValue other)  
      TimeValue clone()  
      int compareTo​(TimeValue o)  
      TimeValue convertTo​(java.util.concurrent.TimeUnit unit)
      Converts this TimeValue to another TimeValue with a different TimeUnit.
      TimeValue difference​(TimeValue timevalue)
      Computes the difference between this timevalue and the supplied timevalue.
      boolean equals​(java.lang.Object obj)  
      long getRawValue()
      Get the raw value for this TimeValue using the TimeUnit used during creation
      long getRawValue​(java.util.concurrent.TimeUnit unit)
      Get the raw value for this TimeValue using the TimeUnit supplied.
      java.util.concurrent.TimeUnit getUnit()  
      int hashCode()  
      static TimeValue parse​(java.lang.String timevalueSerialized)
      Parse a TimeValue from a serialized string
      void setRawValue​(long rawValue)  
      void setUnit​(java.util.concurrent.TimeUnit unit)  
      java.lang.String toString()
      Emits a json serialized string that represents this TimeValue.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TimeValue

        public TimeValue()
      • TimeValue

        public TimeValue​(long rawValue,
                         @Nonnull
                         java.util.concurrent.TimeUnit unit)
    • Method Detail

      • 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
                                java.util.concurrent.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​(java.util.concurrent.TimeUnit unit)
      • getUnit

        public java.util.concurrent.TimeUnit getUnit()
      • parse

        public static TimeValue parse​(java.lang.String timevalueSerialized)
                               throws java.io.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.
        java.io.IOException
      • toString

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

        @Nonnull
        public TimeValue convertTo​(@Nonnull
                                   java.util.concurrent.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.
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • compareTo

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

        public TimeValue clone()
        Overrides:
        clone in class java.lang.Object