Package info.monitorenter.util
Class TimeStampedValue
- java.lang.Object
-
- info.monitorenter.util.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.
compares the key.compareTo(TimeStampedValue)
- 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 givenTimeStampedValue
to this by the internalgetTime()
.boolean
equals(java.lang.Object obj)
java.lang.Long
getKey()
Returns theLong
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.
-
-
-
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 givenTimeStampedValue
to this by the internalgetTime()
.- Specified by:
compareTo
in interfacejava.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 interfacejava.util.Map.Entry<java.lang.Long,java.lang.Object>
- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(java.lang.Object)
-
getKey
public java.lang.Long getKey()
Returns theLong
that marks the time stamp (difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC).- Specified by:
getKey
in interfacejava.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 interfacejava.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 interfacejava.util.Map.Entry<java.lang.Long,java.lang.Object>
- Overrides:
hashCode
in classjava.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 interfacejava.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)
-
-