jenkins-bot has submitted this change and it was merged.

Change subject: Rename index to offset in AnnotationSet
......................................................................


Rename index to offset in AnnotationSet

To avoid confusion between IV store indexes and the index
within the set, rename them to storeIndex and offset.

Change-Id: Ic7d741bd5d39240d63fdc04a2df45658a64441de
---
M modules/ve/dm/ve.dm.AnnotationSet.js
M modules/ve/test/dm/ve.dm.AnnotationSet.test.js
2 files changed, 43 insertions(+), 43 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js 
b/modules/ve/dm/ve.dm.AnnotationSet.js
index 5b2dc30..94e8e12 100644
--- a/modules/ve/dm/ve.dm.AnnotationSet.js
+++ b/modules/ve/dm/ve.dm.AnnotationSet.js
@@ -10,12 +10,12 @@
  *
  * @constructor
  * @param {ve.dm.IndexValueStore} store Index-value store
- * @param {number[]} [indexes] Array of indexes into the store
+ * @param {number[]} [indexes] Array of store indexes
  */
-ve.dm.AnnotationSet = function VeDmAnnotationSet( store, indexes ) {
+ve.dm.AnnotationSet = function VeDmAnnotationSet( store, storeIndexes ) {
        // Parent constructor
        this.store = store;
-       this.storeIndexes = indexes || [];
+       this.storeIndexes = storeIndexes || [];
 };
 
 /* Methods */
@@ -82,17 +82,17 @@
 /**
  * Get an annotation or all annotations from the set.
  *
- * set.get( 5 ) returns the annotation at index 5, set.get() returns an array 
with all annotations
+ * set.get( 5 ) returns the annotation at offset 5, set.get() returns an array 
with all annotations
  * in the entire set.
  *
  * @method
- * @param {number} [index] If set, only get the annotation at the index
- * @returns {ve.dm.Annotation[]|ve.dm.Annotation|undefined} The annotation at 
index, or an array of all
+ * @param {number} [offset] If set, only get the annotation at the offset
+ * @returns {ve.dm.Annotation[]|ve.dm.Annotation|undefined} The annotation at 
offset, or an array of all
  *  annotations in the set
  */
-ve.dm.AnnotationSet.prototype.get = function ( index ) {
-       if ( index !== undefined ) {
-               return this.getStore().value( this.getIndex( index ) );
+ve.dm.AnnotationSet.prototype.get = function ( offset ) {
+       if ( offset !== undefined ) {
+               return this.getStore().value( this.getIndex( offset ) );
        } else {
                return this.getStore().values( this.getIndexes() );
        }
@@ -145,18 +145,18 @@
  * @returns {boolean} There is an annotation in the set with the same hash as 
annotation
  */
 ve.dm.AnnotationSet.prototype.contains = function ( annotation ) {
-       return this.indexOf( annotation ) !== -1;
+       return this.offsetOf( annotation ) !== -1;
 };
 
 /**
  * Check whether a given store index occurs in the set.
  *
  * @method
- * @param {number} annotation Index of annotation in the store
+ * @param {number} storeIndex Store index of annotation
  * @returns {boolean} There is an annotation in the set with this store index
  */
-ve.dm.AnnotationSet.prototype.containsIndex = function ( index ) {
-       return ve.indexOf( index , this.getIndexes() ) !== -1;
+ve.dm.AnnotationSet.prototype.containsIndex = function ( storeIndex ) {
+       return ve.indexOf( storeIndex, this.getIndexes() ) !== -1;
 };
 
 /**
@@ -194,13 +194,13 @@
 };
 
 /**
- * Get the index of a given annotation in the set.
+ * Get the offset of a given annotation in the set.
  *
  * @method
  * @param {ve.dm.Annotation} annotation Annotation to search for
- * @returns {number} Index of annotation in the set, or -1 if annotation is 
not in the set.
+ * @returns {number} Offset of annotation in the set, or -1 if annotation is 
not in the set.
  */
-ve.dm.AnnotationSet.prototype.indexOf = function ( annotation ) {
+ve.dm.AnnotationSet.prototype.offsetOf = function ( annotation ) {
        return ve.indexOf( this.store.indexOfHash( ve.getHash( annotation ) ), 
this.getIndexes() );
 };
 
@@ -297,7 +297,7 @@
  * @returns {boolean} The annotations are the same
  */
 ve.dm.AnnotationSet.prototype.compareTo = function ( annotationSet ) {
-       var i, indexes = this.getIndexes(), length = indexes.length;
+       var i, length = this.getIndexes().length;
 
        if ( length === annotationSet.getLength() ) {
                for ( i = 0; i < length; i++ ) {
@@ -316,28 +316,28 @@
  *
  * 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 index. If index is
- * negative, it will be counted from the end (i.e. index -1 is the last item, 
-2 the second-to-last,
- * etc.). If index is out of bounds, the annotation will be added to the end 
of the set.
+ * 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.
  *
  * @method
  * @param {ve.dm.Annotation} annotation Annotation to add
- * @param {number} index Index to add the annotation at
+ * @param {number} offset Offset to add the annotation at
  */
-ve.dm.AnnotationSet.prototype.add = function ( annotation, index ) {
+ve.dm.AnnotationSet.prototype.add = function ( annotation, offset ) {
        var storeIndex = this.getStore().index( annotation );
        // negative offset
-       if ( index < 0 ) {
-               index = this.getLength() + index;
+       if ( offset < 0 ) {
+               offset = this.getLength() + offset;
        }
        // greater than length, add to end
-       if ( index >= this.getLength() ) {
+       if ( offset >= this.getLength() ) {
                this.push( annotation );
                return;
        }
        // if not in set already, splice in place
        if ( !this.containsIndex( storeIndex ) ) {
-               this.storeIndexes.splice( index, 0, storeIndex );
+               this.storeIndexes.splice( offset, 0, storeIndex );
        }
 };
 
@@ -365,20 +365,20 @@
 };
 
 /**
- * Remove the annotation at a given index.
+ * Remove the annotation at a given offset.
  *
  * @method
- * @param {number} index Index to remove item at. If negative, the counts from 
the end, see add()
- * @throws {Error} Index out of bounds.
+ * @param {number} offset Offset to remove item at. If negative, the counts 
from the end, see add()
+ * @throws {Error} Offset out of bounds.
  */
-ve.dm.AnnotationSet.prototype.removeAt = function ( index ) {
-       if ( index < 0 ) {
-               index = this.getLength() + index;
+ve.dm.AnnotationSet.prototype.removeAt = function ( offset ) {
+       if ( offset < 0 ) {
+               offset = this.getLength() + offset;
        }
-       if ( index >= this.getLength() ) {
-               throw new Error( 'Index out of bounds' );
+       if ( offset >= this.getLength() ) {
+               throw new Error( 'Offset out of bounds' );
        }
-       this.storeIndexes.splice( index, 1 );
+       this.storeIndexes.splice( offset, 1 );
 };
 
 /**
@@ -390,9 +390,9 @@
  * @param {ve.dm.Annotation} annotation Annotation to remove
  */
 ve.dm.AnnotationSet.prototype.remove = function ( annotation ) {
-       var index = this.indexOf( annotation );
-       if ( index !== -1 ) {
-               this.storeIndexes.splice( index, 1 );
+       var offset = this.offsetOf( annotation );
+       if ( offset !== -1 ) {
+               this.storeIndexes.splice( offset, 1 );
        }
 };
 
diff --git a/modules/ve/test/dm/ve.dm.AnnotationSet.test.js 
b/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
index 4f49719..3874ac4 100644
--- a/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
+++ b/modules/ve/test/dm/ve.dm.AnnotationSet.test.js
@@ -30,8 +30,8 @@
        assert.equal( annotationSet.containsAnyOf( emptySet ), false, 
'containsAnyOf empty set is false' );
        assert.equal( annotationSet.containsAllOf( annotationSet2 ), false, 
'containsAllOf set2 set is false' );
        assert.equal( annotationSet.containsAllOf( annotationSet ), true, 
'containsAllOf self is true' );
-       assert.equal( annotationSet.indexOf( italic ), 1, 'indexOf italic is 1' 
);
-       assert.equal( annotationSet.indexOf( underline ), -1, 'indexOf 
underline is -1' );
+       assert.equal( annotationSet.offsetOf( italic ), 1, 'offsetOf italic is 
1' );
+       assert.equal( annotationSet.offsetOf( underline ), -1, 'offsetOf 
underline is -1' );
        assert.deepEqual(
                annotationSet.filter( function ( annotation ) { return 
annotation.name === 'textStyle/bold'; } ).get(),
                [ bold ], 'filter for name=textStyle/bold returns just bold 
annotation'
@@ -40,11 +40,11 @@
        assert.equal( annotationSet.hasAnnotationWithName( 
'textStyle/underline' ), false, 'hasAnnotationWithName underline is false' );
 
        annotationSet2.add( bold, 1 );
-       assert.equal( annotationSet2.indexOf( bold ), 1, 'set2 contains bold at 
1 after add at 1' );
+       assert.equal( annotationSet2.offsetOf( bold ), 1, 'set2 contains bold 
at 1 after add at 1' );
        annotationSet2.remove( bold );
        assert.equal( annotationSet2.contains( bold ), false, 'set2 doesn\'t 
contain bold after remove' );
        annotationSet2.add( bold, 0 );
-       assert.equal( annotationSet2.indexOf( bold ), 0, 'set2 contains bold at 
0 after add at 0' );
+       assert.equal( annotationSet2.offsetOf( bold ), 0, 'set2 contains bold 
at 0 after add at 0' );
        annotationSet2.add( bold, 0 );
        assert.equal( annotationSet2.getLength(), 3, 'adding existing 
annotation doesn\'t change length' );
        // set is now [ bold, italic, underline ]
@@ -65,7 +65,7 @@
        assert.equal( annotationSet.contains( italic ) && 
!annotationSet.contains( underline ), true, 'contains italic not underline 
after removeNotInSet' );
        annotationSet2.add( underline, 1 );
        annotationSet3 = annotationSet2.reversed();
-       assert.equal( annotationSet3.indexOf( underline ), 0, 'underline has 
indexOf 0 after reverse' );
+       assert.equal( annotationSet3.offsetOf( underline ), 0, 'underline has 
offsetOf 0 after reverse' );
        annotationSet3 = annotationSet.mergeWith( annotationSet2 );
        assert.equal( annotationSet3.getLength(), 3, 'set merged with set2 has 
length 3' );
        annotationSet3 = annotationSet.diffWith( annotationSet2 );

-- 
To view, visit https://gerrit.wikimedia.org/r/76106
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic7d741bd5d39240d63fdc04a2df45658a64441de
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to