An error occurred while loading the file. Please try again.
-
Grand Francois authored17222955
import { MapIterator } from "../util/iterator"
import { ParamDefinition } from "./param-definition";
export interface IParamDefinitionIterator extends IterableIterator<ParamDefinition> {
}
/**
* itérateur sur les paramètres d'une seule instance de ParamsEquation
*/
export class ParamDefinitionIterator implements IParamDefinitionIterator {
private _mapIterator: MapIterator<ParamDefinition>;
constructor(_params: ParamsEquation) {
this._mapIterator = new MapIterator(_params.map);
}
public next(): IteratorResult<ParamDefinition> {
return this._mapIterator.next();
}
public [Symbol.iterator](): IterableIterator<ParamDefinition> {
return this;
}
}
/**
* itérateur sur les paramètres d'un tableau de de ParamsEquation
*/
export class ParamsEquationArrayIterator implements IParamDefinitionIterator {
private _paramsEqs: ParamsEquation[];
private _index: number = 0;
private _currentMapIterator: MapIterator<ParamDefinition>;
constructor(p: ParamsEquation[]) {
this._paramsEqs = p;
}
private nextIterator() {
if (this._index < this._paramsEqs.length)
this._currentMapIterator = new MapIterator(this._paramsEqs[this._index++].map);
else
this._currentMapIterator = undefined;
}
private get done(): IteratorResult<ParamDefinition> {
return {
done: true,
value: undefined
};
}
public next(): IteratorResult<ParamDefinition> {
if (this._currentMapIterator == undefined)
this.nextIterator();
if (this._currentMapIterator) {
var res = this._currentMapIterator.next();
if (res.done) {
this.nextIterator();
if (this._currentMapIterator)
res = this._currentMapIterator.next();
}
}
else
res = this.done;
return res;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
}
public [Symbol.iterator](): IterableIterator<ParamDefinition> {
return this;
}
}
/**
* liste des paramètres d'une équation
*/
// tslint:disable-next-line:max-classes-per-file
export abstract class ParamsEquation implements Iterable<ParamDefinition> {
protected _paramMap: { [key: string]: ParamDefinition } = {};
private _calculabilityDefined: boolean;
public constructor() {
this._calculabilityDefined = false;
}
get calculabilityDefined(): boolean {
return this._calculabilityDefined;
}
public DefineCalculability() {
this._calculabilityDefined = true;
}
public hasParameter(name: string): boolean {
for (const p of this)
if (p.symbol === name)
return true;
return false;
}
public get map(): { [key: string]: ParamDefinition } {
return this._paramMap;
}
public resetParametersCalculability() {
for (const p of this)
p.calculability = undefined
}
public checkParametersCalculability() {
const res = [];
for (const p of this)
if (p.calculability === undefined)
res.push(p.symbol);
if (res.length > 0) {
throw new Error("Calculability of parameter(s) " + res.toString() + " has not been defined");
}
}
public [Symbol.iterator](): Iterator<ParamDefinition> {
return this.iterator;
}
public get iterator(): IParamDefinitionIterator {
return new ParamDefinitionIterator(this);
}
protected addParamDefinition(p: ParamDefinition) {
if (!this.hasParameter(p.symbol)) {
this._paramMap[p.symbol] = p;
}
}
141142143144145146
protected addParamDefinitions(ps: ParamsEquation) {
for (const p of ps)
this.addParamDefinition(p);
}
}