Package de.dlr.proseo.ui.gui.service
Class MapComparator
java.lang.Object
de.dlr.proseo.ui.gui.service.MapComparator
- All Implemented Interfaces:
Comparator<Object>
A class for comparing HashMap objects based on one or two specified keys
- Author:
- Ernst Melchinger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMapComparator(String key, Boolean up) Constructor that takes a key and a boolean argument for the sorting orderMapComparator(String key, String key2, Boolean up) Constructor that takes two keys and a boolean argument for the sorting order -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
Constructor Details
-
MapComparator
Constructor that takes a key and a boolean argument for the sorting order- Parameters:
key- the key to look for in compared hash mapsup- true, if the comparison is to be made in ascending order, false otherwise
-
MapComparator
Constructor that takes two keys and a boolean argument for the sorting order- Parameters:
key- the key to look for in compared hash mapskey2- the second key to look forup- true, if the comparison is to be made in ascending order, false otherwise
-
-
Method Details
-
compare
Compares two objects, checks whether they are instances of HashMap and then extracts the values associated with the specified keys from each HashMap.- Specified by:
comparein interfaceComparator<Object>- Parameters:
object1- the first object (HashMap) to compareobject2- the second object (HashMap) to compare- Returns:
- a negative value if the first object should be placed before the second object, a positive value if the first object should be placed after the second object, or zero if the objects are either not HashMaps, or null, or their keys neither integer nor string, or considered equal in terms of sorting
-