12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import { StoreObject } from './storeObject';
- export class StoreObjectArray extends StoreObject {
- static get WRONG_LINE_NUMBER () {
- return 1;
- }
- static get WRONG_TYPE () {
- return 2;
- }
- static get WRONG_COLUMN_NUMBER () {
- return 3;
- }
- constructor (type, lines, columns, value = null, readOnly = false) {
- super(type, value, readOnly);
- this._lines = lines;
- this._columns = columns;
- }
- get lines () {
- return this._lines;
- }
- get columns () {
- return this._columns;
- }
- isCompatible (another) {
- if(another instanceof StoreObjectArray) {
- if((this.isVector && another.isVector) ||
- (!this.isVector && !another.isVector)) {
- return super.isCompatible(another);
- }
- }
- return false;
- }
- get isVector () {
- return this.type.dimensions === 1;
- }
- get isValid () {
- if (this.value !== null) {
- if( this.isVector) {
- if(this.value.length !== this.lines) {
- return [StoreObjectArray.WRONG_LINE_NUMBER, this.value.length];;
- }
- // const mustBeNull = this.value.find(v => !this.type.canAccept(v.type) );
- // if(!!mustBeNull) {
- // return [StoreObjectArray.WRONG_TYPE, this.value.indexOf(mustBeNull)];;
- // }
- return [];
- } else if(this.lines !== this.value.length) {
- return [StoreObjectArray.WRONG_LINE_NUMBER, this.value.length];
- }
- for (let i = 0; i < this.lines; i += 1) {
- const thisRef = this;
- const arrayObject = this.value[i];
- if(arrayObject.lines !== this.columns) {
- return [StoreObjectArray.WRONG_COLUMN_NUMBER, this.columns, arrayObject.lines];
- }
- // const mustBeNull = arrayObject.value.find(v => !arrayObject.type.canAccept(v.type) );
- // if(!!mustBeNull) {
- // console.log(mustBeNull);
- // console.log(thisRef.type.canAccept(mustBeNull));
- // console.log(thisRef.type);
- // return [StoreObjectArray.WRONG_TYPE, i, arrayObject.value.indexOf(mustBeNull)];
- // }
- }
- }
- return [];
- }
- }
|