Class AbstractFixedMap
- All Implemented Interfaces:
Iterable<KeyValuePair>,Callable,FunctionItem,GroundedValue,Item,Sequence
- Direct Known Subclasses:
FixedMap,FixedMapWithStringKeys
The implementation is based on an array of keys, an array of corresponding values,
and a mutable Java java.util.HashMap (but encapsulated
so no mutation can take place after the map has been built) that maps atomic match keys
to integer positions in the array. If put or remove operations
are subsequently attempted, the map is copied to a different implementation structure
that supports functional modification.
The underlying implementation uses an instance of HashMap<AtomicMatchKey, KeyValuePair>
For many data types this means that the key is held twice, once as the key, and once as part
of the value. The reason for this is that the keys() function needs to return
the original keys as supplied, complete with type annotation, which would not (always) have
the same equality semantics. The AtomicMatchKey is computed from the actual key
and in some cases is simply a wrapper with a different equals() method.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.sf.saxon.ma.map.MapItem
MapItem.KeyIterator -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMap<AtomicMatchKey, Integer> protected GroundedValue[]Fields inherited from class net.sf.saxon.ma.map.MapWithTypeCache
knownKeyType, knownValueTypeFields inherited from class net.sf.saxon.ma.map.MapItem
mapConstructorDuplicatesAction, xslMapDuplicatesAction, xslRecordDuplicatesAction -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidEnsure that an index exists, creating it if necessary.get(AtomicValue key) Get an entry from the Mapstatic GeneralMapBuildergetBuilder(int specVersion) Factory method to get a MapBuilder which can be used to construct an instance of aAbstractFixedMapprotected abstract AtomicValuegetKey(int position) Get the key at a given offset.static intgetOffset(HashMap<AtomicMatchKey, Integer> index, AtomicMatchKey key) Get the offset in the index of a given key, or -1 if the key is not present.intgetPosition(AtomicValue key) Get the offset in the index of a given key, or -1 if the key is not present.protected GroundedValuegetValue(int position) Get the value at a given offset.iterator()Return an iterator of key-value pairs.Get the content of the map as an iterable collection of key value pairsput(AtomicValue key, GroundedValue value) Create a new map containing the existing entries in the map plus an additional entry, without modifying the original.static booleanputOffsetIfAbsent(HashMap<AtomicMatchKey, Integer> index, AtomicMatchKey key, int value) Put an entry in the index if the key is currently absentremove(AtomicValue key) Remove an entry from the mapintsize()Get the size of the maptoString()Returns a string representation of the object.Methods inherited from class net.sf.saxon.ma.map.MapWithTypeCache
conforms, setKnownTypeMethods inherited from class net.sf.saxon.ma.map.MapItem
atomize, call, deepEqual40, deepEquals, effectiveBooleanValue, entries, export, followingKeyValuePairs, getAnnotations, getArity, getDescription, getFunctionItemType, getFunctionName, getGenre, getItemType, getItemTypeOfSequence, getOperandRoles, getSpecVersion, getTypedValue, getU, getUnicodeStringValue, getWithPlan, isArray, isEmpty, isKnownToConform, isMap, isTrustedResultType, itemAt, keys, makeNewContext, mapToString, precedingKeyValuePairs, setSpecVersion, toShortStringMethods inherited from class net.sf.saxon.ma.MapOrArray
obtainRootJNodeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.om.FunctionItem
isSequenceVariadicMethods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materializeMethods inherited from interface net.sf.saxon.om.Item
getLabel, getLength, getStringValue, head, isStreamed, iterate, reduce, subsequenceMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Field Details
-
values
-
index
-
-
Constructor Details
-
AbstractFixedMap
public AbstractFixedMap()
-
-
Method Details
-
getBuilder
Factory method to get a MapBuilder which can be used to construct an instance of aAbstractFixedMap- Returns:
- a class for building fixed maps
-
get
Get an entry from the Map -
getOffset
Get the offset in the index of a given key, or -1 if the key is not present. Done this way for C# transpilation (maps with primitive int values work differently...)- Parameters:
index- the index of offsetskey- the wanted key- Returns:
- the offset in the index, or -1 if absent
-
putOffsetIfAbsent
public static boolean putOffsetIfAbsent(HashMap<AtomicMatchKey, Integer> index, AtomicMatchKey key, int value) Put an entry in the index if the key is currently absent- Parameters:
index- the index of offsetskey- the new keyvalue- the new value- Returns:
- true if an entry was added, false if the key was already present
-
getPosition
Get the offset in the index of a given key, or -1 if the key is not present.- Parameters:
key- the wanted key- Returns:
- the offset in the index, or -1 if absent
-
ensureIndexed
protected void ensureIndexed()Ensure that an index exists, creating it if necessary. In many cases an index is only created on the first call onget(AtomicValue). This is because in scenarios such as JSON transformation there may be many maps generated during JSON parsing that are never referenced, or that are copied directly to the serialized output without ever being accessed by key. -
size
public int size()Get the size of the map -
getKey
Get the key at a given offset. This method is provided for use by subclasses, which can store the actual key in different ways.- Parameters:
position- the offset (sibling position within the ordered map) of the required key- Returns:
- the key at the specified position
-
getValue
Get the value at a given offset.- Parameters:
position- the offset (sibling position within the ordered map) of the required key- Returns:
- the key at the specified position
-
keyValuePairs
Get the content of the map as an iterable collection of key value pairs- Specified by:
keyValuePairsin classMapItem- Returns:
- an iterable collection of key value pairs
-
iterator
Return an iterator of key-value pairs.- Specified by:
iteratorin interfaceIterable<KeyValuePair>- Returns:
- an Iterator of key-value pairs.
-
put
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
Remove an entry from the map -
toString
Returns a string representation of the object.
-