messif.objects.keys
Class KeyOperator<T>

java.lang.Object
  extended by messif.objects.keys.KeyOperator<T>
Type Parameters:
T - specific type of the key
All Implemented Interfaces:
java.util.Comparator<T>
Direct Known Subclasses:
DoubleKeyOperator

public abstract class KeyOperator<T>
extends java.lang.Object
implements java.util.Comparator<T>

This class provides an abstract operator for object keys that have a defined order. The operator must know the maximal and minimal keys and must be able to provide a successor and predecesor keys. Finally, it should be able to create key intervals for the pair of keys.


Constructor Summary
KeyOperator()
           
 
Method Summary
abstract  KeyInterval<T> createInteral(T from, T to)
          This method creates an interval given two keys.
abstract  T getDifference(T first, T second)
          Given two keys, return their distance (difference)
abstract  T getMaxKey()
          Returns the maximal value of given key type.
abstract  T getMiddleKey(T first, T second)
          Given two keys, return the key in the middle.
abstract  T getMinKey()
          Returns the minimal value of given key type.
abstract  T getNextKey(T key)
          Given a key, return the smallest key which is greater than the key specified.
abstract  T getPreviousKey(T key)
          Given a key, return the greatest key which is smaller than the key specified.
 boolean intersect(KeyInterval<T> first, KeyInterval<T> second)
          Return true if the two intervals intersect.
 boolean isInBetween(T key, T low, T up)
          Finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in (low, up).
 boolean isInBetweenEQ(T key, T low, T up)
          finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in [low, up]
 boolean isInBetweenEQH(T key, T low, T up)
          Finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in (low, up]
 boolean isInBetweenEQL(T key, T low, T up)
          Finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in [low, up)
abstract  KeyInterval<T> makeLeftOpen(KeyInterval<T> interval)
          This method returns a new instance of KeyInterval which makes this interval opened from the left.
 T max(T first, T second)
          Return the maximum of the two values passed or the first one if they are equal.
 T min(T first, T second)
          Return the minimum of the two values passed or the first one if they are equal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
compare, equals
 

Constructor Detail

KeyOperator

public KeyOperator()
Method Detail

getMaxKey

public abstract T getMaxKey()
Returns the maximal value of given key type.

Returns:
maximal value of given key type

getMinKey

public abstract T getMinKey()
Returns the minimal value of given key type.

Returns:
minimal value of given key type

getNextKey

public abstract T getNextKey(T key)
Given a key, return the smallest key which is greater than the key specified.

Parameters:
key -
Returns:
return the smallest key which is greater than the key

getPreviousKey

public abstract T getPreviousKey(T key)
Given a key, return the greatest key which is smaller than the key specified.

Parameters:
key -
Returns:
return the greatest key which is smaller than the key

getDifference

public abstract T getDifference(T first,
                                T second)
Given two keys, return their distance (difference)

Parameters:
first - the first key
second - the second
Returns:
distance of the keys

getMiddleKey

public abstract T getMiddleKey(T first,
                               T second)
Given two keys, return the key in the middle.

Parameters:
first - the first key
second - the second
Returns:
key in the middle

createInteral

public abstract KeyInterval<T> createInteral(T from,
                                             T to)
This method creates an interval given two keys.

Parameters:
from - the lower bound
to - the upper bound
Returns:
the created interval

makeLeftOpen

public abstract KeyInterval<T> makeLeftOpen(KeyInterval<T> interval)
This method returns a new instance of KeyInterval which makes this interval opened from the left.

Parameters:
interval - the closed interval
Returns:
left-opened interval

max

public final T max(T first,
                   T second)
Return the maximum of the two values passed or the first one if they are equal.

Parameters:
first - the first key
second - the second key
Returns:
the maximum of the two values passed or the first one if they are equal

min

public final T min(T first,
                   T second)
Return the minimum of the two values passed or the first one if they are equal.

Parameters:
first - the first key
second - the second key
Returns:
the minimum of the two values passed or the first one if they are equal

isInBetween

public final boolean isInBetween(T key,
                                 T low,
                                 T up)
Finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in (low, up).

Parameters:
key - the key to be tested
low - the lower bound
up - the upper bound
Returns:
true if the low and the up keys equals; false if the key equals either the low or up keys

isInBetweenEQ

public final boolean isInBetweenEQ(T key,
                                   T low,
                                   T up)
finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in [low, up]

Parameters:
key - the key to be tested
low - the lower bound
up - the upper bound
Returns:
true if the low and the up keys equals; true if the key equals either the low or up keys

isInBetweenEQL

public final boolean isInBetweenEQL(T key,
                                    T low,
                                    T up)
Finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in [low, up)

Parameters:
key - the key to be tested
low - the lower bound
up - the upper bound
Returns:
true if the low and the up keys equals; true if the key equals the low bound but flase for the up keys equality

isInBetweenEQH

public final boolean isInBetweenEQH(T key,
                                    T low,
                                    T up)
Finds out, whether this key is inner the interval specified by the passed bounds - counting on the ring circle (module SIZE). key \in (low, up]

Parameters:
key - the key to be tested
low - the lower bound
up - the upper bound
Returns:
true if the low and the up keys equals; false if the key equals the low bound but; true for the up keys equality

intersect

public final boolean intersect(KeyInterval<T> first,
                               KeyInterval<T> second)
Return true if the two intervals intersect.

Parameters:
first - first interval
second - second interval
Returns:
true if the two intervals intersect