cz.cuni.amis.pogamut.multi.utils.timekey
Class TimeKey

java.lang.Object
  extended by cz.cuni.amis.pogamut.multi.utils.timekey.TimeKey
All Implemented Interfaces:
java.lang.Comparable

public class TimeKey
extends java.lang.Object
implements java.lang.Comparable

the TimeKey class makes sure that for every integer time there is only one instance of the TimeKey object. The inner structure of active is implemented via a WeakHashMap. This means that if a process loses reference for the TimeKey object, it can be garbage collected.


Nested Class Summary
static class TimeKey.TimeKeyComparator
           
 
Field Summary
protected static java.util.Map<java.lang.Long,java.lang.ref.WeakReference<TimeKey>> keys
           
 
Method Summary
static void clear()
          Wipes out case with time keys.
 int compareTo(java.lang.Object key)
           
 boolean equals(java.lang.Object other)
           
static boolean exists(long time)
          Checks if a TimeKey instance exists for the integer time.
protected  void finalize()
           
static TimeKey get(long time)
          Returns the TimeKey object for the required time.
static java.util.List<java.lang.ref.WeakReference<TimeKey>> getAllKeys()
           
static ImmutableFlag<java.lang.Integer> getInstances()
           
 long getTime()
          returns the integer time for this timekey.
 int hashCode()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

keys

protected static java.util.Map<java.lang.Long,java.lang.ref.WeakReference<TimeKey>> keys
Method Detail

getInstances

public static ImmutableFlag<java.lang.Integer> getInstances()

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

get

public static TimeKey get(long time)
Returns the TimeKey object for the required time. synchronized

Parameters:
time -
Returns:
always returns the same reference for the same time!

clear

public static void clear()
Wipes out case with time keys. Used by tests.


equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

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

exists

public static boolean exists(long time)
Checks if a TimeKey instance exists for the integer time.

Parameters:
time -
Returns:

getTime

public long getTime()
returns the integer time for this timekey.

Returns:

compareTo

public int compareTo(java.lang.Object key)
Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getAllKeys

public static java.util.List<java.lang.ref.WeakReference<TimeKey>> getAllKeys()