All files / src/dm/lineardata ve.dm.FlatLinearData.js

100% Statements 17/17
100% Branches 2/2
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86                                  1x   3297x         1x                   1x 26982x                 1x 75431x                     1x 4x 4x 7x 2x     2x                 1x 42062x                 1x 25281x    
/*!
 * VisualEditor FlatLinearData classes.
 *
 * Class containing Flat linear data and a hash-value store.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Flat linear data storage
 *
 * @class
 * @extends ve.dm.LinearData
 * @constructor
 * @param {ve.dm.HashValueStore} store Hash-value store
 * @param {Array} [data] Linear data
 */
ve.dm.FlatLinearData = function VeDmFlatLinearData() {
	// Parent constructor
	ve.dm.FlatLinearData.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.FlatLinearData, ve.dm.LinearData );
 
/* Methods */
 
/**
 * Get the type of the element at a specified offset.
 *
 * @param {number} offset Data offset
 * @return {string} Type of the element
 */
ve.dm.FlatLinearData.prototype.getType = function ( offset ) {
	return ve.dm.LinearData.static.getType( this.getData( offset ) );
};
 
/**
 * Check if data at a given offset is an element.
 *
 * @param {number} offset Data offset
 * @return {boolean} Data at offset is an element
 */
ve.dm.FlatLinearData.prototype.isElementData = function ( offset ) {
	return ve.dm.LinearData.static.isElementData( this.getData( offset ) );
};
 
/**
 * Check for elements in data.
 *
 * This method assumes that any value that has a type property that's a string is an element object.
 * Elements are discovered by iterating through the entire data array (backwards).
 *
 * @return {boolean} At least one elements exists in data
 */
ve.dm.FlatLinearData.prototype.containsElementData = function () {
	let i = this.getLength();
	while ( i-- ) {
		if ( this.isElementData( i ) ) {
			return true;
		}
	}
	return false;
};
 
/**
 * Checks if data at a given offset is an open element.
 *
 * @param {number} offset Data offset
 * @return {boolean} Data at offset is an open element
 */
ve.dm.FlatLinearData.prototype.isOpenElementData = function ( offset ) {
	return ve.dm.LinearData.static.isOpenElementData( this.getData( offset ) );
};
 
/**
 * Checks if data at a given offset is a close element.
 *
 * @param {number} offset Data offset
 * @return {boolean} Data at offset is a close element
 */
ve.dm.FlatLinearData.prototype.isCloseElementData = function ( offset ) {
	return ve.dm.LinearData.static.isCloseElementData( this.getData( offset ) );
};