Using Generic JADE Dictionary Methods
JADE enables you to write generic dictionary methods that receive and pass on KeyType parameters in dictionary classes when no keys are defined. For example, JADE implements the
includesKey(keys: KeyType): Boolean; begin return getAtKey(keys) <> null; end;
When a JADE method with a KeyType formal parameter is compiled in a dictionary class in which no keys are defined, a variable key list is assumed.
The following is an example of a method that could be defined at the
getAtKeyGeqOrLast(keys: KeyType): MemberType; vars entry : MemberType; begin entry := getAtKeyGeq(keys); if entry = null then // If not found, return the last entry in the dictionary entry := last; endif; return entry; end;
Although this getAtKeyGeqOrLast method is a generic method defined in an abstract dictionary class that has no defined keys, it could be called using a reference to a dictionary type with defined keys. This enables the compiler to perform full type-checking on the keys.
In the following example, the CustomerByNameDict dictionary has a single string key. The actual parameter in the call in this example can be fully type-checked by the compiler.
vars customerDict : CustomerByNameDict; cust : Customer; begin ... cust := customerDict.getAtKeyGeqOrLast("Wallace"); ... end;
See also "Defining and Using External Dictionary Methods" and "Variable Parameter List Considerations", earlier in this chapter.