public class XdmMap extends XdmFunctionItem
An XdmMap is immutable.
As originally issued in Saxon 9.8, this class implemented the Map
interface.
It no longer does so, because it was found that the methods XdmItem.size()
, put(XdmAtomicValue, XdmValue)
,
and remove(net.sf.saxon.s9api.XdmAtomicValue)
did not adhere to the semantic contract of that interface. Instead, it is now
possible to obtain a view of this object as an immutable Java Map
by calling the
method asImmutableMap()
. See bug 3824.
Constructor and Description |
---|
XdmMap()
Create an empty XdmMap
|
XdmMap(java.util.Map<? extends XdmAtomicValue,? extends XdmValue> map)
Create an XdmMap supplying the entries in the form of a Java Map,
where the keys and values in the Java Map are XDM values
|
XdmMap(MapItem map)
Create an XdmMap whose underlying value is a MapItem
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<XdmAtomicValue,XdmValue> |
asImmutableMap()
Return this map as an immutable instance of
Map |
java.util.Map<XdmAtomicValue,XdmValue> |
asMap()
Return a mutable Java Map containing the same entries as this map.
|
void |
clear()
Removes all of the mappings from this map (optional operation).
|
boolean |
containsKey(XdmAtomicValue key)
Returns true if this map contains a mapping for the specified
key.
|
java.util.Set<java.util.Map.Entry<XdmAtomicValue,XdmValue>> |
entrySet()
Returns a
Set of the key-value pairs contained in this map. |
XdmValue |
get(double key)
Returns the value to which the specified double-valued 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 integer-valued key is mapped,
or
null if this map contains no mapping for the key. |
XdmValue |
get(java.lang.String key)
Returns the value to which the specified string-valued key is mapped,
or
null if this map contains no mapping for the key. |
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. |
MapItem |
getUnderlyingValue()
Get the underlying implementation object representing the value.
|
boolean |
isEmpty()
Returns true if this map contains no key-value mappings.
|
java.util.Set<XdmAtomicValue> |
keySet()
Get the keys present in the map in the form of an unordered set.
|
static XdmMap |
makeMap(java.util.Map input)
Static factory method to construct an XDM map by converting each entry
in a supplied Java map.
|
int |
mapSize()
Get the number of entries in the map
|
XdmMap |
put(XdmAtomicValue key,
XdmValue value)
Create a new map containing an additional (key, value) pair.
|
XdmMap |
remove(XdmAtomicValue key)
Create a new map in which the entry for a given key has been removed.
|
java.util.Collection<XdmValue> |
values()
Returns a
Collection containing the values found in this map,
that is, the value parts of the key-value pairs. |
asFunction, asStep, call, getArity, getName, getSystemFunction, isAtomicValue
getStringValue, matches, size, stream, wrapItem, wrapItem, wrapItem
append, documentOrder, fromGroundedValue, itemAt, iterator, makeSequence, makeValue, select, setValue, toString, wrap, wrap
public XdmMap()
public XdmMap(MapItem map)
map
- the MapItem to be encapsulatedpublic XdmMap(java.util.Map<? extends XdmAtomicValue,? extends XdmValue> map)
map
- a Java map whose entries are the (key, value) pairspublic MapItem getUnderlyingValue()
getUnderlyingValue
in class XdmItem
public int mapSize()
XdmItem.size()
method returns 1 (one),
because an XDM map is an item.)public XdmMap put(XdmAtomicValue key, XdmValue value)
public XdmMap remove(XdmAtomicValue key)
public java.util.Set<XdmAtomicValue> keySet()
public java.util.Map<XdmAtomicValue,XdmValue> asImmutableMap()
Map
Map
backed by this map.
Methods such as remove(net.sf.saxon.s9api.XdmAtomicValue)
and put(net.sf.saxon.s9api.XdmAtomicValue, net.sf.saxon.s9api.XdmValue)
applied to the result will
always throw UnsupportedOperationException
.public java.util.Map<XdmAtomicValue,XdmValue> asMap()
public void clear()
java.lang.UnsupportedOperationException
- if the clear operation
is not supported by this mappublic boolean isEmpty()
public boolean containsKey(XdmAtomicValue key)
key
- key whose presence in this map is to be testedpublic XdmValue get(XdmAtomicValue key)
null
if this map contains no mapping for the key.key
- the key whose associated value is to be returned.null
if this map contains no mapping for the keyjava.lang.ClassCastException
- if the supplied key cannot be converted to an XdmAtomicValuejava.lang.NullPointerException
- if the supplied key is nullpublic XdmValue get(java.lang.String key)
null
if this map contains no mapping for the key. This is a convenience
method to save the trouble of converting the String to an XdmAtomicValue
.key
- the key whose associated value is to be returned. This is treated
as an instance of xs:string
(which will also match
entries whose key is xs:untypedAtomic
or xs:anyURI
)null
if this map contains no mapping for the keyjava.lang.NullPointerException
- if the supplied key is nullpublic XdmValue get(long key)
null
if this map contains no mapping for the key. This is a convenience
method to save the trouble of converting the integer to an XdmAtomicValue
.key
- the key whose associated value is to be returned. This is treated
as an instance of xs:integer
(which will also match
entries whose key belongs to another numeric type)null
if this map contains no mapping for the keyjava.lang.NullPointerException
- if the supplied key is nullpublic XdmValue get(double key)
null
if this map contains no mapping for the key. This is a convenience
method to save the trouble of converting the double to an XdmAtomicValue
.key
- the key whose associated value is to be returned. This is treated
as an instance of xs:double
(which will also match
entries whose key belongs to another numeric type)null
if this map contains no mapping for the keyjava.lang.NullPointerException
- if the supplied key is nullpublic java.util.Collection<XdmValue> values()
Collection
containing the values found in this map,
that is, the value parts of the key-value pairs.public java.util.Set<java.util.Map.Entry<XdmAtomicValue,XdmValue>> entrySet()
Set
of the key-value pairs contained in this map.public static XdmMap makeMap(java.util.Map input) throws java.lang.IllegalArgumentException
XdmAtomicValue.makeAtomicValue(Object)
method. The associated values must be convertible to XDM sequences
using the XdmValue.makeValue(Object)
method.input
- the supplied mapjava.lang.IllegalArgumentException
- if any value in the input map cannot be converted
to a corresponding XDM value.Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.