@@ -66,8 +66,46 @@ public boolean hasErrors() {
6666 return hasErrors ;
6767 }
6868
69+ /**
70+ * Sets the value unconditionally.
71+ * @param result the MutableInt to set.
72+ * @param value the value to set it to.
73+ * @return the {@code result} argument
74+ */
75+ private MutableInt newValue (final MutableInt result , final int value ) {
76+ result .setValue (value );
77+ return result ;
78+ }
79+
80+ /**
81+ * Sets the {@code result.value} if it is greater than the {@code value} argument.
82+ * @param result the MutableInt to set.
83+ * @param value the value to set it to if it is less than the result.value
84+ * @return the {@code result} argument
85+ */
86+ private MutableInt setMinValue (final MutableInt result , final int value ) {
87+ if (result .intValue () > value ) {
88+ result .setValue (value );
89+ }
90+ return result ;
91+ }
92+
93+ /**
94+ * Sets the {@code result.value} if it is less than the {@code value} argument.
95+ * @param result the MutableInt to set.
96+ * @param value the value to set it to if it is greater than the result.value
97+ * @return the {@code result} argument
98+ */
99+ private MutableInt setMaxValue (final MutableInt result , final int value ) {
100+ if (result .intValue () < value ) {
101+ result .setValue (value );
102+ }
103+ return result ;
104+ }
105+
69106 /**
70107 * Sets the max value for the specified counter.
108+ * Will adjust the minimum if the minimum is greater than the maximum.
71109 * @param counter the counter to set the limit for.
72110 * @param value the value to set. A negative value specifies no maximum value.
73111 */
@@ -76,22 +114,17 @@ public void setMax(final ClaimStatistic.Counter counter, final int value) {
76114 DefaultLog .getInstance ().warn ("`null` passed as argument to setMax() -- ignoring" );
77115 return ;
78116 }
79- MutableInt maxValue = max .compute (counter , (k , v ) -> {
80- MutableInt result = v == null ? new MutableInt (k .getDefaultMaxValue ()) : v ;
81- result .setValue (value < 0 ? Integer .MAX_VALUE : value );
82- return result ;
83- });
84- min .compute (counter , (k , v ) -> {
85- MutableInt result = v == null ? new MutableInt (k .getDefaultMinValue ()) : v ;
86- if (result .intValue () > maxValue .intValue ()) {
87- result .setValue (maxValue .intValue ());
88- }
89- return result ;
90- });
117+ int setValue = value < 0 ? Integer .MAX_VALUE : value ;
118+ MutableInt maxValue = max .compute (counter , (k , v ) ->
119+ v == null ? new MutableInt (setValue ) : newValue (v , setValue ));
120+ min .compute (counter , (k , v ) ->
121+ v == null ? new MutableInt (k .getDefaultMinValue ()) :
122+ setMinValue (v , setValue ));
91123 }
92124
93125 /**
94126 * Sets the min value for the specified counter.
127+ * Will adjust the maximum if the maximum is less than the minimum.
95128 * @param counter the counter to set the limit for.
96129 * @param value the value to set. A negative value specifies no maximum value.
97130 */
@@ -100,12 +133,11 @@ public void setMin(final ClaimStatistic.Counter counter, final int value) {
100133 DefaultLog .getInstance ().warn ("`null` passed as argument to setMin() -- ignoring" );
101134 return ;
102135 }
103- max .compute (counter , (k , v ) -> {
104- MutableInt result = v == null ? new MutableInt (k .getDefaultMinValue ()) : v ;
105- if (result .intValue () < value ) {
106- result .setValue (value );
107- }
108- return v ; });
136+ min .compute (counter , (k , v ) ->
137+ v == null ? new MutableInt (value ) : newValue (v , value ));
138+ max .compute (counter , (k , v ) ->
139+ v == null ? setMaxValue (new MutableInt (k .getDefaultMaxValue ()), value ) :
140+ setMaxValue (v , value ));
109141 }
110142
111143 /**
0 commit comments