storeObjectArray.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { StoreObject } from './storeObject';
  2. export class StoreObjectArray extends StoreObject {
  3. constructor (type, lines, columns, value = null, readOnly = false) {
  4. super(type, value, readOnly);
  5. this._lines = lines;
  6. this._columns = columns;
  7. }
  8. get lines () {
  9. return this._lines;
  10. }
  11. get columns () {
  12. return this._columns;
  13. }
  14. isCompatible (another) {
  15. if(another instanceof StoreObject) {
  16. if(((this.lines === -1 && another.lines > 0) ||
  17. (this.lines === another.lines))) {
  18. if ((this.columns === -1 && another.columns > 0) ||
  19. (this.columns === another.columns)) {
  20. return super.isCompatible(another);
  21. }
  22. }
  23. }
  24. return false;
  25. }
  26. get isVector () {
  27. return this.type.dimensions === 1;
  28. }
  29. get isValid () {
  30. if (this.value !== null) {
  31. if( this.isVector) {
  32. if(this.value.length !== this.lines) {
  33. return false;
  34. }
  35. const mustBeNull = this.value.find(v => !this.type.canAccept(v.type) );
  36. if(!!mustBeNull) {
  37. return false;
  38. }
  39. }
  40. return true;
  41. } else {
  42. if(this.lines !== this.value.length) {
  43. return false;
  44. }
  45. for (let i = 0; i < this.lines; i++) {
  46. for (let j = 0; j < this.columns; j++) {
  47. const arr = this.value[i];
  48. if(arr.length !== this.columns) {
  49. return false;
  50. }
  51. const mustBeNull = arr.find(v => !this.type.canAccept(v.type) );
  52. if(!!mustBeNull) {
  53. return false;
  54. }
  55. }
  56. }
  57. return true;
  58. }
  59. }
  60. }