@@ -102,6 +102,7 @@ private static CurrentLimitsData copyCurrentLimitsData(CurrentLimitsData current
102
102
}
103
103
104
104
/**
105
+ * Combine 2 sides in one list.
105
106
* @return id of the selected operation limits group 1 and 2 if they have been renamed
106
107
*/
107
108
public static void mergeCurrentLimits (Collection <OperationalLimitsGroup > operationalLimitsGroups1 ,
@@ -110,55 +111,44 @@ public static void mergeCurrentLimits(Collection<OperationalLimitsGroup> operati
110
111
List <CurrentLimitsData > mergedLimitsData = new ArrayList <>();
111
112
112
113
// Build temporary limit from side 1 and 2
113
- List <CurrentLimitsData > currentLimitsData1 = operationalLimitsGroups1 .stream ()
114
+ final List <CurrentLimitsData > currentLimitsData1 = operationalLimitsGroups1 .stream ()
114
115
.map (ElementUtils ::operationalLimitsGroupToMapDataCurrentLimits ).toList ();
115
- ArrayList <CurrentLimitsData > currentLimitsData2 = new ArrayList <>(operationalLimitsGroups2 .stream ()
116
- .map (ElementUtils ::operationalLimitsGroupToMapDataCurrentLimits ).toList ());
117
-
118
- // combine 2 sides in one list
116
+ final List <CurrentLimitsData > currentLimitsData2 = operationalLimitsGroups2 .stream ()
117
+ .map (ElementUtils ::operationalLimitsGroupToMapDataCurrentLimits )
118
+ .collect (Collectors .toCollection (ArrayList ::new ));
119
119
120
120
// simple case : one of the arrays are empty
121
121
if (currentLimitsData2 .isEmpty () && !currentLimitsData1 .isEmpty ()) {
122
- for (CurrentLimitsData currentLimitsData : currentLimitsData1 ) {
122
+ for (final CurrentLimitsData currentLimitsData : currentLimitsData1 ) {
123
123
mergedLimitsData .add (copyCurrentLimitsData (currentLimitsData , SIDE1 ));
124
124
}
125
125
build .accept (mergedLimitsData );
126
126
return ;
127
127
}
128
128
if (currentLimitsData1 .isEmpty () && !currentLimitsData2 .isEmpty ()) {
129
- for (CurrentLimitsData currentLimitsData : currentLimitsData2 ) {
129
+ for (final CurrentLimitsData currentLimitsData : currentLimitsData2 ) {
130
130
mergedLimitsData .add (copyCurrentLimitsData (currentLimitsData , SIDE2 ));
131
131
}
132
132
build .accept (mergedLimitsData );
133
133
return ;
134
134
}
135
135
136
136
// more complex case
137
- for (CurrentLimitsData limitsData : currentLimitsData1 ) {
138
- Optional <CurrentLimitsData > l2 = currentLimitsData2 .stream ().filter (l -> l .getId ().equals (limitsData .getId ())).findFirst ();
139
-
137
+ for (final CurrentLimitsData limitsData : currentLimitsData1 ) {
138
+ final Optional <CurrentLimitsData > l2 = currentLimitsData2 .stream ().filter (l -> l .getId ().equals (limitsData .getId ())).findFirst ();
140
139
if (l2 .isPresent ()) {
141
140
CurrentLimitsData limitsData2 = l2 .get ();
142
- // Only side one has limits
143
- if (limitsData .hasLimits () && !limitsData2 .hasLimits ()) {
141
+ if (limitsData .hasLimits () && !limitsData2 .hasLimits ()) { // Only side one has limits
142
+ mergedLimitsData .add (copyCurrentLimitsData (limitsData , SIDE1 ));
143
+ } else if (limitsData2 .hasLimits () && !limitsData .hasLimits ()) { // only side two has limits
144
+ mergedLimitsData .add (copyCurrentLimitsData (limitsData2 , SIDE2 ));
145
+ } else if (limitsData .limitsEquals (limitsData2 )) { // both sides have limits and limits are equals
146
+ mergedLimitsData .add (copyCurrentLimitsData (limitsData , EQUIPMENT ));
147
+ } else { // both side have limits and are different : create 2 different limit sets
144
148
mergedLimitsData .add (copyCurrentLimitsData (limitsData , SIDE1 ));
145
- // only side two has limits
146
- } else if (limitsData2 .hasLimits () && !limitsData .hasLimits ()) {
147
149
mergedLimitsData .add (copyCurrentLimitsData (limitsData2 , SIDE2 ));
148
- } else {
149
- // both sides have limits and limits are equals
150
- if (limitsData .limitsEquals (limitsData2 )) {
151
- mergedLimitsData .add (copyCurrentLimitsData (limitsData , EQUIPMENT ));
152
- // both side have limits and they are different : create 2 different limit sets
153
- } else {
154
- // Side 1
155
- mergedLimitsData .add (copyCurrentLimitsData (limitsData , SIDE1 ));
156
- // Side 2
157
- mergedLimitsData .add (copyCurrentLimitsData (limitsData2 , SIDE2 ));
158
- }
159
150
}
160
- // remove processed limits from side 2
161
- currentLimitsData2 .remove (l2 .get ());
151
+ currentLimitsData2 .remove (l2 .get ()); // remove processed limits from side 2
162
152
} else {
163
153
mergedLimitsData .add (copyCurrentLimitsData (limitsData , SIDE1 ));
164
154
}
0 commit comments