info.monitorenter.util
Class TimeStampedValue

java.lang.Object
  extended by info.monitorenter.util.TimeStampedValue
All Implemented Interfaces:
Comparable, Map.Entry

public final class TimeStampedValue
extends Object
implements Map.Entry, Comparable

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(java.lang.Object) compares the key.

Version:
$Revision: 1.5 $
Author:
Achim Westermann

Constructor Summary
TimeStampedValue(long key, Object value)
          Creates an instance with the given timestamp key and the value to timestamp.
TimeStampedValue(Object value)
          Creates an instance for the given value that is timestamped with the current time.
 
Method Summary
 int compareTo(Object obj)
          Compares the given TimeStampedValue to this by the internal getTime().
 boolean equals(Object o)
          Returns true, if o!
 Object getKey()
          Returns the Long that marks the timestamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
 long getTime()
          Returns the timestamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
 Object getValue()
          Returns the timestamped instance.
 int hashCode()
           
 boolean isPast()
          Returns wethter the internal timestamp marks a time in the past or not.
 Object setValue(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,
                        Object value)
Creates an instance with the given timestamp key and the value to timestamp.

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

TimeStampedValue

public TimeStampedValue(Object value)
Creates an instance for the given value that is timestamped with the current time.

Parameters:
value - the value to timestamp.
See Also:
System.currentTimeMillis()
Method Detail

getKey

public Object getKey()
Returns the Long that marks the timestamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).

Specified by:
getKey in interface Map.Entry
Returns:
the Long that marks the timestamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).
See Also:
Map.Entry.getKey()

getValue

public Object getValue()
Returns the timestamped instance.

Specified by:
getValue in interface Map.Entry
Returns:
the timestamped instance.
See Also:
Map.Entry.getValue()

getTime

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

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

equals

public boolean equals(Object o)
Returns true, if o!=null && this.key.equals(0) && o.insanceOf(TimeStampedValue).

Specified by:
equals in interface Map.Entry
Overrides:
equals in class Object
Parameters:
o - the TimeStampedValue to compare this instance to.
Returns:
true, if o!=null && this.key.equals(0) && o.insanceOf(TimeStampedValue).

hashCode

public int hashCode()
Specified by:
hashCode in interface Map.Entry
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

setValue

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

Specified by:
setValue in interface Map.Entry
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)

compareTo

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

Specified by:
compareTo in interface Comparable
Parameters:
obj - the object to compare this to.
See Also:
Comparable.compareTo(java.lang.Object)

isPast

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

For normal a timestamp 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 timestamp marks a moment in the past, false else.


Copyright © 2001 - 2007 LGPL, All Rights Footloose.