Progress.Collections.IHashable is an interface which allows objects to be used as keys. The interface provides the implementation for generating the hash code (via the HashCode() method) and is also capable of identifying when a key is considered the same (via the Equals() method).

Public Properties

The interface has no public properties.

Public Methods

Equals( ) method HashCode( ) method (IHashable)

Notes

  • The ABL HASH-CODE function can be used in your implementation of HashCode() to generate a hash code for data of various data types.
  • You should override the Equals() method (available on any Progress.Lang.Object) in order to properly identify when a key is the same as another key.
  • 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 (?).

Example

The following is an example of a class named Employee, that implements the Progress.Collections.IHashable interface.

CLASS Employee IMPLEMENTS Progress.Collections.IHashable:

  CONSTRUCTOR Employee(pcID AS CHARACTER):
    EmployeeID = pcID.
  END.

  DEFINE PROPERTY EmployeeID AS CHARACTER GET. PRIVATE SET.

  METHOD PUBLIC INTEGER HashCode(). 
    // Hash on the value of property EmployeeID
    RETURN HASH-CODE(THIS-OBJECT:EmployeeID).
  END.

  METHOD PUBLIC OVERRIDE LOGICAL Equals(otherObj AS Progress.Lang.Object): 
    IF NOT VALID-OBJECT(otherObj) OR
      otherObj:GetClass() NE THIS-OBJECT:GetClass() THEN
      RETURN FALSE.

     // It’s up to the implementation to decide if case-sensitiveness
     // is required or not. This is case-insensitive.
     IF THIS-OBJECT:EmployeeID = CAST(otherObj, Employee):EmployeeID
     THEN
       RETURN TRUE.
     RETURN FALSE.
  END.
  
END.