Class MapComparator

java.lang.Object
de.dlr.proseo.ui.gui.service.MapComparator
All Implemented Interfaces:
Comparator<Object>

public class MapComparator extends Object implements Comparator<Object>
A class for comparing HashMap objects based on one or two specified keys
Author:
Ernst Melchinger
  • Field Details

    • key

      String key
      the first key to compare
    • key2

      String key2
      the second key to compare
    • up

      the sorting order
  • Constructor Details

    • MapComparator

      public MapComparator(String key, Boolean up)
      Constructor that takes a key and a boolean argument for the sorting order
      Parameters:
      key - the key to look for in compared hash maps
      up - true, if the comparison is to be made in ascending order, false otherwise
    • MapComparator

      public MapComparator(String key, String key2, Boolean up)
      Constructor that takes two keys and a boolean argument for the sorting order
      Parameters:
      key - the key to look for in compared hash maps
      key2 - the second key to look for
      up - true, if the comparison is to be made in ascending order, false otherwise
  • Method Details

    • compare

      public int compare(Object object1, Object object2)
      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:
      compare in interface Comparator<Object>
      Parameters:
      object1 - the first object (HashMap) to compare
      object2 - 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