public class XdmMap extends XdmFunctionItem
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(java.lang.Object key)
Returns true if this map contains a mapping for the specified
key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the
specified value.
|
java.util.Set<java.util.Map.Entry<XdmAtomicValue,XdmValue>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
XdmValue |
get(java.lang.Object 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 a list.
|
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.
|
void |
putAll(java.util.Map<? extends XdmAtomicValue,? extends XdmValue> m)
Copies all of the mappings from the specified map to this map
(optional operation).
|
XdmValue |
remove(java.lang.Object key)
Removes the mapping for a key from this map if it is present
(optional operation).
|
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 view of the values contained in this map. |
call, getArity, getName, getSystemFunction, isAtomicValue
getStringValue, size, wrapItem
append, itemAt, iterator, makeSequence, makeValue, setValue, toString, 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(java.lang.Object key)
key
- key whose presence in this map is to be testedjava.lang.ClassCastException
- if the key is of an inappropriate type for
this map
(optional)java.lang.NullPointerException
- if the specified key is null and this map
does not permit null keys
(optional)public boolean containsValue(java.lang.Object value)
This implementation always throws UnsupportedOperationException.
value
- value whose presence in this map is to be testedjava.lang.ClassCastException
- if the value is of an inappropriate type for
this map
(optional)java.lang.NullPointerException
- if the specified value is null and this
map does not permit null values
(optional)public XdmValue get(java.lang.Object key)
null
if this map contains no mapping for the key.
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.null
if this map contains no mapping for the keyjava.lang.ClassCastException
- if the key is of an inappropriate type for
this map (in this case, XdmAtomicValue)
(optional)java.lang.NullPointerException
- if the specified key is null
(optional)public XdmValue remove(java.lang.Object key)
UnsupportedOperationException
.key
- key whose mapping is to be removed from the mapjava.lang.UnsupportedOperationException
- if the remove operation
is not supported by this mappublic void putAll(java.util.Map<? extends XdmAtomicValue,? extends XdmValue> m)
UnsupportedOperationException
.m
- mappings to be stored in this mapjava.lang.UnsupportedOperationException
- if the putAll operation
is not supported by this mappublic java.util.Collection<XdmValue> values()
Collection
view of the values contained in this map.
The collection is backed by the map, so changes to the map are
reflected in the collection, and vice-versa. If the map is
modified while an iteration over the collection is in progress
(except through the iterator's own remove operation),
the results of the iteration are undefined. The collection
supports element removal, which removes the corresponding
mapping from the map, via the Iterator.remove,
Collection.remove, removeAll,
retainAll and clear operations. It does not
support the add or addAll operations.public java.util.Set<java.util.Map.Entry<XdmAtomicValue,XdmValue>> entrySet()
Set
view of the mappings 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-2018 Saxonica Limited. All rights reserved.