Class: ChangeMap

diffusion.datatypes.JSONDelta. ChangeMap

new ChangeMap()

An unmodifiable map describing the changes to a JSON value.

The JSONDelta#inserted method returns a ChangeMap describing the parts of the second JSON value not found in the first JSON value. Similarly, JSONDelta#removed returns a ChangeMap describing the parts of the first JSON value not found in the second JSON value.

The map contains an entry for each change, as follows:

  • The key is a JSON Pointer syntax reference locating the change in the complete value. Since a JSON value is a list of zero or more data items, the reference always begins with an array index. For example, the first part is identified by the JSON Pointer /0.
  • The value is part of the complete value. It is returned as a parsed value.

An error will be thrown if an invalid JSON pointer expression is passed to get, containsKey, descendants, or intersection. This only occurs if the expression does not start with / and is not empty.

Methods

containsKey(pointer) → {Boolean}

Determines if this change map contains an entry for a given JSON Pointer
Parameters:
Name Type Description
pointer String The JSON Pointer expression
Throws:
Error if pointer is an invalid JSON Pointer expression
Returns:
true if an entry exists, false if not
Type
Boolean

descendants(pointer) → {diffusion.datatypes.JSONDelta.ChangeMap}

Returns a view of the portion of this map whose keys are descendants of pointer. If pointer is contained in this map, it will be included in the result.
Parameters:
Name Type Description
pointer String the json pointer expression to derive descendants for
Throws:
Error if pointer is an invalid JSON Pointer expression
Returns:
changemap of descendant changes
Type
diffusion.datatypes.JSONDelta.ChangeMap

entrySet() → {Array}

Returns an array of map entries. Each entry is in the form of a key/value object pair.

The key is a JSON Pointer expression, in string form. The value will be parsed from the underlying diffusion.datatypes.JSON object.

Returns:
the entry array
Type
Array
Example
changeMap.entrySet().forEach(function(entry) {
    console.log(entry.key, entry.value);
});

get(pointer) → {*}

Retrieve a value from this change map, identified by a JSON Pointer.
Parameters:
Name Type Description
pointer String The JSON Pointer expression
Throws:
Error if pointer is an invalid JSON Pointer expression
Returns:
the change map value, if it exists, otherwise null
Type
*

intersection(pointer) → {diffusion.datatypes.JSONDelta.ChangeMap}

Returns a view of the portion of this map whose keys are descendants or parents of pointer. If pointer is contained in this map, it will be included in the result.

This method can be used to determine whether a structural delta affects a particular part of a JSON value. For example:

if (structuralDelta.removed().intersection("/contact/address").length) {
  // The structural delta removes elements that affect '/contact/address'.
}
if (structuralDelta.inserted().intersection("/contact/address").length) {
  // The structural delta inserts elements that affect '/contact/address'.
}

Parameters:
Name Type Description
pointer String the json pointer expression to derive intersection for
Throws:
Error if pointer is an invalid JSON Pointer expression
Returns:
changemap of intersection changes
Type
diffusion.datatypes.JSONDelta.ChangeMap