Package net.sf.saxon.ma.map
Class DictionaryMap
- java.lang.Object
-
- net.sf.saxon.ma.map.MapItem
-
- net.sf.saxon.ma.map.DictionaryMap
-
- All Implemented Interfaces:
Callable
,Function
,GroundedValue
,Item
,Sequence
public class DictionaryMap extends MapItem
A simple implementation of MapItem where the strings are keys, and modification is unlikely. This implementation is used in a number of cases where it can be determined that it is suitable, for example when parsing JSON input, or when creating a fixed map to use in an options argument.
-
-
Constructor Summary
Constructors Constructor Description DictionaryMap()
Create an empty dictionary, to which entries can be added usinginitialPut(String, GroundedValue)
, provided this is done before the map is exposed to the outside world.DictionaryMap(int size)
Create an empty dictionary, to which entries can be added usinginitialPut(String, GroundedValue)
, provided this is done before the map is exposed to the outside world.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MapItem
addEntry(AtomicValue key, GroundedValue value)
Create a new map containing the existing entries in the map plus an additional entry, without modifying the original.boolean
conforms(PlainType keyType, SequenceType valueType, TypeHierarchy th)
Ask whether the map conforms to a given map typeGroundedValue
get(AtomicValue key)
Get an entry from the MapItemType
getItemType(TypeHierarchy th)
Get the type of the map.UType
getKeyUType()
Get the lowest common item type of the keys in the mapvoid
initialAppend(java.lang.String key, GroundedValue value)
During initial construction of the map, append a value to a possibly existing key-value pairvoid
initialPut(java.lang.String key, GroundedValue value)
During initial construction of the map, add a key-value pairboolean
isEmpty()
Ask whether the map is emptyAtomicIterator
keys()
Get the set of all key values in the map.java.lang.Iterable<KeyValuePair>
keyValuePairs()
Get the set of all key-value pairs in the mapMapItem
remove(AtomicValue key)
Remove an entry from the mapint
size()
Get the size of the map-
Methods inherited from class net.sf.saxon.ma.map.MapItem
atomize, call, deepEquals, effectiveBooleanValue, export, getAnnotations, getArity, getDescription, getFunctionItemType, getFunctionName, getGenre, getItemTypeOfSequence, getOperandRoles, getSerialNumber, getTypedValue, getUnicodeStringValue, isArray, isKnownToConform, isMap, isTrustedResultType, itemAt, makeNewContext, mapToString, toShortString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.om.Function
isSequenceVariadic
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
getLength, getStringValue, head, isStreamed, iterate, reduce, subsequence
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Constructor Detail
-
DictionaryMap
public DictionaryMap()
Create an empty dictionary, to which entries can be added usinginitialPut(String, GroundedValue)
, provided this is done before the map is exposed to the outside world.
-
DictionaryMap
public DictionaryMap(int size)
Create an empty dictionary, to which entries can be added usinginitialPut(String, GroundedValue)
, provided this is done before the map is exposed to the outside world.- Parameters:
size
- estimated final size of the dictionary
-
-
Method Detail
-
initialPut
public void initialPut(java.lang.String key, GroundedValue value)
During initial construction of the map, add a key-value pair- Parameters:
key
- the keyvalue
- the corresponding value
-
initialAppend
public void initialAppend(java.lang.String key, GroundedValue value)
During initial construction of the map, append a value to a possibly existing key-value pair- Parameters:
key
- the keyvalue
- the corresponding value
-
get
public GroundedValue get(AtomicValue key)
Get an entry from the Map
-
size
public int size()
Get the size of the map
-
isEmpty
public boolean isEmpty()
Ask whether the map is empty
-
keys
public AtomicIterator keys()
Get the set of all key values in the map.
-
keyValuePairs
public java.lang.Iterable<KeyValuePair> keyValuePairs()
Get the set of all key-value pairs in the map- Specified by:
keyValuePairs
in classMapItem
- Returns:
- an iterable containing all the key-value pairs
-
addEntry
public MapItem addEntry(AtomicValue key, GroundedValue value)
Create a new map containing the existing entries in the map plus an additional entry, without modifying the original. If there is already an entry with the specified key, this entry is replaced by the new entry.
-
remove
public MapItem remove(AtomicValue key)
Remove an entry from the map
-
conforms
public boolean conforms(PlainType keyType, SequenceType valueType, TypeHierarchy th)
Ask whether the map conforms to a given map type
-
getItemType
public ItemType getItemType(TypeHierarchy th)
Get the type of the map. This method is used largely for diagnostics, to report the type of a map when it differs from the required type.- Specified by:
getItemType
in classMapItem
- Parameters:
th
- the type hierarchy cache- Returns:
- the type of this map
-
getKeyUType
public UType getKeyUType()
Get the lowest common item type of the keys in the map- Specified by:
getKeyUType
in classMapItem
- Returns:
- the most specific type to which all the keys belong. If the map is empty, return UType.VOID
-
-