Saxon.Api

 

 

Saxon.Api

Class XdmMap


public class XdmMap
extends XdmFunctionItem

The class XdmMap represents a map item in an XPath 3.1 sequence: this is a new kind of item in the XDM data model. A map is a list of zero or more entries, each of which is a pair comprising a key (which is an atomic value) and a value (which is an arbitrary value).

Constructor Summary

XdmMap ()

Create an empty XdmMap

 

Property Summary

 int Size

Get the number of entries in the map

 

Method Summary

 Dictionary<XdmAtomicValueXdmValue> AsDictionary()

Return a corresponding .NET Dictionary collection of keys and values.

 bool ContainsKey(XdmAtomicValue key)

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.Equals(k)). (There can be at most one such mapping.)

 HashSet<DictionaryEntry> EntrySet()

Returns a HashSet view of the mappings contained in this map.

 XdmValue Get(XdmAtomicValue key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

 XdmValue Get(string key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

 XdmValue Get(long key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

 bool IsEmpty()

Ask whether the XdmMap is empty

 HashSet<XdmAtomicValue> KeySet()

Get the keys present in the map in the form of a set.

static XdmMap MakeMap(IDictionary input)

Static factory method to construct an XDM map by converting each entry in a supplied generic collection of key/value pairs; IDictionary. The keys in the Dictionary must be convertible to XDM atomic values using the XdmAtomicValue.MakeAtomicValue(Object) method. The associated values must be convertible to XDM sequences using the XdmValue.MakeValue(Object) method.

 XdmMap Put(XdmAtomicValue key, XdmValue value)

Create a new map containing an additional (key, value) pair. If there is an existing entry with the same key, it is removed.

 XdmMap Remove(XdmAtomicValue key)

Create a new map in which the entry for a given key has been removed. If there is no entry with the same key, the new map has the same content as the old (it may or may not be the same .NET object)

 ICollection Values()

Returns a Collection containing the values found in this map.

 

Constructor Detail

XdmMap

public XdmMap()

Create an empty XdmMap

Property Detail

Size

public int Size {get; }

Get the number of entries in the map

(Note that the XdmValue.Count method returns 1 (one), because an XDM map is an item.)

Method Detail

AsDictionary

public Dictionary<XdmAtomicValueXdmValue> AsDictionary()

Return a corresponding .NET Dictionary collection of keys and values.

Returns:

A mutable Dictionary from atomic values to (sequence) values, containing the same entries as this map

ContainsKey

public bool ContainsKey(XdmAtomicValue key)

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.Equals(k)). (There can be at most one such mapping.)

Parameters:

key - the key whose presence in this map is to be tested

Returns:

true if this map contains a mapping for the specified key

EntrySet

public HashSet<DictionaryEntry> EntrySet()

Returns a HashSet view of the mappings contained in this map.

Returns:

a set view of the mappings contained in this map

Get

public XdmValue Get(XdmAtomicValue key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters:

key - the key whose associated value is to be returned. If this is not an XdmAtomicValue, the method attempts to construct an XdmAtomicValue using the method XdmAtomicValue.MakeAtomicValue(Object); it is therefore possible to pass a simple key such as a string or integer.

Returns:

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Get

public XdmValue Get(string key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters:

key - the key whose associated value is to be returned.

Returns:

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Get

public XdmValue Get(long key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters:

key - the key whose associated value is to be returned.

Returns:

the value to which the specified key is mapped, or null if this map contains no mapping for the key

IsEmpty

public bool IsEmpty()

Ask whether the XdmMap is empty

Returns:

Returns true if this map contains no key-value pairs, that is if the Size property is zero.

KeySet

public HashSet<XdmAtomicValue> KeySet()

Get the keys present in the map in the form of a set.

Returns:

a set of the keys present in this map, with no defined ordering.

MakeMap

public static XdmMap MakeMap(IDictionary input)

Static factory method to construct an XDM map by converting each entry in a supplied generic collection of key/value pairs; IDictionary. The keys in the Dictionary must be convertible to XDM atomic values using the XdmAtomicValue.MakeAtomicValue(Object) method. The associated values must be convertible to XDM sequences using the XdmValue.MakeValue(Object) method.

Parameters:

input - the supplied map

Returns:

the resulting XdmMap

Put

public XdmMap Put(XdmAtomicValue key,
XdmValue value)

Create a new map containing an additional (key, value) pair. If there is an existing entry with the same key, it is removed.

Parameters:

key - The key of the new entry.
value - The value part of the new entry.

Returns:

A new map containing the additional entry (or replaced entry). The original map is unchanged.

Remove

public XdmMap Remove(XdmAtomicValue key)

Create a new map in which the entry for a given key has been removed. If there is no entry with the same key, the new map has the same content as the old (it may or may not be the same .NET object)

Parameters:

key - The key of the entry that is to be removed

Returns:

A map without the specified entry. The original map is unchanged.

Values

public ICollection Values()

Returns a Collection containing the values found in this map.

Returns:

A collection of the values found in this map, that is, the value parts of the key-value pairs. The result may contain duplicates, and the order of results is unpredictable.