Export (0) Print
Expand All

Map Class [AX 2012]

The Map class allows you to associate one value (the key) with another value. Both the key and value can be any valid X++ type, including objects. The types of the key and the value are specified in the declaration of the map. The way in which maps are implemented means that access to the values is very fast.

class Map extends Object

Run On

Called

  MethodDescription
Gg911868.pubmethod(en-us,AX.60).gif cancelTimeOut Cancels a previous method call to the setTimeOut method. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif definitionString Returns a string that contains the definition of the map.
Gg911868.pubmethod(en-us,AX.60).gif domainSet Creates a set of the key (domain) values in a map.
Gg911868.pubmethod(en-us,AX.60).gif domainType Determines the type of the key (domain) values in a map.
Gg911868.pubmethod(en-us,AX.60).gif elements Returns the number of elements in the map.
Gg911868.pubmethod(en-us,AX.60).gif empty Determines whether the map contains any (key, value) pairs.
Gg911868.pubmethod(en-us,AX.60).gif equal Determines whether the specified object is equal to the current one. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif exists Determines whether a particular value exists as a key in the map.
Gg911868.pubmethod(en-us,AX.60).gif getEnumerator Creates an enumerator for the map which allows you to traverse the map.
Gg911868.pubmethod(en-us,AX.60).gif getTimeOutTimerHandle Returns the timer handle for the object. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif handle Retrieves the handle of the class of the object. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif insert Inserts an element (keyValue, valueValue pair) in the map.
Gg911868.pubmethod(en-us,AX.60).gif keySet Returns a set that contains the key values from a map.
Gg911868.pubmethod(en-us,AX.60).gif keyType Returns the type of the key values in a map.
Gg911868.pubmethod(en-us,AX.60).gif lookup Returns the value mapped to by a particular key value.
Gg911868.pubmethod(en-us,AX.60).gif new Creates a new map. (Overrides the new Method.)
Gg911868.pubmethod(en-us,AX.60).gif notify Releases the hold on an object that has called the wait method on this object. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif notifyAll Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif objectOnServer Determines whether the object is on a server. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif owner Returns the instance that owns the object. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif pack Serializes the current instance of the Map class.
Gg911868.pubmethod(en-us,AX.60).gif rangeSet Returns a set that contains the values (ranges) mapped to by the keys in a map.
Gg911868.pubmethod(en-us,AX.60).gif rangeType Determines the type of the values (ranges) mapped to by the keys in a map.
Gg911868.pubmethod(en-us,AX.60).gif remove Removes a (key, value) pair from a map.
Gg911868.pubmethod(en-us,AX.60).gif setTimeOut Sets up the scheduled execution of a specified method. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif toString Returns a description of the (key, value) pairs in the map. (Overrides the toString Method.)
Gg911868.pubmethod(en-us,AX.60).gif usageCount Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif valueSet Returns a set that contains the values mapped to by the keys in a map.
Gg911868.pubmethod(en-us,AX.60).gif valueType Returns the type of the values that are mapped to by the keys in a map.
Gg911868.pubmethod(en-us,AX.60).gif wait Pauses a process. (Inherited from Object.)
Gg911868.pubmethod(en-us,AX.60).gif xml Returns an XML string that represents the current object. (Overrides the xml Method.)
Gg911868.pubmethod(en-us,AX.60).gif Gg911868.static(en-us,AX.60).gif ::create Creates a map from the container that was obtained from a prior call to the Map.pack method.
Gg911868.pubmethod(en-us,AX.60).gif Gg911868.static(en-us,AX.60).gif ::createFromXML
Gg911868.pubmethod(en-us,AX.60).gif Gg911868.static(en-us,AX.60).gif ::equal Determines whether two maps are equal.
Top

Multiple keys can map to the same value, but one key can map to only one value at a time. If you add a (key, value) pair with an existing key value, it will replace the existing pair with that key value.

The (key, value) pairs in a map can be traversed using the MapEnumerator class.

The following example illustrates how to invert a map. It is only possible to invert a map if no value is mapped to by two different keys. Comparing the number of elements in the Map.keySet method and the Map.valueSet method checks this. Otherwise, the elements are traversed in the incoming map and inserted in the result map. The function that does the inversion, that is, the invertMap method, will work regardless of the types of the keys and values.

{ 
    Map example; 
  
    Map invertMap(map _mapToInvert) 
    { 
        MapEnumerator en; 
        Map result =  new Map( 
            _mapToInvert.valueType(), 
            _mapToInvert.keyType()); 
  
        if (_mapToInvert.keySet().elements()  
            != _mapToInvert.valueSet().elements()) 
        { 
            return null; 
        } 
        en = new MapEnumerator(_mapToInvert); 
        while (en.moveNext()) 
        { 
            result.insert(en.currentValue(), en.currentKey()); 
        } 
        return result; 
    } 
  
    ; 
  
    // Fill in a few values. 
    example = new Map(Types::Integer, Types::String); 
    example.insert (1, "one"); 
    example.insert (2, "two"); 
  
    print invertMap(example).toString(); 
    pause; 
  
    // Now two keys (2 and 3) map to the same value 
    // so can't create inverse map 
    example.insert (3, "two"); 
    if (!invertMap(example)) 
    { 
        print "Could not create the map"; 
    } 
    pause; 
}

Community Additions

ADD
Show:
© 2015 Microsoft