Skip to content

PrintableDict

Jas edited this page Mar 9, 2017 · 2 revisions

PrintableDict

This object extends the standard Dict object but adds the following support:

  • toString: Prints the dictionary contents correctly, similar to a HashMap
  • getSize: Returns the number of entries in the dictionary, similar to kdb+ count

As this object is a sub-class of Dict, it can be used anywhere that Dict would normally be used. For example, KdbDict.convertToDict returns a PrintableDict.

Example Usage

The standard Dict constructor is overridden and can be used:

public Dict newDict() {
    Object[] keys = { 1, 2, 3 };
    Object[] vals = { "abc", "def", "ghi" };

    return new PrintableDict(keys, vals);
}

There is also a new constructor PrintableDict(Dict) which converts a standard Dict:

public Dict newPrintableFromDict() {
    Object[] keys = { 1, 2, 3 };
    Object[] vals = { "abc", "def", "ghi" };

    return new PrintableDict(new Dict(keys, vals));
}
Clone this wiki locally