From 6709bb242f3da46b1443aa05cb4e0d0e56ee3278 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Wed, 6 Jun 2018 11:16:06 +0200
Subject: [PATCH] =?UTF-8?q?=20#45=20s=C3=A9paration=20de=20src/param/param?=
 =?UTF-8?q?-values.ts=20en=20plusieurs=20fichiers?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 spec/iterator/paramvalues_iterator.spec.ts |   4 +-
 spec/param/param-values.spec.ts            |   3 +-
 spec/value_ref/value_ref.spec.ts           |   3 +-
 src/compute-node.ts                        |   1 -
 src/nub.ts                                 |   3 +-
 src/param/param-base.ts                    |   3 +-
 src/param/param-definition.ts              |   2 +-
 src/param/param-value-iterator.ts          | 149 +++++++++++++++++
 src/param/param-value-mode.ts              |  30 ++++
 src/param/param-values.ts                  | 179 +--------------------
 src/remous.ts                              |   2 +-
 src/section/section_nub.ts                 |   2 +-
 src/value_ref/object_ref.ts                |   2 +-
 13 files changed, 196 insertions(+), 187 deletions(-)
 create mode 100644 src/param/param-value-iterator.ts
 create mode 100644 src/param/param-value-mode.ts

diff --git a/spec/iterator/paramvalues_iterator.spec.ts b/spec/iterator/paramvalues_iterator.spec.ts
index 238b64b5..9bfa898d 100644
--- a/spec/iterator/paramvalues_iterator.spec.ts
+++ b/spec/iterator/paramvalues_iterator.spec.ts
@@ -1,4 +1,6 @@
-import { ParamValues, ParamValueMode, ParamValueIterator } from "../../src/param/param-values"
+import { ParamValues } from "../../src/param/param-values"
+import { ParamValueIterator } from "../../src/param/param-value-iterator";
+import { ParamValueMode } from "../../src/param/param-value-mode";
 
 function checkNumberList(it: ParamValueIterator, exp: number[]) {
     let n = 0;
diff --git a/spec/param/param-values.spec.ts b/spec/param/param-values.spec.ts
index 9eae6de7..f7575fe1 100644
--- a/spec/param/param-values.spec.ts
+++ b/spec/param/param-values.spec.ts
@@ -1,6 +1,7 @@
 /// <reference path="../../node_modules/@types/jasmine/index.d.ts" />
 
-import { ParamValues, ParamValueMode } from "../../src/param/param-values"
+import { ParamValues } from "../../src/param/param-values"
+import { ParamValueMode } from "../../src/param/param-value-mode";
 
 describe('paramvalues : ', () => {
     it("check single (1)", () => {
diff --git a/spec/value_ref/value_ref.spec.ts b/spec/value_ref/value_ref.spec.ts
index b48a4d32..c9ba1ddd 100644
--- a/spec/value_ref/value_ref.spec.ts
+++ b/spec/value_ref/value_ref.spec.ts
@@ -8,7 +8,8 @@ import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";
 
 import { NubTest, NubTestParams } from "../nubtest";
 import { precDigits } from "../test_config";
-import { ParamValueMode, Result } from "../../src";
+import { ParamValueMode } from "../../src/param/param-value-mode";
+import { Result } from "../../src";
 
 let nub1: NubTest;
 let nub2: NubTest;
diff --git a/src/compute-node.ts b/src/compute-node.ts
index 88ff3470..e7efe419 100644
--- a/src/compute-node.ts
+++ b/src/compute-node.ts
@@ -1,7 +1,6 @@
 import { Debug, IDebug } from "./base";
 import { ParamsEquation, IParamDefinitionIterator } from "./param/params-equation";
 import { ParamDefinition } from "./param/param-definition";
-import { ParamValueMode } from "./param/param-values";
 import { JalhydObject } from "./jalhyd_object";
 
 /**
diff --git a/src/nub.ts b/src/nub.ts
index a5160d4a..79696d1d 100644
--- a/src/nub.ts
+++ b/src/nub.ts
@@ -2,7 +2,8 @@ import { Debug } from "./base";
 import { Dichotomie } from "./dichotomie";
 import { ComputeNode } from "./compute-node";
 import { Result } from "./util/result";
-import { ParamValues, ParamValueMode } from "./param/param-values";
+import { ParamValues } from "./param/param-values";
+import { ParamValueMode } from "./param/param-value-mode";
 import { ParamDefinition } from ".";
 import { IReferencedObject } from "./value_ref/object_ref";
 
diff --git a/src/param/param-base.ts b/src/param/param-base.ts
index fc8de5e2..7e21c631 100644
--- a/src/param/param-base.ts
+++ b/src/param/param-base.ts
@@ -4,7 +4,8 @@ import { Message, MessageCode } from "../util/message";
 
 import { JalhydObject } from "../jalhyd_object"
 import { ParamDomain, ParamDomainValue } from "./param-domain";
-import { ParamValues, ParamValueMode } from "./param-values";
+import { ParamValues } from "./param-values";
+import { ParamValueMode } from "./param-value-mode";
 import { IReferencedObject, IObjectReference } from "../value_ref/object_ref";
 import { Result } from "..";
 
diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts
index afd80ace..07088060 100644
--- a/src/param/param-definition.ts
+++ b/src/param/param-definition.ts
@@ -2,7 +2,7 @@ import { Message, MessageCode } from "../util/message";
 
 import { BaseParam } from "./param-base";
 import { ParamDomain, ParamDomainValue } from "./param-domain";
-import { ParamValueMode, ParamValueIterator } from "./param-values";
+import { ParamValueMode } from "./param-value-mode";
 
 /**
  * calculabilité du paramètre
diff --git a/src/param/param-value-iterator.ts b/src/param/param-value-iterator.ts
new file mode 100644
index 00000000..0d123d96
--- /dev/null
+++ b/src/param/param-value-iterator.ts
@@ -0,0 +1,149 @@
+import { ParamValues } from "./param-values";
+import { ParamValueMode } from "./param-value-mode";
+
+/**
+ * itérateur sur les (ou la) valeurs prises par le paramètre
+ */
+export class ParamValueIterator implements IterableIterator<number> {
+    /**
+     * paramètre à itérer
+     */
+    private _param: ParamValues;
+
+    /**
+     * true si les valeurs sont fournies de max à min (ParamValueMode.MINMAX)
+     */
+    private _reverse: boolean;
+
+    private _index: number;
+
+    /**
+     * cas de figure :
+     * 0 : valeur fixée
+     * 1 : min/max/pas
+     * 2 : liste de valeurs
+     */
+    private _config: number;
+
+    constructor(prm: ParamValues, reverse: boolean = false) {
+        prm.check();
+        this._param = prm;
+        this.reset(reverse)
+    }
+
+    public reset(reverse: boolean) {
+        this._reverse = reverse;
+
+        switch (this._param.valueMode) {
+            case ParamValueMode.SINGLE:
+                this._config = 0;
+                this._index = 0;
+                break;
+
+            case ParamValueMode.MINMAX:
+                this._config = 1;
+                if (reverse)
+                    this._index = this._param.max;
+                else
+                    this._index = this._param.min;
+                break;
+
+            case ParamValueMode.LISTE:
+                this._config = 2;
+                this._index = 0;
+                break;
+
+            default:
+                throw new Error(`ParamValueIterator : mode de génération de valeurs ${ParamValueMode[this._param.valueMode]} incorrect`);
+        }
+    }
+
+    public get hasNext(): boolean {
+        switch (this._config) {
+            // valeur fixée
+            case 0:
+                return this._index == 0;
+
+            // min/max
+            case 1:
+                const end = this._reverse ? this._index < this._param.min : this._index > this._param.max;
+                return !end;
+
+            // liste
+            case 2:
+                return this._index < this._param.valueList.length;
+
+            default:
+                throw new Error(`ParamValueIterator.hasNext() : erreur interne`);
+        }
+    }
+
+    public next(): IteratorResult<number> {
+        switch (this._config) {
+            // valeur fixée
+            case 0:
+                if (this.hasNext) {
+                    this._index++;
+                    return {
+                        done: false,
+                        value: this._param.singleValue
+                    };
+                }
+                else
+                    return {
+                        done: true,
+                        value: undefined
+                    };
+
+            // min/max
+            case 1:
+                const res = this._index;
+                if (this.hasNext) {
+                    if (this._reverse)
+                        this._index -= this._param.step;
+                    else
+                        this._index += this._param.step;
+                    return {
+                        done: false,
+                        value: res
+                    };
+                } else {
+                    return {
+                        done: true,
+                        value: undefined
+                    };
+                }
+
+            // liste
+            case 2:
+                const i = this._index;
+                if (this.hasNext) {
+                    const res = this._param.valueList[this._index++];
+                    return {
+                        done: false,
+                        value: res
+                    };
+                } else {
+                    return {
+                        done: true,
+                        value: undefined
+                    };
+                }
+
+            default:
+                throw new Error(`ParamValueIterator.next() : erreur interne`);
+        }
+    }
+
+    // public get current(): number {
+    //     if (this._config == 1)
+    //         return this._index;
+    //     throw new Error(`appel ParamValueIterator.current() invalide`)
+    // }
+
+    // interface IterableIterator
+
+    public [Symbol.iterator](): IterableIterator<number> {
+        return this;
+    }
+}
diff --git a/src/param/param-value-mode.ts b/src/param/param-value-mode.ts
new file mode 100644
index 00000000..826ca43f
--- /dev/null
+++ b/src/param/param-value-mode.ts
@@ -0,0 +1,30 @@
+
+/**
+ * mode de génération des valeurs d'un paramètre
+ */
+export enum ParamValueMode {
+    /**
+     * valeur unique
+     */
+    SINGLE,
+
+    /**
+     * min, max, pas
+     */
+    MINMAX,
+
+    /**
+     * liste de valeurs discrètes
+     */
+    LISTE,
+
+    /**
+     * la valeur du paramètre est non définie et à calculer
+     */
+    CALCUL,
+
+    /**
+     * la valeur du paramètre est liée à celle d'un paramètre, d'un résultat, ...
+     */
+    LINK
+}
diff --git a/src/param/param-values.ts b/src/param/param-values.ts
index 57b5457b..8486a6d4 100644
--- a/src/param/param-values.ts
+++ b/src/param/param-values.ts
@@ -2,183 +2,8 @@ import { Pair } from "../util/pair"
 import { DefinedNumber } from "../util/definedvalue";
 import { IReferencedObject, IObjectReference, ObjectReference } from "../value_ref/object_ref";
 import { Result } from "..";
-
-/**
- * mode de génération des valeurs
- */
-export enum ParamValueMode {
-    /**
-     * valeur unique
-     */
-    SINGLE,
-
-    /**
-     * min, max, pas
-     */
-    MINMAX,
-
-    /**
-     * liste de valeurs discrètes
-     */
-    LISTE,
-
-    /**
-     * la valeur du paramètre est non définie et à calculer
-     */
-    CALCUL,
-
-    /**
-     * la valeur du paramètre est liée à celle d'un paramètre, d'un résultat, ...
-     */
-    LINK
-}
-
-/**
- * itérateur sur les (ou la) valeurs prises par le paramètre
- */
-export class ParamValueIterator implements IterableIterator<number> {
-    /**
-     * paramètre à itérer
-     */
-    private _param: ParamValues;
-
-    /**
-     * true si les valeurs sont fournies de max à min (ParamValueMode.MINMAX)
-     */
-    private _reverse: boolean;
-
-    private _index: number;
-
-    /**
-     * cas de figure :
-     * 0 : valeur fixée
-     * 1 : min/max/pas
-     * 2 : liste de valeurs
-     */
-    private _config: number;
-
-    constructor(prm: ParamValues, reverse: boolean = false) {
-        prm.check();
-        this._param = prm;
-        this.reset(reverse)
-    }
-
-    public reset(reverse: boolean) {
-        this._reverse = reverse;
-
-        switch (this._param.valueMode) {
-            case ParamValueMode.SINGLE:
-                this._config = 0;
-                this._index = 0;
-                break;
-
-            case ParamValueMode.MINMAX:
-                this._config = 1;
-                if (reverse)
-                    this._index = this._param.max;
-                else
-                    this._index = this._param.min;
-                break;
-
-            case ParamValueMode.LISTE:
-                this._config = 2;
-                this._index = 0;
-                break;
-
-            default:
-                throw new Error(`ParamValueIterator : mode de génération de valeurs ${ParamValueMode[this._param.valueMode]} incorrect`);
-        }
-    }
-
-    public get hasNext(): boolean {
-        switch (this._config) {
-            // valeur fixée
-            case 0:
-                return this._index == 0;
-
-            // min/max
-            case 1:
-                const end = this._reverse ? this._index < this._param.min : this._index > this._param.max;
-                return !end;
-
-            // liste
-            case 2:
-                return this._index < this._param.valueList.length;
-
-            default:
-                throw new Error(`ParamValueIterator.hasNext() : erreur interne`);
-        }
-    }
-
-    public next(): IteratorResult<number> {
-        switch (this._config) {
-            // valeur fixée
-            case 0:
-                if (this.hasNext) {
-                    this._index++;
-                    return {
-                        done: false,
-                        value: this._param.singleValue
-                    };
-                }
-                else
-                    return {
-                        done: true,
-                        value: undefined
-                    };
-
-            // min/max
-            case 1:
-                const res = this._index;
-                if (this.hasNext) {
-                    if (this._reverse)
-                        this._index -= this._param.step;
-                    else
-                        this._index += this._param.step;
-                    return {
-                        done: false,
-                        value: res
-                    };
-                } else {
-                    return {
-                        done: true,
-                        value: undefined
-                    };
-                }
-
-            // liste
-            case 2:
-                const i = this._index;
-                if (this.hasNext) {
-                    const res = this._param.valueList[this._index++];
-                    return {
-                        done: false,
-                        value: res
-                    };
-                } else {
-                    return {
-                        done: true,
-                        value: undefined
-                    };
-                }
-
-            default:
-                throw new Error(`ParamValueIterator.next() : erreur interne`);
-        }
-    }
-
-    // public get current(): number {
-    //     if (this._config == 1)
-    //         return this._index;
-    //     throw new Error(`appel ParamValueIterator.current() invalide`)
-    // }
-
-    // interface IterableIterator
-
-    public [Symbol.iterator](): IterableIterator<number> {
-        return this;
-    }
-}
+import { ParamValueMode } from "./param-value-mode";
+import { ParamValueIterator } from "./param-value-iterator";
 
 export class ParamValues implements IObjectReference {
     /**
diff --git a/src/remous.ts b/src/remous.ts
index 6c3ff39a..1b0075fa 100644
--- a/src/remous.ts
+++ b/src/remous.ts
@@ -9,7 +9,7 @@ import { cLog } from "./util/log";
 import { Message, MessageCode } from "./util/message";
 import { Result } from "./util/result";
 import { ResultElement } from "./util/resultelement";
-import { ParamValueIterator, ParamValues, BaseParam } from ".";
+import { ParamValues, BaseParam } from ".";
 
 export enum MethodeResolution {
     Trapezes, EulerExplicite, RungeKutta4
diff --git a/src/section/section_nub.ts b/src/section/section_nub.ts
index ad9068b1..56445b7d 100644
--- a/src/section/section_nub.ts
+++ b/src/section/section_nub.ts
@@ -3,7 +3,7 @@ import { acSection } from "./section_type";
 import { Result } from "../util/result";
 import { ParamDefinition, ParamCalculability } from "../param/param-definition";
 import { ParamDomain, ParamDomainValue } from "../param/param-domain";
-import { ParamValueMode } from "../param/param-values";
+import { ParamValueMode } from "../param/param-value-mode";
 import { ResultElement } from "../util/resultelement";
 
 /**
diff --git a/src/value_ref/object_ref.ts b/src/value_ref/object_ref.ts
index 200cc3bb..1591dff8 100644
--- a/src/value_ref/object_ref.ts
+++ b/src/value_ref/object_ref.ts
@@ -1,4 +1,4 @@
-import { ParamValueMode, ParamValueIterator, ParamValues } from "../param/param-values";
+import { ParamValues } from "../param/param-values";
 import { Result } from "..";
 
 /**
-- 
GitLab