2222import static org .jgrasstools .gears .libs .modules .JGTConstants .isNovalue ;
2323
2424import java .util .HashMap ;
25- import java .util .Map ;
25+ import java .util .Set ;
26+ import java .util .Map .Entry ;
2627
2728import oms3 .annotations .Description ;
2829import oms3 .annotations .Execute ;
29- import oms3 .annotations .Finalize ;
3030import oms3 .annotations .In ;
31- import oms3 .annotations .Initialize ;
3231import oms3 .annotations .Out ;
3332
33+ import org .geotools .feature .SchemaException ;
3434import org .jgrasstools .gears .libs .modules .JGTModel ;
35+ import java .io .IOException ;
3536
37+
38+
39+
40+ // TODO: Auto-generated Javadoc
3641/**
3742 * The Class SumSeries compute the sum of two time series
38- *
39- * @author sidereus <francesco.serafin.3@gmail.com>
40- * @date Nov 2nd, 2016
4143 */
42- public class SumSeries extends JGTModel {
44+ public class SumSeries extends JGTModel {
45+
4346
4447 @ Description ("Input first discharge Hashmap" )
4548 @ In
@@ -53,18 +56,9 @@ public class SumSeries extends JGTModel {
5356 @ Description ("The output HashMap with the sum"
5457 + "for the considered layer " )
5558 @ Out
56- public static HashMap <Integer , double []> outHMQtot ;
59+ public HashMap <Integer , double []> outHMQtot = new HashMap < Integer , double []>() ;
5760
58- @ In
59- public static Integer id ;
6061
61- private static int timeSeriesCounter = 0 ;
62-
63- @ Initialize
64- public void init () {
65- outHMQtot = new HashMap <>();
66- timeSeriesCounter = 0 ;
67- }
6862
6963 /**
7064 * Process.
@@ -74,38 +68,61 @@ public void init() {
7468 @ Execute
7569 public void process () throws Exception {
7670
77- System .out .println (id + ": processing sum series - Time step: " +
78- timeSeriesCounter +1 );
71+ //checkNull(inHMDischarge);
7972
80- checkNull (inHMDischarge );
81- double [] sum = new double [1 ];
73+ Set <Entry <Integer , double []>> entrySet = inHMDischarge .entrySet ();
8274
83- sumInHMDischarge (sum , inHMDischarge , timeSeriesCounter );
84- sumInHMDischarge (sum , inHMDischarge2 , 0 );
75+ Set <Entry <Integer , double []>> entrySet2 = inHMDischarge2 .entrySet ();
8576
86- outHMQtot .put (id , sum );
87- timeSeriesCounter += 1 ;
8877
89- }
78+ for (Entry <Integer , double []> entry : entrySet ){
79+ for (Entry <Integer , double []> entry2 : entrySet2 ){
9080
91- @ Finalize
92- public void finalize () {
93- timeSeriesCounter = 0 ;
94- outHMQtot .clear ();
95- }
81+ Integer ID = entry .getKey ();
82+ Integer ID2 = entry2 .getKey ();
9683
97- private void sumInHMDischarge ( double [] sum , final HashMap < Integer ,
98- double []> discharge , int index ) {
84+ double Q1 = inHMDischarge . get ( ID )[ 0 ];
85+ if ( isNovalue ( Q1 )) Q1 = 0 ;
9986
100- if (discharge != null ) {
101- for (Map .Entry <Integer , double []> me : discharge .entrySet ()) {
102- double tmpDischarge = me .getValue ()[index ];
103- if (isNovalue (tmpDischarge )) tmpDischarge = 0.0 ;
104- sum [0 ] += tmpDischarge ;
87+ double Q2 =inHMDischarge2 .get (ID2 )[0 ];
88+ if (isNovalue (Q2 )) Q2 = 0 ;
89+
90+ /** sum of the given quantities */
91+ double sum =sum (Q1 ,Q2 );
92+
93+ /** Save the result in hashmap output */
94+ storeResult_series (ID ,sum );
10595 }
10696 }
10797
10898 }
10999
110- }
111100
101+
102+
103+ /**
104+ * Sum: computation of the sum
105+ *
106+ * @param Q1: the first quantity
107+ * @param Q2 : the second quantity
108+ * @return the double value of the sum
109+ * @throws IOException Signals that an I/O exception has occurred.
110+ */
111+ public double sum (double Q1 , double Q2 ) throws IOException {
112+ double Qtot =Q1 +Q2 ;
113+ return Qtot ;
114+ }
115+
116+
117+ /**
118+ * Store result_series
119+ *
120+ * @param Qtot: the vector with the sums
121+ * @throws SchemaException the schema exception
122+ */
123+ private void storeResult_series (int ID ,double Qtot ) throws SchemaException {
124+ outHMQtot .put (ID , new double []{Qtot });
125+
126+
127+ }
128+ }
0 commit comments