Expand all

ve.dm.AnnotationSet

Constructor

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

Annotation set.

Parameters:

Name Type Attributes Default 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.

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet
Source:
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

Returns:

The annotations are the same

Type
boolean
Source:
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

Returns:

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

Type
boolean
Source:
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

Returns:

All annotations in set are also in the set

Type
boolean
Source:
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

Returns:

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

Type
boolean
Source:
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

Returns:

At least one comparable annotation found

Type
boolean
Source:
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

Returns:

At least one comparable annotation found

Type
boolean
Source:

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

Returns:

There is an annotation in the set with this store hash

Type
boolean
Source:
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

Returns:

At least one matching annotation found

Type
boolean
Source:
See:
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

Returns:

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

Type
ve.dm.AnnotationSet
Source:
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

Returns:

The annotation sets are equal

Type
boolean
Source:
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 Default Description
callback function

Function that takes an annotation and returns boolean true to include

returnBool boolean optional
false

For internal use only

Returns:

New set containing only the matching annotations

Type
ve.dm.AnnotationSet | boolean
Source:
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

Returns:

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

Type
Array.<ve.dm.Annotation> | ve.dm.Annotation | undefined
Source:
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

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet
Source:
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

Returns:

First matching annotation

Type
ve.dm.Annotation | null
Source:
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

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet
Source:

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

Returns:

Copy of annotation set

Type
ve.dm.AnnotationSet
Source:

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

Returns:

Store hash at specified offset

Type
string
Source:
Get store hash from offset within annotation set.

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

Get all store hashes.

Returns:

Store hashes

Type
Array.<string>
Source:
Get all store hashes.

getLength() → {number} #

Get the length of the set.

Returns:

The number of annotations in the set

Type
number
Source:
Get the length of the set.

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

Get the hash-value store.

Returns:

Hash-value store

Type
ve.dm.HashValueStore
Source:
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

Returns:

Annotation of given type exists in the set

Type
boolean
Source:
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

Returns:

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

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

isEmpty() → {boolean} #

Check if the set is empty.

Returns:

The set is empty

Type
boolean
Source:
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

Returns:

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

Type
ve.dm.AnnotationSet
Source:
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

Returns:

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

Type
number
Source:
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

Returns:

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

Type
number
Source:
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()

Throws:

Offset out of bounds.

Type
Error
Source:
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.

Returns:

Copy of the set with the order reversed.

Type
ve.dm.AnnotationSet
Source:
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

Returns:

A new set without the comparable annotations

Type
ve.dm.AnnotationSet
Source:

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

This returns a new set.