Class TimeStampedValue

  • All Implemented Interfaces:
    java.lang.Comparable<TimeStampedValue>, java.util.Map.Entry<java.lang.Long,​java.lang.Object>

    public final class TimeStampedValue
    extends java.lang.Object
    implements java.util.Map.Entry<java.lang.Long,​java.lang.Object>, java.lang.Comparable<TimeStampedValue>
    Simple wrapper around a time in ms and a value Object.

    The key is the time in ms and may be used in a Map. compareTo(TimeStampedValue) compares the key.

    Version:
    $Revision: 1.11 $
    Author:
    Achim Westermann
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeStampedValue​(long key, java.lang.Object value)
      Creates an instance with the given timestamp key and the value to time stamp.
      TimeStampedValue​(java.lang.Object value)
      Creates an instance for the given value that is time stamped with the current time.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(TimeStampedValue obj)
      Compares the given TimeStampedValue to this by the internal getTime().
      boolean equals​(java.lang.Object obj)  
      java.lang.Long getKey()
      Returns the Long that marks the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
      long getTime()
      Returns the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
      java.lang.Object getValue()
      Returns the time stamp.
      int hashCode()  
      boolean isPast()
      Returns whether the internal time stamp marks a time in the past or not.
      java.lang.Object setValue​(java.lang.Object value)
      Assigns a different value to the timestamp.
      • Methods inherited from class java.lang.Object

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

      • TimeStampedValue

        public TimeStampedValue​(long key,
                                java.lang.Object value)
        Creates an instance with the given timestamp key and the value to time stamp.

        Parameters:
        key - the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
        value - the value to time stamp.
      • TimeStampedValue

        public TimeStampedValue​(java.lang.Object value)
        Creates an instance for the given value that is time stamped with the current time.

        Parameters:
        value - the value to time stamp.
        See Also:
        System.currentTimeMillis()
    • Method Detail

      • compareTo

        public int compareTo​(TimeStampedValue obj)
        Compares the given TimeStampedValue to this by the internal getTime().

        Specified by:
        compareTo in interface java.lang.Comparable<TimeStampedValue>
        Parameters:
        obj - the object to compare this to.
        Returns:
        see interface.
        See Also:
        Comparable.compareTo(java.lang.Object)
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map.Entry<java.lang.Long,​java.lang.Object>
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • getKey

        public java.lang.Long getKey()
        Returns the Long that marks the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
        Specified by:
        getKey in interface java.util.Map.Entry<java.lang.Long,​java.lang.Object>
        Returns:
        the Long that marks the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
        See Also:
        Map.Entry.getKey()
      • getTime

        public long getTime()
        Returns the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).

        Returns:
        the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
      • getValue

        public java.lang.Object getValue()
        Returns the time stamp.

        Specified by:
        getValue in interface java.util.Map.Entry<java.lang.Long,​java.lang.Object>
        Returns:
        the time stamp.
        See Also:
        Map.Entry.getValue()
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map.Entry<java.lang.Long,​java.lang.Object>
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • isPast

        public boolean isPast()
        Returns whether the internal time stamp marks a time in the past or not.

        For normal a time stamp represents a value regarded at a time. But it is also thinkable to mark a value for expiration in the future. This method returns true if the internal time- representing key is smaller than the actual time.

        Returns:
        true if the internal time stamp marks a moment in the past, false else.
      • setValue

        public java.lang.Object setValue​(java.lang.Object value)
        Assigns a different value to the timestamp.

        Specified by:
        setValue in interface java.util.Map.Entry<java.lang.Long,​java.lang.Object>
        Parameters:
        value - the new value to be marked with this timestamp.
        Returns:
        the previous value that was contained.
        See Also:
        Map.Entry.setValue(java.lang.Object)