File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
measure/src/main/java/net/laprun/sustainability/power/analysis/total Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ class Totaler {
1313 private final SensorUnit expectedResultUnit ;
1414 private final Function <double [], Double > formula ;
1515 private final String name ;
16+ private final int [] totalComponentIndices ;
1617 private Errors errors ;
1718
1819 Totaler (SensorMetadata metadata , SensorUnit expectedResultUnit , int ... totalComponentIndices ) {
@@ -27,6 +28,7 @@ class Totaler {
2728 .map (TotalComponent ::name )
2829 .collect (Collectors .joining (" + " , "total (" , ")" ));
2930 formula = formulaFrom (totalComponents );
31+ this .totalComponentIndices = totalComponentIndices ;
3032 }
3133
3234 void validate () {
@@ -52,6 +54,11 @@ public SensorUnit expectedResultUnit() {
5254 }
5355
5456 public double computeTotalFrom (double [] measure ) {
57+ if (measure .length < totalComponentIndices .length ) {
58+ throw new IllegalArgumentException ("Provided measure " + Arrays .toString (measure ) +
59+ " doesn't countain components for required total indices: " + Arrays .toString (totalComponentIndices ));
60+ }
61+
5562 checkValidated ();
5663 return convertToExpectedUnit (formula .apply (measure ));
5764 }
You can’t perform that action at this time.
0 commit comments