net.sf.molae.pipe.sorted
Class KeyComparator<K>

java.lang.Object
  extended by net.sf.molae.pipe.sorted.KeyComparator<K>
All Implemented Interfaces:
Comparator<Map.Entry<K,?>>

public final class KeyComparator<K>
extends Object
implements Comparator<Map.Entry<K,?>>

Applies a comparator to the key of map entries.


Constructor Summary
KeyComparator(Comparator<? super K> base)
          Constructs a KeyComparator object.
 
Method Summary
 int compare(Map.Entry<K,?> o1, Map.Entry<K,?> o2)
          Applies the underlying comparator to the key of the specified map entry.
 boolean equals(Object obj)
          Compares the specified object with this collection for equality.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyComparator

public KeyComparator(Comparator<? super K> base)
Constructs a KeyComparator object.

Parameters:
base - The comparator to apply to the keys.
Method Detail

compare

public int compare(Map.Entry<K,?> o1,
                   Map.Entry<K,?> o2)
Applies the underlying comparator to the key of the specified map entry.

Specified by:
compare in interface Comparator<Map.Entry<K,?>>
Throws:
ClassCastException - if either parameter is not a map Map.Entry or if the base comparator cannot compare the keys of the map entries.
NullPointerException - if either entry is null or if either key is null and the base comparator does not accept null values.

equals

public boolean equals(Object obj)
Compares the specified object with this collection for equality. Returns true, iff the parameter is a KeyComparator and the base comparators are equal.

Specified by:
equals in interface Comparator<Map.Entry<K,?>>
Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if the specified Object is equal to this comparator