I got the following code:
def arrayOfInts = [actual_speed_mobile_1.toInteger(), actual_speed_mobile_2.toInteger(), actual_speed_mobile_3.toInteger(), actual_speed_mobile_4.toInteger(), actual_speed_mobile_5.toInteger()]
"this is **important** if we use removeAt"
Collections.sort(arrayOfInts)
def min = Collections.min(arrayOfInts);
WebUI.comment("our min value is " + min.toString())
def max = Collections.max(arrayOfInts);
WebUI.comment("our max value is " + max.toString())
WebUI.comment("our list of values are " + arrayOfInts.toString())
arrayOfInts.removeAt(0);
WebUI.comment("our list of values are " + arrayOfInts.toString())
if (min != max) {
arrayOfInts.removeAt(arrayOfInts.size() - 1);
WebUI.comment("our list of values are " + arrayOfInts.toString())
}
WebUI.comment("our values are " + arrayOfInts.toString())
The output is:
arrayOfInts = [actual_speed_mobile_1.toInteger(), actual_speed_mobile_2.toInteger(), actual_speed_mobile_3.toInteger(), actual_speed_mobile_4.toInteger(), actual_speed_mobile_5.toInteger()]
Collections.sort(arrayOfInts)
in = Collections.min(arrayOfInts)
comment("our min value is " + min.toString())
our min value is 74
max = Collections.max(arrayOfInts)
comment("our max value is " + max.toString())
our max value is 86
comment("our list of values are " + arrayOfInts.toString())
our list of values are [74, 82, 83, 84, 86]
arrayOfInts.removeAt(0)
comment("our list of values are " + arrayOfInts.toString())
our list of values are [82, 83, 84, 86]
if (min != max)
arrayOfInts.removeAt(arrayOfInts.size() - 1)
comment("our list of values are " + arrayOfInts.toString())
our list of values are [82, 83, 84]
I want the list to do average I was thinking to add it into a new variable and transform it to inter but I got error:
Reason:
groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.toInterger() is applicable for argument types: () values: []
at Aspire_cashout.run(Aspire_cashout:115)
Your code can be rewritten in somewhat more idiomatic groovy as for example:
where the
iterable.average()
method was introduced in groovy 3.0. If you are running a version of groovy older than that, you can use theints.sum() / ints.size()
construct.When executed (with groovy 3.x) the above code results in:
Other relevant methods on iterable: init, tail, head, last.