The Progress.Collections.IEqualityComparer<T> interface provides an alternate implementation of HashCode() and Equals() to the map collection. It is used in situations where modifying a class is not possible, or the default implementations of HashCode() and/or Equals() of an object have undesirable behavior.

Public Properties

The interface has no public properties.

Public Methods

Equals( ) method (Map Collections) HashCode( ) method (IHashable)

Notes

  • Two objects that are considered the same, must return the same hash code. If obj1:Equals(obj2) returns TRUE, then obj2:Equals(obj1) must also return TRUE, and obj1:HashCode() must be the same as obj2:HashCode(). That implies that the same values should be used when identifying equality and generating the hash code. Note that different objects may return the same hash code.
  • The HashCode() and Equals() methods should not return the Unknown value (?). If they do, an ERROR is raised.
  • A user-defined class must implement the IEqualityComparer interface to be able to work with a HashMap collection that needs to use a custom equality comparer. In order to implement this interface, the “equality comparer” user-defined class will need to define the type argument as a specific class type, making it a comparer object for a specific type (or types that inherit that type).

Example

CLASS EmployeeEQComparer
  IMPLEMENTS Progress.Collections.IEqualityComparer<Employee>:

  METHOD PUBLIC INTEGER HashCode (element AS Employee):
    // Hash on the value of property EmployeeID
    RETURN hash-code(element:EmployeeID).
  END.

  METHOD PUBLIC LOGICAL Equals (person1 AS Employee, person2 AS Employee): 
 
    IF person1:EmployeeID = person2:EmployeeID THEN
      RETURN TRUE.
    RETURN FALSE.
  END.

END.

See also

<T> Generic type reference