You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/12/20 09:36:40 UTC
[groovy] branch GROOVY_3_0_X updated (1720c82 -> abad9b8)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 1720c82 GROOVY-9865: Add some DGM methods for primitive arrays (fix test)
new da926ca add another example to Javadoc
new abad9b8 GROOVY-9868: DGM methods via dgminfo not enabled for int[][], long[][], double[][]
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../groovy/reflection/GeneratedMetaMethod.java | 1 +
.../groovy/runtime/DefaultGroovyMethods.java | 32 ++++++++++++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
[groovy] 02/02: GROOVY-9868: DGM methods via dgminfo not enabled
for int[][], long[][], double[][]
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit abad9b8e83bf713e339c55a23aa0ee1c61d3dbf5
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Dec 20 18:47:50 2020 +1000
GROOVY-9868: DGM methods via dgminfo not enabled for int[][], long[][], double[][]
---
src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java | 1 +
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java b/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java
index 23a0db7..b38c10b 100644
--- a/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java
+++ b/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java
@@ -121,6 +121,7 @@ public abstract class GeneratedMetaMethod extends MetaMethod {
boolean[].class, char[].class, byte[].class, short[].class,
int[].class, long[].class, double[].class, float[].class,
+ int[][].class, long[][].class, double[][].class,
Object[].class, String[].class, Class[].class, Byte[].class, CharSequence[].class,
};
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 079a126..62f5a92 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -5512,7 +5512,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* A transpose method for 2D int arrays.
* <p>
* Example usage:
- * <pre class="FIXME_groovyTestCase">
+ * <pre class="groovyTestCase">
* int[][] nums = [[10, 15, 20], [30, 35, 40]]
* int[][] expected = [[10, 30], [15, 35], [20, 40]]
* assert nums.transpose() == expected
[groovy] 01/02: add another example to Javadoc
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit da926ca9dfca17f50ab07a431e229868ef7b7291
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Dec 20 17:12:43 2020 +1000
add another example to Javadoc
---
.../groovy/runtime/DefaultGroovyMethods.java | 30 ++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 50486af..079a126 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -6757,10 +6757,13 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* Averages the items in an Iterable. This is equivalent to invoking the
* "plus" method on all items in the Iterable and then dividing by the
* total count using the "div" method for the resulting sum.
- * <pre class="groovyTestCase">assert 3 == [1, 2, 6].average()</pre>
+ * <pre class="groovyTestCase">
+ * assert 3 == [1, 2, 6].average()
+ * </pre>
*
* @param self Iterable of values to average
* @return The average of all of the items
+ * @see #average(Iterator)
* @since 3.0.0
*/
public static Object average(Iterable<?> self) {
@@ -6771,7 +6774,9 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* Averages the items in an array. This is equivalent to invoking the
* "plus" method on all items in the array and then dividing by the
* total count using the "div" method for the resulting sum.
- * <pre class="groovyTestCase">assert 3 == ([1, 2, 6] as Integer[]).average()</pre>
+ * <pre class="groovyTestCase">
+ * assert 3 == ([1, 2, 6] as Integer[]).average()
+ * </pre>
*
* @param self The array of values to average
* @return The average of all of the items
@@ -6790,6 +6795,27 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* "plus" method on all items in the array and then dividing by the
* total count using the "div" method for the resulting sum.
* The iterator will become exhausted of elements after determining the average value.
+ * While most frequently used with aggregates of numbers,
+ * {@code average} will work with any class supporting {@code plus} and {@code div}, e.g.:
+ * <pre class="groovyTestCase">
+ * class Stars {
+ * int numStars = 0
+ * String toString() {
+ * '*' * numStars
+ * }
+ * Stars plus(Stars other) {
+ * new Stars(numStars: numStars + other.numStars)
+ * }
+ * Stars div(Number divisor) {
+ * int newSize = numStars.intdiv(divisor)
+ * new Stars(numStars: newSize)
+ * }
+ * }
+ *
+ * def stars = [new Stars(numStars: 1), new Stars(numStars: 3)]
+ * assert stars*.toString() == ['*', '***']
+ * assert stars.average().toString() == '**'
+ * </pre>
*
* @param self an Iterator for the values to average
* @return The average of all of the items