Expand all

ve.dm.AnnotationSet

Constructor

new ve.dm.AnnotationSet(store, [storeHashes]) #

Annotation set.

Parameters:

Name Type Attributes Description
store ve.dm.HashValueStore
storeHashes Array.<string> optional
Source:
Annotation set.

Methods

add(annotation, offset) #

Add an annotation to the set.

If the annotation is already present in the set, nothing happens.

The annotation will be inserted before the annotation that is currently at the given offset. If offset is negative, it will be counted from the end (i.e. offset -1 is the last item, -2 the second-to-last, etc.). If offset is out of bounds, the annotation will be added to the end of the set.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to add

offset number

Offset to add the annotation at

Source:
Add an annotation to the set.

addSet(set, [offset]) #

Add all annotations in the given set, removing any duplicates (including existing ones).

The offset calculation happens before duplicates are removed.

Parameters:

Name Type Attributes Description
set ve.dm.AnnotationSet

Set to add to the set

offset number optional

Offset at which to insert; defaults to the end of the set

Source:
Add all annotations in the given set, removing any duplicates (including existing ones).

clone() → {ve.dm.AnnotationSet} #

Get a clone.

Source:

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet
Get a clone.

compareTo(annotationSet) → {boolean} #

Check if the set contains the same annotations as another set.

Compares annotations by their comparable object value.

Parameters:

Name Type Description
annotationSet ve.dm.AnnotationSet

The annotationSet to compare this one to

Source:

Returns:

The annotations are the same

Type
boolean
Check if the set contains the same annotations as another set.

contains(annotation) → {boolean} #

Check whether a given annotation occurs in the set.

Annotations are compared by store hash.

Parameters:

Name Type Description
annotation ve.dm.Annotation
Source:

Returns:

There is an annotation in the set with the same hash as annotation

Type
boolean
Check whether a given annotation occurs in the set.

containsAllOf(set) → {boolean} #

Check whether the set contains all of the annotations in another set.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Set to compare the set with

Source:

Returns:

All annotations in set are also in the set

Type
boolean
Check whether the set contains all of the annotations in another set.

containsAnyOf(set) → {boolean} #

Check whether the set contains any of the annotations in another set.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Set to compare the set with

Source:

Returns:

There is at least one annotation in set that is also in the set

Type
boolean
Check whether the set contains any of the annotations in another set.

containsComparable(annotation) → {boolean} #

Check if the set contains an annotation comparable to the specified one.

getComparableObject is used to compare the annotations, and should return true if an annotation is found which is mergeable with the specified one.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to compare to

Source:

Returns:

At least one comparable annotation found

Type
boolean
Check if the set contains an annotation comparable to the specified one.

containsComparableForSerialization(annotation) → {boolean} #

FIXME T126031: Check if the set contains an annotation comparable to the specified one for the purposes of serialization.

This method uses getComparableObjectForSerialization which also includes HTML attributes.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to compare to

Source:

Returns:

At least one comparable annotation found

Type
boolean

FIXME T126031: Check if the set contains an annotation comparable to the specified one for the purposes of serialization.

containsHash(storeHash) → {boolean} #

Check whether a given store hash occurs in the set.

Parameters:

Name Type Description
storeHash string

Store hash of annotation

Source:

Returns:

There is an annotation in the set with this store hash

Type
boolean
Check whether a given store hash occurs in the set.

containsMatching(callback) → {boolean} #

Check if the set contains at least one annotation where a given property matches a given filter.

This is equivalent to (but more efficient than) !this.filter( .. ).isEmpty().

Parameters:

Name Type Description
callback function

Function that takes an annotation and returns boolean true to include

Source:
See:

Returns:

At least one matching annotation found

Type
boolean
Check if the set contains at least one annotation where a given property matches a given filter.

diffWith(set) → {ve.dm.AnnotationSet} #

Get the difference between the set and another set.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Other set

Source:

Returns:

New set containing all annotations that are in the set but not in set

Type
ve.dm.AnnotationSet
Get the difference between the set and another set.

equalsInOrder(set) → {boolean} #

Strictly compare two annotation sets for equality.

This method only considers two annotation sets to be equal if they contain exactly the same annotations (not just comparable, but with the same hash in the HashValueStore) in exactly the same order.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

The annotation set to compare this one to

Source:

Returns:

The annotation sets are equal

Type
boolean
Strictly compare two annotation sets for equality.

filter(callback, [returnBool]) → {ve.dm.AnnotationSet|boolean} #

Filter the set by an item property.

This returns a new set with all annotations in the set for which the callback returned true for.

Parameters:

Name Type Attributes Description
callback function

Function that takes an annotation and returns boolean true to include

returnBool boolean optional

For internal use only

Source:

Returns:

New set containing only the matching annotations

Type
ve.dm.AnnotationSet | boolean
Filter the set by an item property.

get([offset]) → {Array.<ve.dm.Annotation>|ve.dm.Annotation|undefined} #

Get an annotation or all annotations from the set.

set.get( 5 ) returns the annotation at offset 5, set.get() returns an array with all annotations in the entire set.

Parameters:

Name Type Attributes Description
offset number optional

If set, only get the annotation at the offset

Source:

Returns:

The annotation at offset, or an array of all annotations in the set

Type
Array.<ve.dm.Annotation> | ve.dm.Annotation | undefined
Get an annotation or all annotations from the set.

getAnnotationsByName(name) → {ve.dm.AnnotationSet} #

Get an annotation set containing only annotations within the set with a specific name.

Parameters:

Name Type Description
name string

Type name

Source:

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet
Get an annotation set containing only annotations within the set with a specific name.

getComparable(annotation) → {ve.dm.Annotation|null} #

Get the first annotation mergeable with the specified one

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to compare to

Source:

Returns:

First matching annotation

Type
ve.dm.Annotation | null
Get the first annotation mergeable with the specified one

getComparableAnnotations(annotation) → {ve.dm.AnnotationSet} #

Get an annotation set containing only annotations within the set which are comparable to a specific annotation.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to compare to

Source:

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet

Get an annotation set containing only annotations within the set which are comparable to a specific annotation.

getComparableAnnotationsFromSet(annotations) → {ve.dm.AnnotationSet} #

Get an annotation set containing only annotations within the set which are comparable to an annotation from another set.

Parameters:

Name Type Description
annotations ve.dm.AnnotationSet

Annotation set to compare to

Source:

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet

Get an annotation set containing only annotations within the set which are comparable to an annotation from another set.

getHash(offset) → {string} #

Get store hash from offset within annotation set.

Parameters:

Name Type Description
offset number

Offset within annotation set

Source:

Returns:

Store hash at specified offset

Type
string
Get store hash from offset within annotation set.

getHashes() → {Array.<string>} #

Get all store hashes.

Source:

Returns:

Store hashes

Type
Array.<string>
Get all store hashes.

getLength() → {number} #

Get the length of the set.

Source:

Returns:

The number of annotations in the set

Type
number
Get the length of the set.

getStore() → {ve.dm.HashValueStore} #

Get the hash-value store.

Source:

Returns:

Hash-value store

Type
ve.dm.HashValueStore
Get the hash-value store.

hasAnnotationWithName(name) → {boolean} #

Check if any annotations in the set have a specific name.

Parameters:

Name Type Description
name string

Type name

Source:

Returns:

Annotation of given type exists in the set

Type
boolean
Check if any annotations in the set have a specific name.

intersectWith(set) → {ve.dm.AnnotationSet} #

Get the intersection of the set with another set.

This requires annotations to be strictly equal. To find annotations which are comparable use the slower #getComparableAnnotationsFromSet with #addSet.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Other set

Source:

Returns:

New set containing all annotations that are both in the set and in set

Type
ve.dm.AnnotationSet
Get the intersection of the set with another set.

isEmpty() → {boolean} #

Check if the set is empty.

Source:

Returns:

The set is empty

Type
boolean
Check if the set is empty.

mergeWith(set) → {ve.dm.AnnotationSet} #

Merge another set into the set.

This returns a copy, the original set is not modified.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Other set

Source:

Returns:

Set containing all annotations in the set as well as all annotations in set

Type
ve.dm.AnnotationSet
Merge another set into the set.

offsetOf(annotation) → {number} #

Get the offset of a given annotation in the set.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to search for

Source:

Returns:

Offset of annotation in the set, or -1 if annotation is not in the set.

Type
number
Get the offset of a given annotation in the set.

offsetOfHash(storeHash) → {number} #

Get the offset of a given annotation in the set by store hash.

Parameters:

Name Type Description
storeHash string

Store hash of annotation to search for

Source:

Returns:

Offset of annotation in the set, or -1 if annotation is not in the set.

Type
number
Get the offset of a given annotation in the set by store hash.

push(annotation) #

Add an annotation at the end of the set.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to add

Source:
Add an annotation at the end of the set.

pushHash(storeHash) #

Add an annotation at the end of the set by store hash.

Parameters:

Name Type Description
storeHash string

Store hash of annotation to add

Source:
Add an annotation at the end of the set by store hash.

remove(annotation) #

Remove a given annotation from the set.

If the annotation isn't in the set, nothing happens.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to remove

Source:
Remove a given annotation from the set.

removeAll() #

Remove all annotations.

Source:
Remove all annotations.

removeAt(offset) #

Remove the annotation at a given offset.

Parameters:

Name Type Description
offset number

Offset to remove item at. If negative, the counts from the end, see add()

Source:

Throws:

Offset out of bounds.

Type
Error
Remove the annotation at a given offset.

removeHash(storeHash) #

Remove a given annotation from the set by store hash.

If the annotation isn't in the set, nothing happens.

Parameters:

Name Type Description
storeHash string

Store hash of annotation to remove

Source:
Remove a given annotation from the set by store hash.

removeNotInSet(set) #

Remove all annotations that are not also in a given other set from the set.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Set to intersect with the set

Source:
Remove all annotations that are not also in a given other set from the set.

removeSet(set) #

Remove all annotations in a given set from the set.

Annotations that aren't in the set are ignored.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

Set to remove from the set

Source:
Remove all annotations in a given set from the set.

reversed() → {ve.dm.AnnotationSet} #

Reverse the set.

This returns a copy, the original set is not modified.

Source:

Returns:

Copy of the set with the order reversed.

Type
ve.dm.AnnotationSet
Reverse the set.

withoutComparableSet(set) → {ve.dm.AnnotationSet} #

Filter out all annotations in this set which are comparable to those in another set

This returns a new set.

Parameters:

Name Type Description
set ve.dm.AnnotationSet

The AnnotationSet to filter out

Source:

Returns:

A new set without the comparable annotations

Type
ve.dm.AnnotationSet

Filter out all annotations in this set which are comparable to those in another set

This returns a new set.