This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 2ed4a76d75 GROOVY-10921: remove incubating eachBy variants
2ed4a76d75 is described below
commit 2ed4a76d759ff475c1463bf48956bee8649b0b21
Author: Paul King <[email protected]>
AuthorDate: Sat Apr 8 11:36:05 2023 +1000
GROOVY-10921: remove incubating eachBy variants
---
.../groovy/runtime/ArrayGroovyMethods.java | 192 +--------------------
.../runtime/ArrayGroovyMethodsSTCTest.groovy | 32 ++--
2 files changed, 21 insertions(+), 203 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
index 1efcbe956e..f84abba9d8 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
@@ -1007,29 +1007,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a boolean[] passing each boolean to the given closure.
- * <pre class="groovyTestCase">
- * boolean[] array = [false, true, false]
- * String result = ''
- * array.eachBy{ result += it.toString()[0] }
- * assert result == 'ftf'
- * </pre>
- *
- * @param self the boolean array over which we iterate
- * @param closure the closure applied on each boolean
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static boolean[] eachBy(boolean[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (boolean item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through a byte[] passing each byte to the given consumer.
* <pre class="groovyTestCase">
@@ -1053,29 +1030,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a byte[] passing each byte to the given closure.
- * <pre class="groovyTestCase">
- * byte[] array = [0, 1, 2]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == '012'
- * </pre>
- *
- * @param self the byte array over which we iterate
- * @param closure the closure applied on each byte
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static byte[] eachBy(byte[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (byte item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through a char[] passing each char to the given consumer.
* <pre class="groovyTestCase">
@@ -1099,29 +1053,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a char[] passing each char to the given closure.
- * <pre class="groovyTestCase">
- * char[] array = ['a' as char, 'b' as char, 'c' as char]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == 'abc'
- * </pre>
- *
- * @param self the char array over which we iterate
- * @param closure the closure applied on each char
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static char[] eachBy(char[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (char item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through a short[] passing each short to the given consumer.
* <pre class="groovyTestCase">
@@ -1145,29 +1076,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a short[] passing each short to the given closure.
- * <pre class="groovyTestCase">
- * short[] array = [0, 1, 2]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == '012'
- * </pre>
- *
- * @param self the short array over which we iterate
- * @param closure the closure applied on each short
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static short[] eachBy(short[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (short item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through an int[] passing each int to the given consumer.
* <pre class="groovyTestCase">
@@ -1191,29 +1099,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through an int[] passing each int to the given closure.
- * <pre class="groovyTestCase">
- * int[] array = [0, 1, 2]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == '012'
- * </pre>
- *
- * @param self the int array over which we iterate
- * @param closure the closure applied on each int
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static int[] eachBy(int[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (int item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through a long[] passing each long to the given consumer.
* <pre class="groovyTestCase">
@@ -1237,29 +1122,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a long[] passing each long to the given closure.
- * <pre class="groovyTestCase">
- * long[] array = [0L, 1L, 2L]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == '012'
- * </pre>
- *
- * @param self the long array over which we iterate
- * @param closure the closure applied on each long
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static long[] eachBy(long[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (long item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through a float[] passing each float to the given consumer.
* <pre class="groovyTestCase">
@@ -1283,29 +1145,6 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a float[] passing each float to the given closure.
- * <pre class="groovyTestCase">
- * float[] array = [0f, 1f, 2f]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == '0.01.02.0'
- * </pre>
- *
- * @param self the float array over which we iterate
- * @param closure the closure applied on each float
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static float[] eachBy(float[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (float item : self) {
- closure.call(item);
- }
- return self;
- }
-
/**
* Iterates through a double[] passing each double to the given consumer.
* <pre class="groovyTestCase">
@@ -1329,42 +1168,21 @@ public class ArrayGroovyMethods extends
DefaultGroovyMethodsSupport {
return self;
}
- /**
- * Iterates through a double[] passing each double to the given closure.
- * <pre class="groovyTestCase">
- * double[] array = [0d, 1d, 2d]
- * String result = ''
- * array.eachBy{ result += it }
- * assert result == '0.01.02.0'
- * </pre>
- *
- * @param self the double array over which we iterate
- * @param closure the closure applied on each double
- * @return the self array
- * @since 5.0.0
- */
- @Incubating
- public static double[] eachBy(double[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- Objects.requireNonNull(self);
- for (double item : self) {
- closure.call(item);
- }
- return self;
- }
-
//-------------------------------------------------------------------------
// eachByte
/**
- * Traverse through each byte of this byte array. Alias for each.
+ * Traverse through each byte of this byte array.
*
* @param self a byte array
* @param closure a closure
- * @see #eachBy(byte[], groovy.lang.Closure)
* @since 1.5.5
*/
public static void eachByte(byte[] self,
@ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- eachBy(self, closure);
+ Objects.requireNonNull(self);
+ for (double item : self) {
+ closure.call(item);
+ }
}
//-------------------------------------------------------------------------
diff --git
a/src/test/org/codehaus/groovy/runtime/ArrayGroovyMethodsSTCTest.groovy
b/src/test/org/codehaus/groovy/runtime/ArrayGroovyMethodsSTCTest.groovy
index 539accf2ca..e9fb0604da 100644
--- a/src/test/org/codehaus/groovy/runtime/ArrayGroovyMethodsSTCTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/ArrayGroovyMethodsSTCTest.groovy
@@ -80,74 +80,74 @@ class ArrayGroovyMethodsSTCTest extends
StaticTypeCheckingTestCase {
'''
}
- void testEachByForBooleanArray() {
+ void testEachForBooleanArray() {
assertScript '''
boolean[] array = [false, true, false]
String result = ''
- array.eachBy{ result += it.booleanValue() }
+ array.each{ result += it.booleanValue() }
assert result == 'falsetruefalse'
'''
}
- void testEachByForByteArray() {
+ void testEachForByteArray() {
assertScript '''
byte[] array = [0, 1, 2]
String result = ''
- array.eachBy{ result += it.intValue() }
+ array.each{ result += it.intValue() }
assert result == '012'
'''
}
- void testEachByForCharArray() {
+ void testEachForCharArray() {
assertScript '''
char[] array = 'abc'.chars
String result = ''
- array.eachBy{ result += it.charValue() }
+ array.each{ result += it.charValue() }
assert result == 'abc'
'''
}
- void testEachByForShortArray() {
+ void testEachForShortArray() {
assertScript '''
short[] array = [0, 1, 2]
String result = ''
- array.eachBy{ result += it.shortValue() }
+ array.each{ result += it.shortValue() }
assert result == '012'
'''
}
- void testEachByForIntArray() {
+ void testEachForIntArray() {
assertScript '''
int[] array = [0, 1, 2]
String result = ''
- array.eachBy{ result += it.intValue() }
+ array.each{ result += it.intValue() }
assert result == '012'
'''
}
- void testEachByForLongArray() {
+ void testEachForLongArray() {
assertScript '''
long[] array = [0L, 1L, 2L]
String result = ''
- array.eachBy{ result += it.longValue() }
+ array.each{ result += it.longValue() }
assert result == '012'
'''
}
- void testEachByForFloatArray() {
+ void testEachForFloatArray() {
assertScript '''
float[] array = [0f, 1f, 2f]
String result = ''
- array.eachBy{ result += it.floatValue() }
+ array.each{ result += it.floatValue() }
assert result == '0.01.02.0'
'''
}
- void testEachByForDoubleArray() {
+ void testEachForDoubleArray() {
assertScript '''
double[] array = [0d, 1d, 2d]
String result = ''
- array.eachBy{ result += it.doubleValue() }
+ array.each{ result += it.doubleValue() }
assert result == '0.01.02.0'
'''
}