moving object array extensions
diff --git a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
index c52f3ec..50b02b4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java
@@ -19,19 +19,26 @@
package org.codehaus.groovy.runtime;
import groovy.lang.Closure;
+import groovy.lang.EmptyRange;
import groovy.lang.IntRange;
+import groovy.lang.MetaClass;
import groovy.lang.ObjectRange;
import groovy.lang.Range;
import groovy.transform.stc.ClosureParams;
import groovy.transform.stc.FirstParam;
import groovy.transform.stc.FromString;
+import groovy.util.ClosureComparator;
+import groovy.util.OrderBy;
import groovy.util.function.DoubleComparator;
import groovy.util.function.IntComparator;
import groovy.util.function.LongComparator;
import org.apache.groovy.lang.annotation.Incubating;
import org.codehaus.groovy.runtime.callsite.BooleanClosureWrapper;
+import org.codehaus.groovy.runtime.callsite.BooleanReturningMethodInvoker;
import org.codehaus.groovy.runtime.dgmimpl.NumberNumberDiv;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
+import org.codehaus.groovy.util.ArrayIterable;
+import org.codehaus.groovy.util.ArrayIterator;
import org.codehaus.groovy.util.BooleanArrayIterator;
import org.codehaus.groovy.util.ByteArrayIterator;
import org.codehaus.groovy.util.CharArrayIterator;
@@ -50,12 +57,15 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.DoubleUnaryOperator;
@@ -65,10 +75,9 @@
import java.util.function.LongUnaryOperator;
/**
- * This class defines new groovy methods which appear on primitive arrays inside the Groovy environment.
- * Static methods are used with the
- * first parameter being the destination class,
- * i.e. <code>public static int[] each(int[] self, Closure closure)</code>
+ * This class defines new groovy methods which appear on primitive arrays inside
+ * the Groovy environment. Static methods are used with the first parameter being
+ * the destination class, i.e. <code>public static int[] each(int[] self, Closure closure)</code>
* provides a <code>each({i -> })</code> method for <code>int[]</code>.
* <p>
* NOTE: While this class contains many 'public' static methods, it is
@@ -80,7 +89,9 @@
* aim to keep the method available from within Groovy.
*/
public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport {
- public static final String FIRST = "first";
+
+ private ArrayGroovyMethods() {}
+
/* Arrangement of each method (skip any inapplicable types for the methods):
* 1. boolean[]
* 2. byte[]
@@ -90,12 +101,10 @@
* 6. long[]
* 7. float[]
* 8. double[]
+ * 9. Object[]
*/
- private ArrayGroovyMethods() {
- }
-
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// any
/**
@@ -304,7 +313,25 @@
return false;
}
- //-------------------------------------------------------------------------
+ /**
+ * Iterates over the contents of an Array, and checks whether a
+ * predicate is valid for at least one element.
+ *
+ * @param self the array over which we iterate
+ * @param predicate the closure predicate used for matching
+ * @return true if any iteration for the object matches the closure predicate
+ * @since 2.5.0
+ */
+ public static <T> boolean any(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
+ Objects.requireNonNull(self);
+ BooleanClosureWrapper bcw = new BooleanClosureWrapper(predicate);
+ for (T item : self) {
+ if (bcw.call(item)) return true;
+ }
+ return false;
+ }
+
+ //--------------------------------------------------------------------------
// asBoolean
/**
@@ -312,12 +339,12 @@
* A boolean array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(boolean[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(boolean[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -331,12 +358,12 @@
* assert array2
* </pre>
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(byte[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(byte[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -344,12 +371,12 @@
* A char array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(char[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(char[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -357,12 +384,12 @@
* A short array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(short[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(short[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -370,12 +397,12 @@
* An int array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(int[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(int[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -383,12 +410,12 @@
* A long array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(long[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(long[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -396,12 +423,12 @@
* A float array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(float[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(float[] self) {
+ return self != null && self.length > 0;
}
/**
@@ -409,17 +436,54 @@
* A double array is false if the array is of length 0,
* and true otherwise.
*
- * @param array an array
+ * @param self an array
* @return the array's boolean value
* @since 1.7.4
*/
- public static boolean asBoolean(double[] array) {
- return array != null && array.length > 0;
+ public static boolean asBoolean(double[] self) {
+ return self != null && self.length > 0;
}
- //-------------------------------------------------------------------------
- // asType (skipped, as it is not needed)
- //-------------------------------------------------------------------------
+ /**
+ * Coerces an object array to a boolean value.
+ * An Object array is false if the array is of length 0.
+ * and to true otherwise
+ *
+ * @param self the array
+ * @return the boolean value
+ * @since 1.7.0
+ */
+ public static boolean asBoolean(Object[] self) {
+ return self != null && self.length > 0;
+ }
+
+ //--------------------------------------------------------------------------
+ // asType
+
+ /**
+ * Converts the given array to either a List, Set, or SortedSet. If the given class is
+ * something else, the call is deferred to {@link DefaultGroovyMethods#asType(Object,Class)}.
+ *
+ * @param self an array
+ * @param type the desired class
+ * @return the object resulting from this type conversion
+ * @since 1.5.1
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T asType(Object[] self, Class<T> type) {
+ if (type == List.class) {
+ return (T) new ArrayList<>(Arrays.asList(self));
+ }
+ if (type == Set.class) {
+ return (T) new HashSet<>(Arrays.asList(self));
+ }
+ if (type == SortedSet.class) {
+ return (T) new TreeSet<>(Arrays.asList(self));
+ }
+ return DefaultGroovyMethods.asType((Object) self, type);
+ }
+
+ //--------------------------------------------------------------------------
// average
/**
@@ -524,7 +588,48 @@
return s / self.length;
}
- //-------------------------------------------------------------------------
+ /**
+ * 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>
+ *
+ * @param self The array of values to average
+ * @return The average of all the items
+ * @see #sum(java.lang.Object[])
+ * @since 3.0.0
+ */
+ public static Object average(Object[] self) {
+ Object result = sum(self);
+ MetaClass metaClass = InvokerHelper.getMetaClass(result);
+ result = metaClass.invokeMethod(result, "div", self.length);
+ return result;
+ }
+
+ /**
+ * Averages the result of applying a closure to each item of an array.
+ * <code>array.average(closure)</code> is equivalent to:
+ * <code>array.collect(closure).average()</code>.
+ * <pre class="groovyTestCase">
+ * def (nums, strings) = [[1, 3] as Integer[], ['to', 'from'] as String[]]
+ * assert 20 == nums.average { it * 10 }
+ * assert 3 == strings.average { it.size() }
+ * assert 3 == strings.average (String::size)
+ * </pre>
+ *
+ * @param self An array
+ * @param closure a single parameter closure that returns a (typically) numeric value.
+ * @return The average of the values returned by applying the closure to each
+ * item of the array.
+ * @since 3.0.0
+ */
+ public static <T> Object average(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.average(new ArrayIterator<>(self), closure);
+ }
+
+ //--------------------------------------------------------------------------
// chop
/**
@@ -679,15 +784,19 @@
return DefaultGroovyMethods.chop(new DoubleArrayIterator(self), chopSizes);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// collate
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// collect
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// collectEntries
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// collectMany
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// contains
/**
@@ -818,7 +927,7 @@
return false;
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// count
/**
@@ -973,15 +1082,65 @@
return DefaultGroovyMethods.count(new DoubleArrayIterator(self), value);
}
+ /**
+ * Counts the number of occurrences of the given value inside this array.
+ * Comparison is done using Groovy's == operator (using
+ * <code>compareTo(value) == 0</code> or <code>equals(value)</code> ).
+ *
+ * @param self the array within which we count the number of occurrences
+ * @param value the value being searched for
+ * @return the number of occurrences
+ * @since 1.6.4
+ */
+ public static Number count(Object[] self, Object value) {
+ return DefaultGroovyMethods.count(Arrays.asList(self), value);
+ }
+
+ /**
+ * Counts the number of occurrences which satisfy the given closure from inside this array.
+ *
+ * @param self the array within which we count the number of occurrences
+ * @param predicate a closure condition
+ * @return the number of occurrences
+ * @since 1.8.0
+ */
+ public static <T> Number count(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
+ return DefaultGroovyMethods.count(Arrays.asList(self), predicate);
+ }
+
//-------------------------------------------------------------------------
// countBy
+
+ /**
+ * Sorts all array members into groups determined by the supplied mapping
+ * closure and counts the group size. The closure should return the key that each
+ * item should be grouped by. The returned Map will have an entry for each
+ * distinct key returned from the closure, with each value being the frequency of
+ * items occurring for that group.
+ * <p>
+ * Example usage:
+ * <pre class="groovyTestCase">assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]</pre>
+ *
+ * @param self an array to group and count
+ * @param closure a closure mapping items to the frequency keys
+ * @return a new Map grouped by keys with frequency counts
+ * @see DefaultGroovyMethods#countBy(Iterator, Closure)
+ * @since 1.8.0
+ */
+ public static <K,E> Map<K, Integer> countBy(E[] self, @ClosureParams(FirstParam.Component.class) Closure<K> closure) {
+ return DefaultGroovyMethods.countBy(new ArrayIterator<>(self), closure);
+ }
+
//-------------------------------------------------------------------------
// drop
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// dropRight
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// dropWhile
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// each
/**
@@ -1168,11 +1327,32 @@
return self;
}
- //-------------------------------------------------------------------------
+ /**
+ * Iterates through an array passing each array entry to the given closure.
+ * <pre class="groovyTestCase">
+ * String[] letters = ['a', 'b', 'c']
+ * String result = ''
+ * letters.each{ result += it }
+ * assert result == 'abc'
+ * </pre>
+ *
+ * @param self the array over which we iterate
+ * @param closure the closure applied on each array entry
+ * @return the self array
+ * @since 2.5.0
+ */
+ public static <T> T[] each(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ for (T item : self) {
+ closure.call(item);
+ }
+ return self;
+ }
+
+ //--------------------------------------------------------------------------
// eachByte
/**
- * Traverse through each byte of this byte array.
+ * Traverses through each byte of this byte array.
*
* @param self a byte array
* @param closure a closure
@@ -1185,7 +1365,18 @@
}
}
- //-------------------------------------------------------------------------
+ /**
+ * Traverses through each byte of this Byte array. Alias for each.
+ *
+ * @param self a Byte array
+ * @param closure a closure
+ * @since 1.5.5
+ */
+ public static void eachByte(Byte[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ each(self, closure);
+ }
+
+ //--------------------------------------------------------------------------
// eachWithIndex
/**
@@ -1204,7 +1395,7 @@
* @return the self array
* @since 5.0.0
*/
- public static boolean[] eachWithIndex(boolean[] self, @ClosureParams(value = FromString.class, options = "Boolean,Integer") Closure<?> closure) {
+ public static boolean[] eachWithIndex(boolean[] self, @ClosureParams(value=FromString.class,options="Boolean,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1231,7 +1422,7 @@
* @return the self array
* @since 5.0.0
*/
- public static byte[] eachWithIndex(byte[] self, @ClosureParams(value = FromString.class, options = "Byte,Integer") Closure<?> closure) {
+ public static byte[] eachWithIndex(byte[] self, @ClosureParams(value=FromString.class,options="Byte,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1258,7 +1449,7 @@
* @return the self array
* @since 5.0.0
*/
- public static char[] eachWithIndex(char[] self, @ClosureParams(value = FromString.class, options = "Character,Integer") Closure<?> closure) {
+ public static char[] eachWithIndex(char[] self, @ClosureParams(value=FromString.class,options="Character,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1285,7 +1476,7 @@
* @return the self array
* @since 5.0.0
*/
- public static short[] eachWithIndex(short[] self, @ClosureParams(value = FromString.class, options = "Short,Integer") Closure<?> closure) {
+ public static short[] eachWithIndex(short[] self, @ClosureParams(value=FromString.class,options="Short,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1312,7 +1503,7 @@
* @return the self array
* @since 5.0.0
*/
- public static int[] eachWithIndex(int[] self, @ClosureParams(value = FromString.class, options = "Integer,Integer") Closure<?> closure) {
+ public static int[] eachWithIndex(int[] self, @ClosureParams(value=FromString.class,options="Integer,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1339,7 +1530,7 @@
* @return the self array
* @since 5.0.0
*/
- public static long[] eachWithIndex(long[] self, @ClosureParams(value = FromString.class, options = "Long,Integer") Closure<?> closure) {
+ public static long[] eachWithIndex(long[] self, @ClosureParams(value=FromString.class,options="Long,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1366,7 +1557,7 @@
* @return the self array
* @since 5.0.0
*/
- public static float[] eachWithIndex(float[] self, @ClosureParams(value = FromString.class, options = "Float,Integer") Closure<?> closure) {
+ public static float[] eachWithIndex(float[] self, @ClosureParams(value=FromString.class,options="Float,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1393,7 +1584,7 @@
* @return the self array
* @since 5.0.0
*/
- public static double[] eachWithIndex(double[] self, @ClosureParams(value = FromString.class, options = "Double,Integer") Closure<?> closure) {
+ public static double[] eachWithIndex(double[] self, @ClosureParams(value=FromString.class,options="Double,Integer") Closure<?> closure) {
Objects.requireNonNull(self);
final Object[] args = new Object[2];
for (int i = 0, n = self.length; i < n; i += 1) {
@@ -1404,7 +1595,33 @@
return self;
}
- //-------------------------------------------------------------------------
+ /**
+ * Iterates through an array, passing each array element and the element's
+ * index (a counter starting at zero) to the given closure.
+ * <pre class="groovyTestCase">
+ * String[] letters = ['a', 'b', 'c']
+ * String result = ''
+ * letters.eachWithIndex{ letter, index {@code ->} result += "$index:$letter" }
+ * assert result == '0:a1:b2:c'
+ * </pre>
+ *
+ * @param self an array
+ * @param closure a Closure to operate on each array entry
+ * @return the self array
+ * @since 2.5.0
+ */
+ public static <T> T[] eachWithIndex(T[] self, @ClosureParams(value=FromString.class,options="T,Integer") Closure<?> closure) {
+ final Object[] args = new Object[2];
+ int counter = 0;
+ for(T item : self) {
+ args[0] = item;
+ args[1] = counter++;
+ closure.call(args);
+ }
+ return self;
+ }
+
+ //--------------------------------------------------------------------------
// equals
/**
@@ -1418,13 +1635,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a boolean array
+ * @param self a boolean array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(boolean[] left, boolean[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(boolean[] self, boolean[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1438,13 +1655,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a byte array
+ * @param self a byte array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(byte[] left, byte[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(byte[] self, byte[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1458,13 +1675,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a char array
+ * @param self a char array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(char[] left, char[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(char[] self, char[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1478,13 +1695,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a short array
+ * @param self a short array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(short[] left, short[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(short[] self, short[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1498,13 +1715,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left an int array
+ * @param self an int array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(int[] left, int[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(int[] self, int[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1518,13 +1735,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a long array
+ * @param self a long array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(long[] left, long[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(long[] self, long[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1538,13 +1755,13 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a float array
+ * @param self a float array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(float[] left, float[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(float[] self, float[] right) {
+ return Arrays.equals(self, right);
}
/**
@@ -1558,16 +1775,16 @@
* assert array1.equals(array2)
* </pre>
*
- * @param left a double array
+ * @param self a double array
* @param right the array being compared
* @return true if the contents of both arrays are equal.
* @since 5.0.0
*/
- public static boolean equals(double[] left, double[] right) {
- return Arrays.equals(left, right);
+ public static boolean equals(double[] self, double[] right) {
+ return Arrays.equals(self, right);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// every
/**
@@ -1603,7 +1820,7 @@
*
* @param self the boolean array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(boolean[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1626,7 +1843,7 @@
*
* @param self the byte array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(byte[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1649,7 +1866,7 @@
*
* @param self the char array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(char[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1672,7 +1889,7 @@
*
* @param self the char array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(short[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1695,7 +1912,7 @@
*
* @param self the int array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(int[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1718,7 +1935,7 @@
*
* @param self the long array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(long[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1741,7 +1958,7 @@
*
* @param self the float array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(float[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1764,7 +1981,7 @@
*
* @param self the double array over which we iterate
* @param predicate the closure predicate used for matching
- * @return true if the closure predicate is true for all elements in the array
+ * @return true if the predicate returns true for all elements in the array
* @since 5.0.0
*/
public static boolean every(double[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
@@ -1776,21 +1993,131 @@
return true;
}
- //-------------------------------------------------------------------------
+ /**
+ * Used to determine if the given predicate closure is valid (i.e. returns
+ * <code>true</code> for all items in this Array).
+ *
+ * @param self an array
+ * @param predicate the closure predicate used for matching
+ * @return true if the predicate returns true for all elements in the array
+ * @since 2.5.0
+ */
+ public static <T> boolean every(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> predicate) {
+ Objects.requireNonNull(self);
+ BooleanClosureWrapper bcw = new BooleanClosureWrapper(predicate);
+ for (T item : self) {
+ if (!bcw.call(item)) return false;
+ }
+ return true;
+ }
+
+ //--------------------------------------------------------------------------
// find
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// findAll
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// findIndexOf
- //-------------------------------------------------------------------------
+
+ /**
+ * Iterates over the elements of an array and returns the index of the first
+ * item that satisfies the condition specified by the closure.
+ *
+ * @param self an array
+ * @param condition the matching condition
+ * @return an integer that is the index of the first matched object or -1 if no match was found
+ * @since 2.5.0
+ */
+ public static <T> int findIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> condition) {
+ return findIndexOf(self, 0, condition);
+ }
+
+ /**
+ * Iterates over the elements of an array, starting from a specified index,
+ * and returns the index of the first item that satisfies the condition
+ * specified by the closure.
+ *
+ * @param self an array
+ * @param startIndex start matching from this index
+ * @param condition the matching condition
+ * @return an integer that is the index of the first matched object or -1 if no match was found
+ * @since 2.5.0
+ */
+ public static <T> int findIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure<?> condition) {
+ return DefaultGroovyMethods.findIndexOf(new ArrayIterator<>(self), startIndex, condition);
+ }
+
+ //--------------------------------------------------------------------------
// findIndexValues
- //-------------------------------------------------------------------------
+
+ /**
+ * Iterates over the elements of an array and returns the index values of
+ * the items that match the condition specified in the closure.
+ *
+ * @param self an array
+ * @param condition the matching condition
+ * @return a list of numbers corresponding to the index values of all matched objects
+ * @since 2.5.0
+ */
+ public static <T> List<Number> findIndexValues(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> condition) {
+ return findIndexValues(self, 0, condition);
+ }
+
+ /**
+ * Iterates over the elements of an array, starting from a specified index,
+ * and returns the index values of the items that match the condition
+ * specified in the closure.
+ *
+ * @param self an array
+ * @param startIndex start matching from this index
+ * @param condition the matching condition
+ * @return a list of numbers corresponding to the index values of all matched objects
+ * @since 2.5.0
+ */
+ public static <T> List<Number> findIndexValues(T[] self, Number startIndex, @ClosureParams(FirstParam.Component.class) Closure<?> condition) {
+ return DefaultGroovyMethods.findIndexValues(new ArrayIterator<>(self), startIndex, condition);
+ }
+
+ //--------------------------------------------------------------------------
// findLastIndexOf
- //-------------------------------------------------------------------------
+
+ /**
+ * Iterates over the elements of an array and returns the index of the last
+ * item that matches the condition specified in the closure.
+ *
+ * @param self an array
+ * @param condition the matching condition
+ * @return an integer that is the index of the last matched object or -1 if no match was found
+ * @since 2.5.0
+ */
+ public static <T> int findLastIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> condition) {
+ return DefaultGroovyMethods.findLastIndexOf(new ArrayIterator<>(self), 0, condition);
+ }
+
+ /**
+ * Iterates over the elements of an array, starting from a specified index,
+ * and returns the index of the last item that matches the condition
+ * specified in the closure.
+ *
+ * @param self an array
+ * @param startIndex start matching from this index
+ * @param condition the matching condition
+ * @return an integer that is the index of the last matched object or -1 if no match was found
+ * @since 2.5.0
+ */
+ public static <T> int findLastIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure<?> condition) {
+ // TODO: Could this be made more efficient by using a reverse index?
+ return DefaultGroovyMethods.findLastIndexOf(new ArrayIterator<>(self), startIndex, condition);
+ }
+
+ //--------------------------------------------------------------------------
// findResult
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// findResults
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// first
/**
@@ -1808,7 +2135,7 @@
*/
public static boolean first(boolean[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1827,7 +2154,7 @@
*/
public static byte first(byte[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1846,7 +2173,7 @@
*/
public static char first(char[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1865,7 +2192,7 @@
*/
public static short first(short[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1884,7 +2211,7 @@
*/
public static int first(int[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1903,7 +2230,7 @@
*/
public static long first(long[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1922,7 +2249,7 @@
*/
public static float first(float[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
@@ -1941,15 +2268,15 @@
*/
public static double first(double[] self) {
Objects.requireNonNull(self);
- throwNoSuchElementIfEmpty(self.length, FIRST);
+ throwNoSuchElementIfEmpty(self.length, "first");
return self[0];
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// flatten
/**
- * Flatten an array. This array is added to a new collection.
+ * Flattens an array. This array is added to a new collection.
* It is an alias for {@code toList()} but allows algorithms to be written which also
* work on multidimensional arrays or non-arrays where flattening would be applicable.
* <pre class="groovyTestCase">
@@ -1961,12 +2288,133 @@
* @return a Collection of the array elements
* @since 1.6.0
*/
- public static Collection<Boolean> flatten(boolean[] self) {
+ public static List<Boolean> flatten(boolean[] self) {
return toList(self);
}
/**
- * Flatten a 2D array into a new collection.
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * byte[] array = [0, 1]
+ * assert array.flatten() == [0, 1]
+ * </pre>
+ *
+ * @param self a byte Array
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Byte> flatten(byte[] self) {
+ return toList(self);
+ }
+
+ /**
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * char[] array = 'ab'.chars
+ * assert array.flatten() == ['a', 'b']
+ * </pre>
+ *
+ * @param self a char Array
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Character> flatten(char[] self) {
+ return toList(self);
+ }
+
+ /**
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * short[] array = [0, 1]
+ * assert array.flatten() == [0, 1]
+ * </pre>
+ *
+ * @param self a short Array
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Short> flatten(short[] self) {
+ return toList(self);
+ }
+
+ /**
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * int[] array = [0, 1]
+ * assert array.flatten() == [0, 1]
+ * </pre>
+ *
+ * @param self an int Array
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Integer> flatten(int[] self) {
+ return toList(self);
+ }
+
+ /**
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * long[] array = [0L, 1L]
+ * assert array.flatten() == [0L, 1L]
+ * </pre>
+ *
+ * @param self a long Array to flatten
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Long> flatten(long[] self) {
+ return toList(self);
+ }
+
+ /**
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * float[] array = [0.0f, 1.0f]
+ * assert array.flatten() == [0.0f, 1.0f]
+ * </pre>
+ *
+ * @param self a float Array to flatten
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Float> flatten(float[] self) {
+ return toList(self);
+ }
+
+ /**
+ * Flattens an array. This array is added to a new collection.
+ * It is an alias for {@code toList()} but allows algorithms to be written which also
+ * work on multidimensional arrays or non-arrays where flattening would be applicable.
+ * <pre class="groovyTestCase">
+ * double[] array = [0.0d, 1.0d]
+ * assert array.flatten() == [0.0d, 1.0d]
+ * </pre>
+ *
+ * @param self a double Array to flatten
+ * @return a Collection of the array elements
+ * @since 1.6.0
+ */
+ public static List<Double> flatten(double[] self) {
+ return toList(self);
+ }
+
+ //
+
+ /**
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -1979,7 +2427,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Boolean> flatten(boolean[][] self) {
+ public static List<Boolean> flatten(boolean[][] self) {
Objects.requireNonNull(self);
List<Boolean> result = new ArrayList<>();
for (boolean[] booleans : self) {
@@ -1989,24 +2437,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * byte[] array = [0, 1]
- * assert array.flatten() == [0, 1]
- * </pre>
- *
- * @param self a byte Array
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Byte> flatten(byte[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2019,7 +2450,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Byte> flatten(byte[][] self) {
+ public static List<Byte> flatten(byte[][] self) {
Objects.requireNonNull(self);
List<Byte> result = new ArrayList<>();
for (byte[] bytes : self) {
@@ -2029,24 +2460,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * char[] array = 'ab'.chars
- * assert array.flatten() == ['a', 'b']
- * </pre>
- *
- * @param self a char Array
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Character> flatten(char[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2059,7 +2473,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Character> flatten(char[][] self) {
+ public static List<Character> flatten(char[][] self) {
Objects.requireNonNull(self);
List<Character> result = new ArrayList<>();
for (char[] chars : self) {
@@ -2069,24 +2483,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * short[] array = [0, 1]
- * assert array.flatten() == [0, 1]
- * </pre>
- *
- * @param self a short Array
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Short> flatten(short[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2099,7 +2496,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Short> flatten(short[][] self) {
+ public static List<Short> flatten(short[][] self) {
Objects.requireNonNull(self);
List<Short> result = new ArrayList<>();
for (short[] shorts : self) {
@@ -2109,24 +2506,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * int[] array = [0, 1]
- * assert array.flatten() == [0, 1]
- * </pre>
- *
- * @param self an int Array
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Integer> flatten(int[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2139,7 +2519,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Integer> flatten(int[][] self) {
+ public static List<Integer> flatten(int[][] self) {
Objects.requireNonNull(self);
List<Integer> result = new ArrayList<>();
for (int[] ints : self) {
@@ -2149,24 +2529,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * long[] array = [0L, 1L]
- * assert array.flatten() == [0L, 1L]
- * </pre>
- *
- * @param self a long Array to flatten
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Long> flatten(long[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2179,7 +2542,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Long> flatten(long[][] self) {
+ public static List<Long> flatten(long[][] self) {
Objects.requireNonNull(self);
List<Long> result = new ArrayList<>();
for (long[] longs : self) {
@@ -2189,24 +2552,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * float[] array = [0.0f, 1.0f]
- * assert array.flatten() == [0.0f, 1.0f]
- * </pre>
- *
- * @param self a float Array to flatten
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Float> flatten(float[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2219,7 +2565,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Float> flatten(float[][] self) {
+ public static List<Float> flatten(float[][] self) {
Objects.requireNonNull(self);
List<Float> result = new ArrayList<>();
for (float[] floats : self) {
@@ -2229,24 +2575,7 @@
}
/**
- * Flatten an array. This array is added to a new collection.
- * It is an alias for {@code toList()} but allows algorithms to be written which also
- * work on multidimensional arrays or non-arrays where flattening would be applicable.
- * <pre class="groovyTestCase">
- * double[] array = [0.0d, 1.0d]
- * assert array.flatten() == [0.0d, 1.0d]
- * </pre>
- *
- * @param self a double Array to flatten
- * @return a Collection of the array elements
- * @since 1.6.0
- */
- public static Collection<Double> flatten(double[] self) {
- return toList(self);
- }
-
- /**
- * Flatten a 2D array into a new collection.
+ * Flattens a 2D array into a new collection.
* The items are copied row by row.
* <p>
* Example usage:
@@ -2259,7 +2588,7 @@
* @return a Collection of the array elements
* @since 5.0.0
*/
- public static Collection<Double> flatten(double[][] self) {
+ public static List<Double> flatten(double[][] self) {
Objects.requireNonNull(self);
List<Double> result = new ArrayList<>();
for (double[] doubles : self) {
@@ -2268,7 +2597,7 @@
return result;
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// getAt
/**
@@ -2286,7 +2615,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Boolean> getAt(boolean[] array, Range range) {
+ public static List<Boolean> getAt(boolean[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2305,7 +2634,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Byte> getAt(byte[] array, Range range) {
+ public static List<Byte> getAt(byte[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2324,7 +2653,7 @@
* @since 1.5.0
*/
@SuppressWarnings("unchecked")
- public static List<Character> getAt(char[] array, Range range) {
+ public static List<Character> getAt(char[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2343,7 +2672,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Short> getAt(short[] array, Range range) {
+ public static List<Short> getAt(short[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2362,7 +2691,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Integer> getAt(int[] array, Range range) {
+ public static List<Integer> getAt(int[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2381,7 +2710,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Long> getAt(long[] array, Range range) {
+ public static List<Long> getAt(long[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2400,7 +2729,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Float> getAt(float[] array, Range range) {
+ public static List<Float> getAt(float[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
@@ -2419,11 +2748,26 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Double> getAt(double[] array, Range range) {
+ public static List<Double> getAt(double[] array, Range<?> range) {
return primitiveArrayGet(array, range);
}
/**
+ * Support the subscript operator for an object array with a range giving the desired indices.
+ *
+ * @param array an Array of Objects
+ * @param range a Range
+ * @return a range of a list from the range's from index up to but not
+ * including the range's to value
+ * @since 1.0
+ */
+ public static <T> List<T> getAt(T[] array, Range<?> range) {
+ return DefaultGroovyMethods.getAt(Arrays.asList(array), range);
+ }
+
+ //
+
+ /**
* Support the subscript operator for a boolean array with an IntRange giving the desired indices.
* <pre class="groovyTestCase">
* boolean[] array = [false, false, true, true, false]
@@ -2592,6 +2936,20 @@
}
/**
+ *
+ * @param array an object array
+ * @param range an IntRange
+ * @return a range of a list from the range's from index up to but not
+ * including the range's to value
+ * @since 1.0
+ */
+ public static <T> List<T> getAt(T[] array, IntRange range) {
+ return DefaultGroovyMethods.getAt(Arrays.asList(array), range);
+ }
+
+ //
+
+ /**
* Support the subscript operator for a boolean array with an ObjectRange giving the desired indices.
* <pre class="groovyTestCase">
* boolean[] array = [false, false, true, true, false]
@@ -2736,6 +3094,32 @@
}
/**
+ * @param array an Array of Objects
+ * @param range an ObjectRange
+ * @return a range of a list from the range's from index up to but not
+ * including the range's to value
+ * @since 1.0
+ */
+ public static <T> List<T> getAt(T[] array, ObjectRange range) {
+ return DefaultGroovyMethods.getAt(Arrays.asList(array), range);
+ }
+
+ //
+
+ /**
+ *
+ * @param array an Array of Objects
+ * @param range an EmptyRange
+ * @return an empty Range
+ * @since 1.5.0
+ */
+ public static <T> List<T> getAt(T[] array, EmptyRange<?> range) {
+ return new ArrayList<>();
+ }
+
+ //
+
+ /**
* Support the subscript operator for a boolean array
* with a (potentially nested) collection giving the desired indices.
* <pre class="groovyTestCase">
@@ -2750,7 +3134,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Boolean> getAt(boolean[] array, Collection indices) {
+ public static List<Boolean> getAt(boolean[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2769,7 +3153,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Byte> getAt(byte[] array, Collection indices) {
+ public static List<Byte> getAt(byte[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2788,7 +3172,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Character> getAt(char[] array, Collection indices) {
+ public static List<Character> getAt(char[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2807,7 +3191,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Short> getAt(short[] array, Collection indices) {
+ public static List<Short> getAt(short[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2826,7 +3210,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Integer> getAt(int[] array, Collection indices) {
+ public static List<Integer> getAt(int[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2845,7 +3229,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Long> getAt(long[] array, Collection indices) {
+ public static List<Long> getAt(long[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2864,7 +3248,7 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Float> getAt(float[] array, Collection indices) {
+ public static List<Float> getAt(float[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
@@ -2883,11 +3267,35 @@
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Double> getAt(double[] array, Collection indices) {
+ public static List<Double> getAt(double[] array, Collection<?> indices) {
return primitiveArrayGet(array, indices);
}
- //-------------------------------------------------------------------------
+ /**
+ * Select a List of items from an array using a Collection to
+ * identify the indices to be selected.
+ *
+ * @param array an object array
+ * @param indices a collection of indices
+ * @return a new list of the values at the given indices
+ * @since 1.0
+ */
+ public static <T> List<T> getAt(T[] array, Collection<?> indices) {
+ List<T> answer = new ArrayList<>(indices.size());
+ for (Object value : indices) {
+ if (value instanceof Range) {
+ answer.addAll(getAt(array, (Range<?>) value));
+ } else if (value instanceof Collection) {
+ answer.addAll(getAt(array, (Collection<?>) value));
+ } else {
+ int idx = DefaultTypeTransformation.intUnbox(value);
+ answer.add(array[normaliseIndex(idx, array.length)]);
+ }
+ }
+ return answer;
+ }
+
+ //--------------------------------------------------------------------------
// getIndices
/**
@@ -3010,11 +3418,79 @@
return new IntRange(false, 0, self.length);
}
- //-------------------------------------------------------------------------
+ /**
+ * Returns indices of the array.
+ * <p>
+ * Example:
+ * <pre class="groovyTestCase">
+ * String[] letters = ['a', 'b', 'c', 'd']
+ * {@code assert 0..<4 == letters.indices}
+ * </pre>
+ *
+ * @param self an array
+ * @return an index range
+ * @since 2.4.0
+ */
+ public static <T> IntRange getIndices(T[] self) {
+ return new IntRange(false, 0, self.length);
+ }
+
+ //--------------------------------------------------------------------------
// grep
- //-------------------------------------------------------------------------
+
+ /**
+ * Iterates over the array returning each element that matches
+ * using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.
+ * <p>
+ * Example:
+ * <pre class="groovyTestCase">
+ * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[]
+ * assert items.grep() == [1, 2, true, 'foo', [4, 5]]
+ * </pre>
+ *
+ * @param self an array
+ * @return a list of elements which satisfy Groovy truth
+ * @see Closure#IDENTITY
+ * @since 2.0
+ */
+ public static <T> List<T> grep(T[] self) {
+ return grep(self, Closure.IDENTITY);
+ }
+
+ /**
+ * Iterates over the array of items and returns a collection of items that match
+ * the given filter - calling the {@link DefaultGroovyMethods#isCase(Object,Object)}
+ * method used by switch statements. This method can be used with different
+ * kinds of filters like regular expressions, classes, ranges etc.
+ * Example:
+ * <pre class="groovyTestCase">
+ * def items = ['a', 'b', 'aa', 'bc', 3, 4.5] as Object[]
+ * assert items.grep( ~/a+/ ) == ['a', 'aa']
+ * assert items.grep( ~/../ ) == ['aa', 'bc']
+ * assert items.grep( Number ) == [ 3, 4.5 ]
+ * assert items.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
+ * </pre>
+ *
+ * @param self an array
+ * @param filter the filter to perform on each element of the array (using the {@link #isCase(java.lang.Object, java.lang.Object)} method)
+ * @return a list of objects which match the filter
+ * @since 2.0
+ */
+ public static <T> List<T> grep(T[] self, Object filter) {
+ List<T> answer = new ArrayList<>();
+ BooleanReturningMethodInvoker bmi = new BooleanReturningMethodInvoker("isCase");
+ for (T element : self) {
+ if (bmi.invoke(filter, element)) {
+ answer.add(element);
+ }
+ }
+ return answer;
+ }
+
+ //--------------------------------------------------------------------------
// groupBy
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// head
/**
@@ -3169,7 +3645,7 @@
return self[0];
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// indexed
/**
@@ -3189,6 +3665,40 @@
}
/**
+ * Zips a long[] with indices in (index, value) order starting from index 0.
+ * <p/>
+ * Example usage:
+ * <pre class="groovyTestCase">
+ * long[] nums = [10L, 20L, 30L]
+ * assert [0: 10L, 1: 20L, 2: 30L] == nums.indexed()
+ * </pre>
+ *
+ * @see #indexed(long[], int)
+ * @since 3.0.8
+ */
+ public static Map<Integer, Long> indexed(long[] self) {
+ return indexed(self, 0);
+ }
+
+ /**
+ * Zips a double[] with indices in (index, value) order starting from index 0.
+ * <p/>
+ * Example usage:
+ * <pre class="groovyTestCase">
+ * double[] nums = [10.0d, 20.0d, 30.0d]
+ * assert [0: 10.0d, 1: 20.0d, 2: 30.0d] == nums.indexed()
+ * </pre>
+ *
+ * @see #indexed(double[], int)
+ * @since 3.0.8
+ */
+ public static Map<Integer, Double> indexed(double[] self) {
+ return indexed(self, 0);
+ }
+
+ //
+
+ /**
* Zips an int[] with indices in (index, value) order.
* <p/>
* Example usage:
@@ -3209,22 +3719,6 @@
}
/**
- * Zips a long[] with indices in (index, value) order starting from index 0.
- * <p/>
- * Example usage:
- * <pre class="groovyTestCase">
- * long[] nums = [10L, 20L, 30L]
- * assert [0: 10L, 1: 20L, 2: 30L] == nums.indexed()
- * </pre>
- *
- * @see #indexed(long[], int)
- * @since 3.0.8
- */
- public static Map<Integer, Long> indexed(long[] self) {
- return indexed(self, 0);
- }
-
- /**
* Zips a long[] with indices in (index, value) order.
* <p/>
* Example usage:
@@ -3244,22 +3738,6 @@
}
/**
- * Zips a double[] with indices in (index, value) order starting from index 0.
- * <p/>
- * Example usage:
- * <pre class="groovyTestCase">
- * double[] nums = [10.0d, 20.0d, 30.0d]
- * assert [0: 10.0d, 1: 20.0d, 2: 30.0d] == nums.indexed()
- * </pre>
- *
- * @see #indexed(double[], int)
- * @since 3.0.8
- */
- public static Map<Integer, Double> indexed(double[] self) {
- return indexed(self, 0);
- }
-
- /**
* Zips a double[] with indices in (index, value) order.
* <p/>
* Example usage:
@@ -3278,7 +3756,7 @@
return DefaultGroovyMethods.indexed(new DoubleArrayIterable(self), offset);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// init
/**
@@ -3441,11 +3919,68 @@
return Arrays.copyOfRange(self, 0, self.length - 1);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// inject
- //-------------------------------------------------------------------------
+
+ /**
+ * Iterates through the given array as with inject(Object[],initialValue,closure), but
+ * using the first element of the array as the initialValue, and then iterating
+ * the remaining elements of the array.
+ *
+ * @param self an array
+ * @param closure a closure
+ * @return the result of the last closure call
+ * @throws NoSuchElementException if the array is empty.
+ * @see #inject(Object[], Object, Closure)
+ * @since 1.8.7
+ */
+ public static <E,T, V extends T> T inject(E[] self, @ClosureParams(value=FromString.class,options="E,E") Closure<V> closure) {
+ return DefaultGroovyMethods.inject((Object) self, closure);
+ }
+
+ /**
+ * Iterates through the given array, passing in the initial value to
+ * the closure along with the first item. The result is passed back (injected) into
+ * the closure along with the second item. The new result is injected back into
+ * the closure along with the third item and so on until all elements of the array
+ * have been used.
+ * <p>
+ * Also known as foldLeft in functional parlance.
+ *
+ * @param self an Object[]
+ * @param initialValue some initial value
+ * @param closure a closure
+ * @return the result of the last closure call
+ * @since 1.5.0
+ */
+ public static <E, T, U extends T, V extends T> T inject(E[] self, U initialValue, @ClosureParams(value=FromString.class,options="U,E") Closure<V> closure) {
+ Object[] params = new Object[2];
+ T value = initialValue;
+ for (Object next : self) {
+ params[0] = value;
+ params[1] = next;
+ value = closure.call(params);
+ }
+ return value;
+ }
+
+ //--------------------------------------------------------------------------
// iterator
- //-------------------------------------------------------------------------
+
+ /**
+ * Attempts to create an Iterator for the given object by first
+ * converting it to a Collection.
+ *
+ * @param self an array
+ * @return an Iterator for the given Array.
+ * @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object[])
+ * @since 1.6.4
+ */
+ public static <T> Iterator<T> iterator(final T[] self) {
+ return DefaultTypeTransformation.asCollection(self).iterator();
+ }
+
+ //--------------------------------------------------------------------------
// join
/**
@@ -3552,7 +4087,21 @@
return DefaultGroovyMethods.join(new DoubleArrayIterator(self), separator);
}
- //-------------------------------------------------------------------------
+ /**
+ * Concatenates the <code>toString()</code> representation of each
+ * item in this array, with the given String as a separator between each
+ * item.
+ *
+ * @param self an array of Object
+ * @param separator a String separator
+ * @return the joined String
+ * @since 1.0
+ */
+ public static <T> String join(T[] self, String separator) {
+ return DefaultGroovyMethods.join(new ArrayIterator<>(self), separator);
+ }
+
+ //--------------------------------------------------------------------------
// last
/**
@@ -3699,7 +4248,7 @@
return self[self.length - 1];
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// max
/**
@@ -3727,6 +4276,68 @@
}
/**
+ * Adds max() method to long arrays.
+ * <p/>
+ * Example usage:
+ * <pre class="groovyTestCase">
+ * long[] nums = [1L, 3L, 2L]
+ * assert 3L == nums.max()
+ * </pre>
+ *
+ * @param self a long array
+ * @return the maximum value
+ * @since 3.0.8
+ */
+ public static long max(long[] self) {
+ Objects.requireNonNull(self);
+ throwUnsupportedOperationIfEmpty(self.length, "max");
+ long answer = self[0];
+ for (int i = 1; i < self.length; i++) {
+ long value = self[i];
+ if (value > answer) answer = value;
+ }
+ return answer;
+ }
+
+ /**
+ * Adds max() method to double arrays.
+ * <p/>
+ * Example usage:
+ * <pre class="groovyTestCase">
+ * double[] nums = [1.1d, 3.3d, 2.2d]
+ * assert 3.3d == nums.max()
+ * </pre>
+ *
+ * @param self a double array
+ * @return the maximum value
+ * @since 3.0.8
+ */
+ public static double max(double[] self) {
+ Objects.requireNonNull(self);
+ throwUnsupportedOperationIfEmpty(self.length, "max");
+ double answer = self[0];
+ for (int i = 1; i < self.length; i++) {
+ double value = self[i];
+ if (value > answer) answer = value;
+ }
+ return answer;
+ }
+
+ /**
+ * Adds max() method to Object arrays.
+ *
+ * @param self an array
+ * @return the maximum value
+ * @see #max(Iterator)
+ * @since 1.5.5
+ */
+ public static <T> T max(T[] self) {
+ return DefaultGroovyMethods.max(new ArrayIterator<>(self));
+ }
+
+ //
+
+ /**
* Selects the maximum value found from the int array
* using the supplier IntBinaryOperator as a comparator to determine the maximum of any two values.
* <p>
@@ -3792,81 +4403,6 @@
}
/**
- * Selects the maximum value found from the int array
- * using the closure to determine the maximum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * int[] nums = [30, 45, 60, 90]
- * assert 90 == nums.maxBy{ Math.sin(Math.toRadians(it)) }
- * assert 30 == nums.maxBy{ Math.cos(Math.toRadians(it)) } // cos(90) == 0
- * </pre>
- * <p>
- * If the closure has two parameters it is used like a traditional Comparator,
- * i.e., it should compare its two parameters for order, returning a negative integer,
- * zero, or a positive integer when the first parameter is less than,
- * equal to, or greater than the second respectively. Otherwise,
- * the Closure is assumed to take a single parameter and return a
- * Comparable (typically an Integer) which is then used for
- * further comparison.
- *
- * @param self an int array
- * @param closure a Closure used to determine the correct ordering
- * @return the maximum value
- * @see DefaultGroovyMethods#max(Iterator, groovy.lang.Closure)
- * @since 5.0.0
- */
- @Incubating
- public static int maxBy(int[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- return DefaultGroovyMethods.max(new IntArrayIterator(self), closure);
- }
-
- /**
- * Selects the maximum value found from the int array
- * using the comparator to determine the maximum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * int[] nums = [10, 20, 30]
- * assert 30 == nums.maxComparing(Comparator.naturalOrder())
- * assert 10 == nums.maxComparing(Comparator.reverseOrder())
- * </pre>
- * <p>
- *
- * @param self an int array
- * @param comparator a Comparator
- * @return the maximum value
- * @see DefaultGroovyMethods#max(Iterator, java.util.Comparator)
- * @since 5.0.0
- */
- @Incubating
- public static int maxComparing(int[] self, Comparator<Integer> comparator) {
- return DefaultGroovyMethods.max(new IntArrayIterator(self), comparator);
- }
-
- /**
- * Adds max() method to long arrays.
- * <p/>
- * Example usage:
- * <pre class="groovyTestCase">
- * long[] nums = [1L, 3L, 2L]
- * assert 3L == nums.max()
- * </pre>
- *
- * @param self a long array
- * @return the maximum value
- * @since 3.0.8
- */
- public static long max(long[] self) {
- Objects.requireNonNull(self);
- throwUnsupportedOperationIfEmpty(self.length, "max");
- long answer = self[0];
- for (int i = 1; i < self.length; i++) {
- long value = self[i];
- if (value > answer) answer = value;
- }
- return answer;
- }
-
- /**
* Selects the maximum value found from the long array
* using the supplier LongBinaryOperator as a comparator to determine the maximum of any two values.
* <p>
@@ -3932,81 +4468,6 @@
}
/**
- * Selects the maximum value found from the long array
- * using the closure to determine the maximum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * long[] nums = [-30L, 10L, 20L]
- * assert 20L == nums.maxBy{ a, b {@code ->} a {@code <=>} b }
- * assert -30L == nums.maxBy{ it.abs() }
- * </pre>
- * <p>
- * If the closure has two parameters it is used like a traditional Comparator,
- * i.e., it should compare its two parameters for order, returning a negative integer,
- * zero, or a positive integer when the first parameter is less than,
- * equal to, or greater than the second respectively. Otherwise,
- * the Closure is assumed to take a single parameter and return a
- * Comparable (typically an Integer) which is then used for
- * further comparison.
- *
- * @param self a long array
- * @param closure a Closure used to determine the correct ordering
- * @return the maximum value
- * @see DefaultGroovyMethods#max(Iterator, groovy.lang.Closure)
- * @since 5.0.0
- */
- @Incubating
- public static long maxBy(long[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- return DefaultGroovyMethods.max(new LongArrayIterator(self), closure);
- }
-
- /**
- * Selects the maximum value found from the long array
- * using the comparator to determine the maximum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * long[] nums = [10L, 20L, 30L]
- * assert 30L == nums.maxComparing(Comparator.naturalOrder())
- * assert 10L == nums.maxComparing(Comparator.reverseOrder())
- * </pre>
- * <p>
- *
- * @param self a long array
- * @param comparator a Comparator
- * @return the maximum value
- * @see DefaultGroovyMethods#max(Iterator, java.util.Comparator)
- * @since 5.0.0
- */
- @Incubating
- public static long maxComparing(long[] self, Comparator<Long> comparator) {
- return DefaultGroovyMethods.max(new LongArrayIterator(self), comparator);
- }
-
- /**
- * Adds max() method to double arrays.
- * <p/>
- * Example usage:
- * <pre class="groovyTestCase">
- * double[] nums = [1.1d, 3.3d, 2.2d]
- * assert 3.3d == nums.max()
- * </pre>
- *
- * @param self a double array
- * @return the maximum value
- * @since 3.0.8
- */
- public static double max(double[] self) {
- Objects.requireNonNull(self);
- throwUnsupportedOperationIfEmpty(self.length, "max");
- double answer = self[0];
- for (int i = 1; i < self.length; i++) {
- double value = self[i];
- if (value > answer) answer = value;
- }
- return answer;
- }
-
- /**
* Selects the maximum value found from the double array
* using the supplier DoubleComparator to determine the maximum of any two values.
* <p>
@@ -4072,6 +4533,101 @@
}
/**
+ * Selects the maximum value found from the Object array using the given comparator.
+ *
+ * @param self an array
+ * @param comparator a Comparator
+ * @return the maximum value
+ * @see #max(Iterator, Comparator)
+ * @since 1.5.5
+ */
+ public static <T> T max(T[] self, Comparator<? super T> comparator) {
+ return DefaultGroovyMethods.max(new ArrayIterator<>(self), comparator);
+ }
+
+ /**
+ * Selects the maximum value found from the Object array
+ * using the closure to determine the correct ordering.
+ * <p>
+ * If the closure has two parameters
+ * it is used like a traditional Comparator. I.e. it should compare
+ * its two parameters for order, returning a negative integer,
+ * zero, or a positive integer when the first parameter is less than,
+ * equal to, or greater than the second respectively. Otherwise,
+ * the Closure is assumed to take a single parameter and return a
+ * Comparable (typically an Integer) which is then used for
+ * further comparison.
+ *
+ * @param self an array
+ * @param closure a Closure used to determine the correct ordering
+ * @return the maximum value
+ * @since 1.5.5
+ */
+ public static <T> T max(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure) {
+ return DefaultGroovyMethods.max(new ArrayIterator<>(self), closure);
+ }
+
+ //
+
+ /**
+ * Selects the maximum value found from the int array
+ * using the closure to determine the maximum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * int[] nums = [30, 45, 60, 90]
+ * assert 90 == nums.maxBy{ Math.sin(Math.toRadians(it)) }
+ * assert 30 == nums.maxBy{ Math.cos(Math.toRadians(it)) } // cos(90) == 0
+ * </pre>
+ * <p>
+ * If the closure has two parameters it is used like a traditional Comparator,
+ * i.e., it should compare its two parameters for order, returning a negative integer,
+ * zero, or a positive integer when the first parameter is less than,
+ * equal to, or greater than the second respectively. Otherwise,
+ * the Closure is assumed to take a single parameter and return a
+ * Comparable (typically an Integer) which is then used for
+ * further comparison.
+ *
+ * @param self an int array
+ * @param closure a Closure used to determine the correct ordering
+ * @return the maximum value
+ * @see DefaultGroovyMethods#max(Iterator, groovy.lang.Closure)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static int maxBy(int[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.max(new IntArrayIterator(self), closure);
+ }
+
+ /**
+ * Selects the maximum value found from the long array
+ * using the closure to determine the maximum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * long[] nums = [-30L, 10L, 20L]
+ * assert 20L == nums.maxBy{ a, b {@code ->} a {@code <=>} b }
+ * assert -30L == nums.maxBy{ it.abs() }
+ * </pre>
+ * <p>
+ * If the closure has two parameters it is used like a traditional Comparator,
+ * i.e., it should compare its two parameters for order, returning a negative integer,
+ * zero, or a positive integer when the first parameter is less than,
+ * equal to, or greater than the second respectively. Otherwise,
+ * the Closure is assumed to take a single parameter and return a
+ * Comparable (typically an Integer) which is then used for
+ * further comparison.
+ *
+ * @param self a long array
+ * @param closure a Closure used to determine the correct ordering
+ * @return the maximum value
+ * @see DefaultGroovyMethods#max(Iterator, groovy.lang.Closure)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static long maxBy(long[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.max(new LongArrayIterator(self), closure);
+ }
+
+ /**
* Selects the maximum value found from the double array
* using the closure to determine the maximum of any two values.
* <p>
@@ -4100,6 +4656,52 @@
return DefaultGroovyMethods.max(new DoubleArrayIterator(self), closure);
}
+ //
+
+ /**
+ * Selects the maximum value found from the int array
+ * using the comparator to determine the maximum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * int[] nums = [10, 20, 30]
+ * assert 30 == nums.maxComparing(Comparator.naturalOrder())
+ * assert 10 == nums.maxComparing(Comparator.reverseOrder())
+ * </pre>
+ * <p>
+ *
+ * @param self an int array
+ * @param comparator a Comparator
+ * @return the maximum value
+ * @see DefaultGroovyMethods#max(Iterator, java.util.Comparator)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static int maxComparing(int[] self, Comparator<Integer> comparator) {
+ return DefaultGroovyMethods.max(new IntArrayIterator(self), comparator);
+ }
+
+ /**
+ * Selects the maximum value found from the long array
+ * using the comparator to determine the maximum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * long[] nums = [10L, 20L, 30L]
+ * assert 30L == nums.maxComparing(Comparator.naturalOrder())
+ * assert 10L == nums.maxComparing(Comparator.reverseOrder())
+ * </pre>
+ * <p>
+ *
+ * @param self a long array
+ * @param comparator a Comparator
+ * @return the maximum value
+ * @see DefaultGroovyMethods#max(Iterator, java.util.Comparator)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static long maxComparing(long[] self, Comparator<Long> comparator) {
+ return DefaultGroovyMethods.max(new LongArrayIterator(self), comparator);
+ }
+
/**
* Selects the maximum value found from the double array
* using the comparator to determine the maximum of any two values.
@@ -4122,7 +4724,7 @@
return DefaultGroovyMethods.max(new DoubleArrayIterator(self), comparator);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// min
/**
@@ -4150,6 +4752,68 @@
}
/**
+ * Adds min() method to long arrays.
+ * <p/>
+ * Example usage:
+ * <pre class="groovyTestCase">
+ * long[] nums = [20L, 10L, 30L]
+ * assert 10L == nums.min()
+ * </pre>
+ *
+ * @param self a long array
+ * @return the minimum value
+ * @since 3.0.8
+ */
+ public static long min(long[] self) {
+ Objects.requireNonNull(self);
+ throwUnsupportedOperationIfEmpty(self.length, "max");
+ long answer = self[0];
+ for (int i = 1; i < self.length; i++) {
+ long value = self[i];
+ if (value < answer) answer = value;
+ }
+ return answer;
+ }
+
+ /**
+ * Adds min() method to double arrays.
+ * <p/>
+ * Example usage:
+ * <pre class="groovyTestCase">
+ * double[] nums = [20.0d, 10.0d, 30.0d]
+ * assert 10.0d == nums.min()
+ * </pre>
+ *
+ * @param self a double array
+ * @return the minimum value
+ * @since 3.0.8
+ */
+ public static double min(double[] self) {
+ Objects.requireNonNull(self);
+ throwUnsupportedOperationIfEmpty(self.length, "max");
+ double answer = self[0];
+ for (int i = 1; i < self.length; i++) {
+ double value = self[i];
+ if (value < answer) answer = value;
+ }
+ return answer;
+ }
+
+ /**
+ * Adds min() method to Object arrays.
+ *
+ * @param self an array
+ * @return the minimum value
+ * @see #min(Iterator)
+ * @since 1.5.5
+ */
+ public static <T> T min(T[] self) {
+ return DefaultGroovyMethods.min(new ArrayIterator<>(self));
+ }
+
+ //
+
+ /**
* Selects the minimum value found from the int array
* using the supplier IntComparator to determine the minimum of any two values.
* <p>
@@ -4215,81 +4879,6 @@
}
/**
- * Selects the minimum value found from the int array
- * using the closure to determine the minimum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * int[] nums = [-20, 10, 30]
- * assert -20 == nums.minBy{ a, b {@code ->} a {@code <=>} b }
- * assert 10 == nums.minBy{ it.abs() }
- * </pre>
- * <p>
- * If the closure has two parameters it is used like a traditional Comparator,
- * i.e., it should compare its two parameters for order, returning a negative integer,
- * zero, or a positive integer when the first parameter is less than,
- * equal to, or greater than the second respectively. Otherwise,
- * the Closure is assumed to take a single parameter and return a
- * Comparable (typically an Integer) which is then used for
- * further comparison.
- *
- * @param self an int array
- * @param closure a Closure used to determine the correct ordering
- * @return the minimum value
- * @see DefaultGroovyMethods#min(Iterator, groovy.lang.Closure)
- * @since 5.0.0
- */
- @Incubating
- public static int minBy(int[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- return DefaultGroovyMethods.min(new IntArrayIterator(self), closure);
- }
-
- /**
- * Selects the minimum value found from the int array
- * using the comparator to determine the minimum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * int[] nums = [1, 2, 3]
- * assert 1 == nums.minComparing(Comparator.naturalOrder())
- * assert 3 == nums.minComparing(Comparator.reverseOrder())
- * </pre>
- * <p>
- *
- * @param self an int array
- * @param comparator a Comparator
- * @return the minimum value
- * @see DefaultGroovyMethods#min(Iterator, java.util.Comparator)
- * @since 5.0.0
- */
- @Incubating
- public static int minComparing(int[] self, Comparator<Integer> comparator) {
- return DefaultGroovyMethods.min(new IntArrayIterator(self), comparator);
- }
-
- /**
- * Adds min() method to long arrays.
- * <p/>
- * Example usage:
- * <pre class="groovyTestCase">
- * long[] nums = [20L, 10L, 30L]
- * assert 10L == nums.min()
- * </pre>
- *
- * @param self a long array
- * @return the minimum value
- * @since 3.0.8
- */
- public static long min(long[] self) {
- Objects.requireNonNull(self);
- throwUnsupportedOperationIfEmpty(self.length, "max");
- long answer = self[0];
- for (int i = 1; i < self.length; i++) {
- long value = self[i];
- if (value < answer) answer = value;
- }
- return answer;
- }
-
- /**
* Selects the minimum value found from the long array
* using the supplier LongBinaryOperator as a comparator to determine the minimum of any two values.
* <p>
@@ -4355,81 +4944,6 @@
}
/**
- * Selects the minimum value found from the long array
- * using the closure to determine the minimum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * long[] nums = [-20L, 10L, 30L]
- * assert -20L == nums.minBy{ a, b {@code ->} a {@code <=>} b }
- * assert 10L == nums.minBy{ it.abs() }
- * </pre>
- * <p>
- * If the closure has two parameters it is used like a traditional Comparator,
- * i.e., it should compare its two parameters for order, returning a negative integer,
- * zero, or a positive integer when the first parameter is less than,
- * equal to, or greater than the second respectively. Otherwise,
- * the Closure is assumed to take a single parameter and return a
- * Comparable (typically an int or long) which is then used for
- * further comparison.
- *
- * @param self a long array
- * @param closure a Closure used to determine the correct ordering
- * @return the minimum value
- * @see DefaultGroovyMethods#min(Iterator, groovy.lang.Closure)
- * @since 5.0.0
- */
- @Incubating
- public static long minBy(long[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
- return DefaultGroovyMethods.min(new LongArrayIterator(self), closure);
- }
-
- /**
- * Selects the minimum value found from the long array
- * using the comparator to determine the minimum of any two values.
- * <p>
- * <pre class="groovyTestCase">
- * long[] nums = [10L, 20L, 30L]
- * assert 10L == nums.minComparing(Comparator.naturalOrder())
- * assert 30L == nums.minComparing(Comparator.reverseOrder())
- * </pre>
- * <p>
- *
- * @param self a long array
- * @param comparator a Comparator
- * @return the minimum value
- * @see DefaultGroovyMethods#min(Iterator, java.util.Comparator)
- * @since 5.0.0
- */
- @Incubating
- public static long minComparing(long[] self, Comparator<Long> comparator) {
- return DefaultGroovyMethods.min(new LongArrayIterator(self), comparator);
- }
-
- /**
- * Adds min() method to double arrays.
- * <p/>
- * Example usage:
- * <pre class="groovyTestCase">
- * double[] nums = [20.0d, 10.0d, 30.0d]
- * assert 10.0d == nums.min()
- * </pre>
- *
- * @param self a double array
- * @return the minimum value
- * @since 3.0.8
- */
- public static double min(double[] self) {
- Objects.requireNonNull(self);
- throwUnsupportedOperationIfEmpty(self.length, "max");
- double answer = self[0];
- for (int i = 1; i < self.length; i++) {
- double value = self[i];
- if (value < answer) answer = value;
- }
- return answer;
- }
-
- /**
* Selects the minimum value found from the double array
* using the supplier DoubleBinaryOperator as a comparator to determine the minimum of any two values.
* <p>
@@ -4495,6 +5009,102 @@
}
/**
+ * Selects the minimum value found from the Object array using the given comparator.
+ *
+ * @param self an array
+ * @param comparator a Comparator
+ * @return the minimum value
+ * @see #min(Iterator, java.util.Comparator)
+ * @since 1.5.5
+ */
+ public static <T> T min(T[] self, Comparator<? super T> comparator) {
+ return DefaultGroovyMethods.min(new ArrayIterator<>(self), comparator);
+ }
+
+ /**
+ * Selects the minimum value found from the Object array
+ * using the closure to determine the correct ordering.
+ * <p>
+ * If the closure has two parameters
+ * it is used like a traditional Comparator. I.e. it should compare
+ * its two parameters for order, returning a negative integer,
+ * zero, or a positive integer when the first parameter is less than,
+ * equal to, or greater than the second respectively. Otherwise,
+ * the Closure is assumed to take a single parameter and return a
+ * Comparable (typically an Integer) which is then used for
+ * further comparison.
+ *
+ * @param self an array
+ * @param closure a Closure used to determine the correct ordering
+ * @return the minimum value
+ * @see #min(Iterator, groovy.lang.Closure)
+ * @since 1.5.5
+ */
+ public static <T> T min(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure) {
+ return DefaultGroovyMethods.min(new ArrayIterator<>(self), closure);
+ }
+
+ //
+
+ /**
+ * Selects the minimum value found from the int array
+ * using the closure to determine the minimum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * int[] nums = [-20, 10, 30]
+ * assert -20 == nums.minBy{ a, b {@code ->} a {@code <=>} b }
+ * assert 10 == nums.minBy{ it.abs() }
+ * </pre>
+ * <p>
+ * If the closure has two parameters it is used like a traditional Comparator,
+ * i.e., it should compare its two parameters for order, returning a negative integer,
+ * zero, or a positive integer when the first parameter is less than,
+ * equal to, or greater than the second respectively. Otherwise,
+ * the Closure is assumed to take a single parameter and return a
+ * Comparable (typically an Integer) which is then used for
+ * further comparison.
+ *
+ * @param self an int array
+ * @param closure a Closure used to determine the correct ordering
+ * @return the minimum value
+ * @see DefaultGroovyMethods#min(Iterator, groovy.lang.Closure)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static int minBy(int[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.min(new IntArrayIterator(self), closure);
+ }
+
+ /**
+ * Selects the minimum value found from the long array
+ * using the closure to determine the minimum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * long[] nums = [-20L, 10L, 30L]
+ * assert -20L == nums.minBy{ a, b {@code ->} a {@code <=>} b }
+ * assert 10L == nums.minBy{ it.abs() }
+ * </pre>
+ * <p>
+ * If the closure has two parameters it is used like a traditional Comparator,
+ * i.e., it should compare its two parameters for order, returning a negative integer,
+ * zero, or a positive integer when the first parameter is less than,
+ * equal to, or greater than the second respectively. Otherwise,
+ * the Closure is assumed to take a single parameter and return a
+ * Comparable (typically an int or long) which is then used for
+ * further comparison.
+ *
+ * @param self a long array
+ * @param closure a Closure used to determine the correct ordering
+ * @return the minimum value
+ * @see DefaultGroovyMethods#min(Iterator, groovy.lang.Closure)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static long minBy(long[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.min(new LongArrayIterator(self), closure);
+ }
+
+ /**
* Selects the minimum value found from the double array
* using the closure to determine the minimum of any two values.
* <p>
@@ -4523,6 +5133,52 @@
return DefaultGroovyMethods.min(new DoubleArrayIterator(self), closure);
}
+ //
+
+ /**
+ * Selects the minimum value found from the int array
+ * using the comparator to determine the minimum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * int[] nums = [1, 2, 3]
+ * assert 1 == nums.minComparing(Comparator.naturalOrder())
+ * assert 3 == nums.minComparing(Comparator.reverseOrder())
+ * </pre>
+ * <p>
+ *
+ * @param self an int array
+ * @param comparator a Comparator
+ * @return the minimum value
+ * @see DefaultGroovyMethods#min(Iterator, java.util.Comparator)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static int minComparing(int[] self, Comparator<Integer> comparator) {
+ return DefaultGroovyMethods.min(new IntArrayIterator(self), comparator);
+ }
+
+ /**
+ * Selects the minimum value found from the long array
+ * using the comparator to determine the minimum of any two values.
+ * <p>
+ * <pre class="groovyTestCase">
+ * long[] nums = [10L, 20L, 30L]
+ * assert 10L == nums.minComparing(Comparator.naturalOrder())
+ * assert 30L == nums.minComparing(Comparator.reverseOrder())
+ * </pre>
+ * <p>
+ *
+ * @param self a long array
+ * @param comparator a Comparator
+ * @return the minimum value
+ * @see DefaultGroovyMethods#min(Iterator, java.util.Comparator)
+ * @since 5.0.0
+ */
+ @Incubating
+ public static long minComparing(long[] self, Comparator<Long> comparator) {
+ return DefaultGroovyMethods.min(new LongArrayIterator(self), comparator);
+ }
+
/**
* Selects the minimum value found from the double array
* using the comparator to determine the minimum of any two values.
@@ -4545,11 +5201,13 @@
return DefaultGroovyMethods.min(new DoubleArrayIterator(self), comparator);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// minus
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// plus
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// reverse
/**
@@ -4904,7 +5562,7 @@
return self;
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// reverseEach
/**
@@ -5083,11 +5741,29 @@
return self;
}
- //-------------------------------------------------------------------------
+ /**
+ * Iterate over each element of the array in the reverse order.
+ *
+ * @param self an array
+ * @param closure a closure to which each item is passed
+ * @return the original array
+ * @since 1.5.2
+ */
+ public static <T> T[] reverseEach(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ Objects.requireNonNull(self);
+ for (int i = self.length - 1; i >= 0; i--) {
+ closure.call(self[i]);
+ }
+ return self;
+ }
+
+ //--------------------------------------------------------------------------
// shuffle
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// shuffled
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// size
/**
@@ -5097,104 +5773,109 @@
* assert array.size() == 3
* </pre>
*
- * @param array a boolean array
+ * @param self a boolean array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.5.0
*/
- public static int size(boolean[] array) {
- return Array.getLength(array);
+ public static int size(boolean[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array a byte array
+ * @param self a byte array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(byte[] array) {
- return Array.getLength(array);
+ public static int size(byte[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array a char array
+ * @param self a char array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(char[] array) {
- return Array.getLength(array);
+ public static int size(char[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array a short array
+ * @param self a short array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(short[] array) {
- return Array.getLength(array);
+ public static int size(short[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array an int array
+ * @param self an int array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(int[] array) {
- return Array.getLength(array);
+ public static int size(int[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array a long array
+ * @param self a long array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(long[] array) {
- return Array.getLength(array);
+ public static int size(long[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array a float array
+ * @param self a float array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(float[] array) {
- return Array.getLength(array);
+ public static int size(float[] self) {
+ return self.length;
}
/**
* Provide arrays with a {@code size} method similar to collections.
*
- * @param array a double array
+ * @param self a double array
* @return the length of the array
- * @see java.lang.reflect.Array#getLength(java.lang.Object)
* @since 1.0
*/
- public static int size(double[] array) {
- return Array.getLength(array);
+ public static int size(double[] self) {
+ return self.length;
}
- //-------------------------------------------------------------------------
+ /**
+ * Provide the standard Groovy <code>size()</code> method for an array.
+ *
+ * @param self an object array
+ * @return the length of the array
+ * @since 1.0
+ */
+ public static int size(Object[] self) {
+ return self.length;
+ }
+
+ //--------------------------------------------------------------------------
// sort
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// split
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// sum
/**
@@ -5282,6 +5963,19 @@
}
/**
+ * Sums the items in an array. This is equivalent to invoking the
+ * "plus" method on all items in the array.
+ *
+ * @param self The array of values to add together
+ * @return The sum of all the items
+ * @see #sum(java.util.Iterator)
+ * @since 1.7.1
+ */
+ public static Object sum(Object[] self) {
+ return DefaultGroovyMethods.sum(new ArrayIterator<>(self), null, true);
+ }
+
+ /**
* Sums the items in an array, adding the result to some initial value.
* <pre class="groovyTestCase">assert (5+1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum(5 as byte)</pre>
*
@@ -5407,8 +6101,50 @@
return s;
}
+ /**
+ * Sums the items in an array, adding the result to some initial value.
+ *
+ * @param self an array of values to sum
+ * @param initialValue the items in the array will be summed to this initial value
+ * @return The sum of all the items.
+ * @since 1.7.1
+ */
+ public static Object sum(Object[] self, Object initialValue) {
+ return DefaultGroovyMethods.sum(new ArrayIterator<>(self), initialValue, false);
+ }
- //-------------------------------------------------------------------------
+ /**
+ * Sums the result of applying a closure to each item of an array.
+ * <code>array.sum(closure)</code> is equivalent to:
+ * <code>array.collect(closure).sum()</code>.
+ *
+ * @param self An array
+ * @param closure a single parameter closure that returns a (typically) numeric value.
+ * @return The sum of the values returned by applying the closure to each
+ * item of the array.
+ * @since 1.7.1
+ */
+ public static <T> Object sum(T[] self, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.sum(new ArrayIterator<>(self), null, closure, true);
+ }
+
+ /**
+ * Sums the result of applying a closure to each item of an array to some initial value.
+ * <code>array.sum(initVal, closure)</code> is equivalent to:
+ * <code>array.collect(closure).sum(initVal)</code>.
+ *
+ * @param self an array
+ * @param closure a single parameter closure that returns a (typically) numeric value.
+ * @param initialValue the closure results will be summed to this initial value
+ * @return The sum of the values returned by applying the closure to each
+ * item of the array.
+ * @since 1.7.1
+ */
+ public static <T> Object sum(T[] self, Object initialValue, @ClosureParams(FirstParam.Component.class) Closure<?> closure) {
+ return DefaultGroovyMethods.sum(new ArrayIterator<>(self), initialValue, closure, false);
+ }
+
+ //--------------------------------------------------------------------------
// swap
/**
@@ -5587,7 +6323,28 @@
return self;
}
- //-------------------------------------------------------------------------
+ /**
+ * Swaps two elements at the specified positions.
+ * <p>
+ * Example:
+ * <pre class="groovyTestCase">
+ * assert (["a", "c", "b", "d"] as String[]) == (["a", "b", "c", "d"] as String[]).swap(1, 2)
+ * </pre>
+ *
+ * @param self an array
+ * @param i a position
+ * @param j a position
+ * @return self
+ * @since 2.4.0
+ */
+ public static <T> T[] swap(T[] self, int i, int j) {
+ T tmp = self[i];
+ self[i] = self[j];
+ self[j] = tmp;
+ return self;
+ }
+
+ //--------------------------------------------------------------------------
// tail
/**
@@ -5750,123 +6507,137 @@
return Arrays.copyOfRange(self, 1, self.length);
}
-
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// take
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// takeRight
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// takeWhile
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// toArrayString
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// toList
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a boolean array
- * @return a list containing the contents of this array.
+ * @param self a boolean array
+ * @return A list containing the contents of this array.
* @since 1.6.0
*/
@SuppressWarnings("unchecked")
- public static List<Boolean> toList(boolean[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Boolean> toList(boolean[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a byte array
- * @return a list containing the contents of this array.
+ * @param self a byte array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Byte> toList(byte[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Byte> toList(byte[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a char array
- * @return a list containing the contents of this array.
+ * @param self a char array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Character> toList(char[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Character> toList(char[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a short array
- * @return a list containing the contents of this array.
+ * @param self a short array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Short> toList(short[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Short> toList(short[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array an int array
- * @return a list containing the contents of this array.
+ * @param self an int array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Integer> toList(int[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Integer> toList(int[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a long array
- * @return a list containing the contents of this array.
+ * @param self a long array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Long> toList(long[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Long> toList(long[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a float array
- * @return a list containing the contents of this array.
+ * @param self a float array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Float> toList(float[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Float> toList(float[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
/**
* Converts this array to a List of the same size, with each element
* added to the list.
*
- * @param array a double array
- * @return a list containing the contents of this array.
+ * @param self a double array
+ * @return A list containing the contents of this array.
* @since 1.0
*/
@SuppressWarnings("unchecked")
- public static List<Double> toList(double[] array) {
- return DefaultTypeTransformation.primitiveArrayToList(array);
+ public static List<Double> toList(double[] self) {
+ return DefaultTypeTransformation.primitiveArrayToList(self);
}
- //-------------------------------------------------------------------------
+ /**
+ * Allows conversion of arrays into a mutable List.
+ *
+ * @param self an object array
+ * @return A list containing the contents of this array.
+ * @since 1.0
+ */
+ public static <T> List<T> toList(T[] self) {
+ return new ArrayList<>(Arrays.asList(self));
+ }
+
+ //--------------------------------------------------------------------------
// toSet
/**
@@ -5877,13 +6648,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a boolean array
- * @return a set containing the unique contents of this array.
+ * @param self a boolean array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Boolean> toSet(boolean[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Boolean> toSet(boolean[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5894,13 +6665,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a byte array
- * @return a set containing the unique contents of this array.
+ * @param self a byte array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Byte> toSet(byte[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Byte> toSet(byte[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5911,13 +6682,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a char array
- * @return a set containing the unique contents of this array.
+ * @param self a char array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Character> toSet(char[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Character> toSet(char[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5928,13 +6699,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a short array
- * @return a set containing the unique contents of this array.
+ * @param self a short array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Short> toSet(short[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Short> toSet(short[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5945,13 +6716,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array an int array
- * @return a set containing the unique contents of this array.
+ * @param self an int array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Integer> toSet(int[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Integer> toSet(int[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5962,13 +6733,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a long array
- * @return a set containing the unique contents of this array.
+ * @param self a long array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Long> toSet(long[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Long> toSet(long[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5979,13 +6750,13 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a float array
- * @return a set containing the unique contents of this array.
+ * @param self a float array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Float> toSet(float[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Float> toSet(float[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
/**
@@ -5996,18 +6767,30 @@
* assert array.toSet() == expected
* </pre>
*
- * @param array a double array
- * @return a set containing the unique contents of this array.
+ * @param self a double array
+ * @return A set containing the unique contents of this array.
* @since 1.8.0
*/
@SuppressWarnings("unchecked")
- public static Set<Double> toSet(double[] array) {
- return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(array));
+ public static Set<Double> toSet(double[] self) {
+ return DefaultGroovyMethods.toSet(DefaultTypeTransformation.primitiveArrayToUnmodifiableList(self));
}
- //-------------------------------------------------------------------------
+ /**
+ * Converts this array to a Set, with each unique element added to the set.
+ *
+ * @param self an object array
+ * @return A set containing the unique contents of this array.
+ * @since 5.0.0
+ */
+ public static <T> Set<T> toSet(T[] self) {
+ return DefaultGroovyMethods.toSet(Arrays.asList(self));
+ }
+
+ //--------------------------------------------------------------------------
// toSorted
- //-------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------
// toString
/**
@@ -6132,9 +6915,74 @@
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// toUnique
- //-------------------------------------------------------------------------
+
+ /**
+ * Returns a new Array containing the items from the original Array but with duplicates removed using the
+ * natural ordering of the items in the array.
+ * <p>
+ * <pre class="groovyTestCase">
+ * String[] letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't']
+ * String[] expected = ['c', 'a', 't', 's', 'h']
+ * def result = letters.toUnique()
+ * assert result == expected
+ * assert result.class.componentType == String
+ * </pre>
+ *
+ * @param self an array
+ * @return the unique items from the array
+ */
+ public static <T> T[] toUnique(T[] self) {
+ return toUnique(self, (Comparator<T>) null);
+ }
+
+ /**
+ * Returns a new Array containing the items from the original Array but with duplicates removed with the supplied
+ * comparator determining which items are unique.
+ * <p>
+ * <pre class="groovyTestCase">
+ * String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T']
+ * String[] lower = ['c', 'a', 't', 's', 'h']
+ * class LowerComparator implements Comparator {
+ * int compare(a, b) { a.toLowerCase() {@code <=>} b.toLowerCase() }
+ * }
+ * assert letters.toUnique(new LowerComparator()) == lower
+ * </pre>
+ *
+ * @param self an array
+ * @param comparator a Comparator used to determine unique (equal) items
+ * If {@code null}, the Comparable natural ordering of the elements will be used.
+ * @return the unique items from the array
+ */
+ public static <T> T[] toUnique(T[] self, Comparator<? super T> comparator) {
+ Collection<T> items = DefaultGroovyMethods.toUnique(new ArrayIterable<>(self), comparator);
+ return items.toArray(createSimilarArray(self, items.size()));
+ }
+
+ /**
+ * Returns a new Array containing the items from the original Array but with duplicates removed with the supplied
+ * closure determining which items are unique.
+ * <p>
+ * <pre class="groovyTestCase">
+ * String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T']
+ * String[] expected = ['c', 'a', 't', 's', 'h']
+ * assert letters.toUnique{ p1, p2 {@code ->} p1.toLowerCase() {@code <=>} p2.toLowerCase() } == expected
+ * assert letters.toUnique{ it.toLowerCase() } == expected
+ * </pre>
+ *
+ * @param self an array
+ * @param closure a Closure used to determine unique items
+ * @return the unique items from the array
+ */
+ public static <T> T[] toUnique(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure) {
+ Comparator<T> comparator = closure.getMaximumNumberOfParameters() == 1
+ ? new OrderBy<>(closure, true)
+ : new ClosureComparator<>(closure);
+ return toUnique(self, comparator);
+ }
+
+ //--------------------------------------------------------------------------
// transpose
/**
@@ -6351,16 +7199,18 @@
return result;
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// union
- private static void throwNoSuchElementIfEmpty(int size, String method) {
+ //--------------------------------------------------------------------------
+
+ private static void throwNoSuchElementIfEmpty(final int size, final String method) {
if (size == 0) {
throw new NoSuchElementException("Cannot access " + method + "() for an empty array");
}
}
- private static void throwUnsupportedOperationIfEmpty(int size, String method) {
+ private static void throwUnsupportedOperationIfEmpty(final int size, final String method) {
if (size == 0) {
throw new UnsupportedOperationException("Accessing " + method + "() is unsupported for an empty array");
}
@@ -6370,12 +7220,12 @@
* Implements the getAt(int) method for primitive type arrays.
*
* @param self an array object
- * @param idx the index of interest
+ * @param index the index of interest
* @return the returned value from the array
* @since 1.5.0
*/
- private static Object primitiveArrayGet(Object self, int idx) {
- return Array.get(self, normaliseIndex(idx, Array.getLength(self)));
+ private static Object primitiveArrayGet(final Object self, final int index) {
+ return Array.get(self, normaliseIndex(index, Array.getLength(self)));
}
/**
@@ -6386,9 +7236,9 @@
* @return the returned values from the array corresponding to the range
* @since 1.5.0
*/
- @SuppressWarnings("unchecked")
- private static List primitiveArrayGet(Object self, Range range) {
- List answer = new ArrayList();
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static List primitiveArrayGet(final Object self, final Range range) {
+ List answer = new ArrayList<>();
for (Object next : range) {
int idx = DefaultTypeTransformation.intUnbox(next);
answer.add(primitiveArrayGet(self, idx));
@@ -6406,9 +7256,9 @@
* @return the returned values from the array
* @since 1.0
*/
- @SuppressWarnings("unchecked")
- private static List primitiveArrayGet(Object self, Collection indices) {
- List answer = new ArrayList();
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static List primitiveArrayGet(final Object self, final Collection indices) {
+ List answer = new ArrayList<>();
for (Object value : indices) {
if (value instanceof Range) {
answer.addAll(primitiveArrayGet(self, (Range) value));
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 4080a2d..82dc020 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -98,11 +98,8 @@
import org.codehaus.groovy.transform.trait.Traits;
import org.codehaus.groovy.util.ArrayIterable;
import org.codehaus.groovy.util.ArrayIterator;
-import org.codehaus.groovy.util.DoubleArrayIterable;
-import org.codehaus.groovy.util.IntArrayIterable;
import org.codehaus.groovy.util.IteratorBufferedIterator;
import org.codehaus.groovy.util.ListBufferedIterator;
-import org.codehaus.groovy.util.LongArrayIterable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -175,12 +172,6 @@
*/
public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
- private static final Integer ONE = 1;
- private static final BigInteger BI_INT_MAX = BigInteger.valueOf(Integer.MAX_VALUE);
- private static final BigInteger BI_INT_MIN = BigInteger.valueOf(Integer.MIN_VALUE);
- private static final BigInteger BI_LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
- private static final BigInteger BI_LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE);
-
public static final Class[] ADDITIONAL_CLASSES = {
NumberNumberPlus.class,
NumberNumberMultiply.class,
@@ -205,7 +196,7 @@
DoubleArrayGetAtMetaMethod.class,
DoubleArrayPutAtMetaMethod.class,
};
- public static final Class[] DGM_LIKE_CLASSES = new Class[]{
+ public static final Class[] DGM_LIKE_CLASSES = {
ArrayGroovyMethods.class,
DefaultGroovyMethods.class,
EncodingGroovyMethods.class,
@@ -225,7 +216,11 @@
XmlExtensions.class,
*/
};
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+
+ private static final BigInteger BI_INT_MAX = BigInteger.valueOf(Integer.MAX_VALUE);
+ private static final BigInteger BI_INT_MIN = BigInteger.valueOf(Integer.MIN_VALUE);
+ private static final BigInteger BI_LONG_MAX = BigInteger.valueOf( Long.MAX_VALUE);
+ private static final BigInteger BI_LONG_MIN = BigInteger.valueOf( Long.MIN_VALUE);
private static final NumberAwareComparator<Comparable> COMPARABLE_NUMBER_AWARE_COMPARATOR = new NumberAwareComparator<>();
/**
@@ -816,7 +811,7 @@
*/
public static void println(Closure self) {
Object owner = getClosureOwner(self);
- InvokerHelper.invokeMethod(owner, "println", EMPTY_OBJECT_ARRAY);
+ InvokerHelper.invokeMethod(owner, "println", InvokerHelper.EMPTY_ARGS);
}
/**
@@ -2134,91 +2129,6 @@
}
/**
- * Returns a new Array containing the items from the original Array but with duplicates removed with the supplied
- * comparator determining which items are unique.
- * <p>
- * <pre class="groovyTestCase">
- * String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T']
- * String[] lower = ['c', 'a', 't', 's', 'h']
- * class LowerComparator implements Comparator {
- * int compare(let1, let2) { let1.toLowerCase() {@code <=>} let2.toLowerCase() }
- * }
- * assert letters.toUnique(new LowerComparator()) == lower
- * </pre>
- *
- * @param self an array
- * @param comparator a Comparator used to determine unique (equal) items
- * If {@code null}, the Comparable natural ordering of the elements will be used.
- * @return the unique items from the array
- */
- public static <T> T[] toUnique(T[] self, Comparator<? super T> comparator) {
- Collection<T> items = toUnique(new ArrayIterable<>(self), comparator);
- return items.toArray(createSimilarArray(self, items.size()));
- }
-
- /**
- * Returns a new Array containing the items from the original Array but with duplicates removed using the
- * natural ordering of the items in the array.
- * <p>
- * <pre class="groovyTestCase">
- * String[] letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't']
- * String[] expected = ['c', 'a', 't', 's', 'h']
- * def result = letters.toUnique()
- * assert result == expected
- * assert result.class.componentType == String
- * </pre>
- *
- * @param self an array
- * @return the unique items from the array
- */
- public static <T> T[] toUnique(T[] self) {
- return toUnique(self, (Comparator<T>) null);
- }
-
- /**
- * Returns a new Array containing the items from the original Array but with duplicates removed with the supplied
- * comparator determining which items are unique.
- * <p>
- * <pre class="groovyTestCase">
- * String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T']
- * String[] expected = ['c', 'a', 't', 's', 'h']
- * assert letters.toUnique{ p1, p2 {@code ->} p1.toLowerCase() {@code <=>} p2.toLowerCase() } == expected
- * assert letters.toUnique{ it.toLowerCase() } == expected
- * </pre>
- *
- * @param self an array
- * @param condition a Closure used to determine unique items
- * @return the unique items from the array
- */
- public static <T> T[] toUnique(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure condition) {
- Comparator<T> comparator = condition.getMaximumNumberOfParameters() == 1
- ? new OrderBy<>(condition, true)
- : new ClosureComparator<>(condition);
- return toUnique(self, comparator);
- }
-
- /**
- * Iterates through an array passing each array entry to the given closure.
- * <pre class="groovyTestCase">
- * String[] letters = ['a', 'b', 'c']
- * String result = ''
- * letters.each{ result += it }
- * assert result == 'abc'
- * </pre>
- *
- * @param self the array over which we iterate
- * @param closure the closure applied on each array entry
- * @return the self array
- * @since 2.5.0
- */
- public static <T> T[] each(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- for(T item : self){
- closure.call(item);
- }
- return self;
- }
-
- /**
* Iterates through an aggregate type or data structure,
* passing each item to the given closure. Custom types may utilize this
* method by simply providing an "iterator()" method. The items returned
@@ -2240,33 +2150,6 @@
}
/**
- * Iterates through an array,
- * passing each array element and the element's index (a counter starting at
- * zero) to the given closure.
- * <pre class="groovyTestCase">
- * String[] letters = ['a', 'b', 'c']
- * String result = ''
- * letters.eachWithIndex{ letter, index {@code ->} result += "$index:$letter" }
- * assert result == '0:a1:b2:c'
- * </pre>
- *
- * @param self an array
- * @param closure a Closure to operate on each array entry
- * @return the self array
- * @since 2.5.0
- */
- public static <T> T[] eachWithIndex(T[] self, @ClosureParams(value=FromString.class, options="T,Integer") Closure closure) {
- final Object[] args = new Object[2];
- int counter = 0;
- for(T item : self) {
- args[0] = item;
- args[1] = counter++;
- closure.call(args);
- }
- return self;
- }
-
- /**
* Iterates through an aggregate type or data structure,
* passing each item and the item's index (a counter starting at
* zero) to the given closure.
@@ -2555,22 +2438,6 @@
}
/**
- * Iterate over each element of the array in the reverse order.
- *
- * @param self an array
- * @param closure a closure to which each item is passed
- * @return the original array
- * @since 1.5.2
- */
- public static <T> T[] reverseEach(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- Objects.requireNonNull(self);
- for (int i = self.length - 1; i >= 0; i--) {
- closure.call(self[i]);
- }
- return self;
- }
-
- /**
* Iterate over each element of the set in reverse order.
* <pre class="groovyTestCase">
* TreeSet navSet = [2, 4, 1, 3] // natural order is sorted
@@ -2631,19 +2498,6 @@
/**
* Used to determine if the given predicate closure is valid (i.e. returns
- * <code>true</code> for all items in this Array).
- *
- * @param self an Array
- * @param predicate the closure predicate used for matching
- * @return true if every element of the Array matches the closure predicate
- * @since 2.5.0
- */
- public static <T> boolean every(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
- return every(new ArrayIterator<>(self), predicate);
- }
-
- /**
- * Used to determine if the given predicate closure is valid (i.e. returns
* <code>true</code> for all items in this iterable).
* A simple example for a list:
* <pre>def list = [3,4,5]
@@ -2764,19 +2618,6 @@
}
/**
- * Iterates over the contents of an Array, and checks whether a
- * predicate is valid for at least one element.
- *
- * @param self the array over which we iterate
- * @param predicate the closure predicate used for matching
- * @return true if any iteration for the object matches the closure predicate
- * @since 2.5.0
- */
- public static <T> boolean any(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
- return any(new ArrayIterator<>(self), predicate);
- }
-
- /**
* Iterates over the entries of a map, and checks whether a predicate is
* valid for at least one entry. If the
* closure takes one parameter then it will be passed the Map.Entry
@@ -2935,36 +2776,6 @@
}
/**
- * Iterates over the array of items and returns a collection of items that match
- * the given filter - calling the <code>{@link #isCase(java.lang.Object, java.lang.Object)}</code>
- * method used by switch statements. This method can be used with different
- * kinds of filters like regular expressions, classes, ranges etc.
- * Example:
- * <pre class="groovyTestCase">
- * def items = ['a', 'b', 'aa', 'bc', 3, 4.5] as Object[]
- * assert items.grep( ~/a+/ ) == ['a', 'aa']
- * assert items.grep( ~/../ ) == ['aa', 'bc']
- * assert items.grep( Number ) == [ 3, 4.5 ]
- * assert items.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
- * </pre>
- *
- * @param self an array
- * @param filter the filter to perform on each element of the array (using the {@link #isCase(java.lang.Object, java.lang.Object)} method)
- * @return a collection of objects which match the filter
- * @since 2.0
- */
- public static <T> Collection<T> grep(T[] self, Object filter) {
- Collection<T> answer = new ArrayList<>();
- BooleanReturningMethodInvoker bmi = new BooleanReturningMethodInvoker("isCase");
- for (T element : self) {
- if (bmi.invoke(filter, element)) {
- answer.add(element);
- }
- }
- return answer;
- }
-
- /**
* Iterates over the collection of items which this Object represents and returns each item that matches
* using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.
* <p>
@@ -3041,25 +2852,6 @@
}
/**
- * Iterates over the array returning each element that matches
- * using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.
- * <p>
- * Example:
- * <pre class="groovyTestCase">
- * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[]
- * assert items.grep() == [1, 2, true, 'foo', [4, 5]]
- * </pre>
- *
- * @param self an array
- * @return a collection of elements which satisfy Groovy truth
- * @see Closure#IDENTITY
- * @since 2.0
- */
- public static <T> Collection<T> grep(T[] self) {
- return grep(self, Closure.IDENTITY);
- }
-
- /**
* Counts the number of occurrences of the given value from the
* items within this Iterator.
* Comparison is done using Groovy's == operator (using
@@ -3169,72 +2961,6 @@
}
/**
- * Counts the number of occurrences of the given value inside this array.
- * Comparison is done using Groovy's == operator (using
- * <code>compareTo(value) == 0</code> or <code>equals(value)</code> ).
- *
- * @param self the array within which we count the number of occurrences
- * @param value the value being searched for
- * @return the number of occurrences
- * @since 1.6.4
- */
- public static Number count(Object[] self, Object value) {
- return count(Arrays.asList(self), value);
- }
-
- /**
- * Counts the number of occurrences which satisfy the given closure from inside this array.
- *
- * @param self the array within which we count the number of occurrences
- * @param closure a closure condition
- * @return the number of occurrences
- * @since 1.8.0
- */
- public static <T> Number count(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- return count(Arrays.asList(self), closure);
- }
-
- @Deprecated
- public static Number count(int[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(long[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(short[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(char[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(boolean[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(double[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(float[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- @Deprecated
- public static Number count(byte[] self, Object value) {
- return ArrayGroovyMethods.count(self, value);
- }
-
- /**
* Convert an iterator to a List. The iterator will become
* exhausted of elements after making this conversion.
*
@@ -3778,11 +3504,6 @@
return collectMany(self, new ArrayList<>(), projection);
}
- @Deprecated
- public static <T, K, V> Collection<T> collectMany$$bridge(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<? extends Collection<? extends T>> projection) {
- return collectMany(self, projection);
- }
-
/**
* Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.
* <p>
@@ -5280,11 +5001,6 @@
return findMany(new ArrayList<>(), new ArrayIterator<>(self), condition);
}
- @Deprecated
- public static <T> Collection<T> findAll$$bridge(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
- return findAll(self, condition);
- }
-
/**
* Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).
* <p>
@@ -5357,11 +5073,6 @@
return findAll(self, Closure.IDENTITY);
}
- @Deprecated
- public static <T> Collection<T> findAll$$bridge(T[] self) {
- return findAll(self);
- }
-
/**
* Finds all items matching the closure condition.
*
@@ -5375,11 +5086,6 @@
return findMany(new ArrayList(), InvokerHelper.asIterator(self), closure);
}
- @Deprecated
- public static Collection findAll$$bridge(Object self, Closure closure) {
- return findAll(self, closure);
- }
-
/**
* Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth).
* <p>
@@ -5398,11 +5104,6 @@
return findAll(self, Closure.IDENTITY);
}
- @Deprecated
- public static Collection findAll$$bridge(Object self) {
- return findAll(self);
- }
-
private static <T, C extends Collection<T>> C findMany(C collector, Iterator<? extends T> iter, Closure<?> closure) {
BooleanClosureWrapper test = new BooleanClosureWrapper(closure);
while (iter.hasNext()) {
@@ -5892,22 +5593,6 @@
return GroovyCollections.transpose(self);
}
-
- @Deprecated
- public static int[][] transpose(int[][] self) {
- return ArrayGroovyMethods.transpose(self);
- }
-
- @Deprecated
- public static long[][] transpose(long[][] self) {
- return ArrayGroovyMethods.transpose(self);
- }
-
- @Deprecated
- public static double[][] transpose(double[][] self) {
- return ArrayGroovyMethods.transpose(self);
- }
-
/**
* Sorts all Iterable members into groups determined by the supplied mapping closure.
* The closure should return the key that this item should be grouped by. The returned
@@ -6093,26 +5778,6 @@
}
/**
- * Sorts all array members into groups determined by the supplied mapping
- * closure and counts the group size. The closure should return the key that each
- * item should be grouped by. The returned Map will have an entry for each
- * distinct key returned from the closure, with each value being the frequency of
- * items occurring for that group.
- * <p>
- * Example usage:
- * <pre class="groovyTestCase">assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]</pre>
- *
- * @param self an array to group and count
- * @param closure a closure mapping items to the frequency keys
- * @return a new Map grouped by keys with frequency counts
- * @see #countBy(Iterator, Closure)
- * @since 1.8.0
- */
- public static <K,E> Map<K, Integer> countBy(E[] self, @ClosureParams(FirstParam.Component.class) Closure<K> closure) {
- return countBy(new ArrayIterator<>(self), closure);
- }
-
- /**
* Sorts all iterator items into groups determined by the supplied mapping
* closure and counts the group size. The closure should return the key that each
* item should be grouped by. The returned Map will have an entry for each
@@ -6526,47 +6191,6 @@
}
/**
- * Iterates through the given array as with inject(Object[],initialValue,closure), but
- * using the first element of the array as the initialValue, and then iterating
- * the remaining elements of the array.
- *
- * @param self an Object[]
- * @param closure a closure
- * @return the result of the last closure call
- * @throws NoSuchElementException if the array is empty.
- * @see #inject(Object[], Object, Closure)
- * @since 1.8.7
- */
- public static <E,T, V extends T> T inject(E[] self, @ClosureParams(value=FromString.class,options="E,E") Closure<V> closure) {
- return inject( (Object)self, closure ) ;
- }
-
- /**
- * Iterates through the given array, passing in the initial value to
- * the closure along with the first item. The result is passed back (injected) into
- * the closure along with the second item. The new result is injected back into
- * the closure along with the third item and so on until all elements of the array
- * have been used. Also known as foldLeft in functional parlance.
- *
- * @param self an Object[]
- * @param initialValue some initial value
- * @param closure a closure
- * @return the result of the last closure call
- * @see #inject(Collection, Object, Closure)
- * @since 1.5.0
- */
- public static <E, T, U extends T, V extends T> T inject(E[] self, U initialValue, @ClosureParams(value=FromString.class,options="U,E") Closure<V> closure) {
- Object[] params = new Object[2];
- T value = initialValue;
- for (Object next : self) {
- params[0] = value;
- params[1] = next;
- value = closure.call(params);
- }
- return value;
- }
-
- /**
* Sums the items in an Iterable. This is equivalent to invoking the
* "plus" method on all items in the Iterable.
* <pre class="groovyTestCase">assert 1+2+3+4 == [1,2,3,4].sum()</pre>
@@ -6581,19 +6205,6 @@
}
/**
- * Sums the items in an array. This is equivalent to invoking the
- * "plus" method on all items in the array.
- *
- * @param self The array of values to add together
- * @return The sum of all the items
- * @see #sum(java.util.Iterator)
- * @since 1.7.1
- */
- public static Object sum(Object[] self) {
- return sum(new ArrayIterator<>(self), null, true);
- }
-
- /**
* Sums the items from an Iterator. This is equivalent to invoking the
* "plus" method on all items from the Iterator. The iterator will become
* exhausted of elements after determining the sum value.
@@ -6606,41 +6217,6 @@
return sum(self, null, true);
}
- @Deprecated
- public static byte sum(byte[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
- @Deprecated
- public static short sum(short[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
- @Deprecated
- public static int sum(int[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
- @Deprecated
- public static long sum(long[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
- @Deprecated
- public static char sum(char[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
- @Deprecated
- public static float sum(float[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
- @Deprecated
- public static double sum(double[] self) {
- return ArrayGroovyMethods.sum(self);
- }
-
/**
* Sums the items in an Iterable, adding the result to some initial value.
* <pre class="groovyTestCase">
@@ -6658,18 +6234,6 @@
}
/**
- * Sums the items in an array, adding the result to some initial value.
- *
- * @param self an array of values to sum
- * @param initialValue the items in the array will be summed to this initial value
- * @return The sum of all the items.
- * @since 1.7.1
- */
- public static Object sum(Object[] self, Object initialValue) {
- return sum(new ArrayIterator<>(self), initialValue, false);
- }
-
- /**
* Sums the items from an Iterator, adding the result to some initial value. This is
* equivalent to invoking the "plus" method on all items from the Iterator. The iterator
* will become exhausted of elements after determining the sum value.
@@ -6683,7 +6247,7 @@
return sum(self, initialValue, false);
}
- private static Object sum(Iterator<?> self, Object initialValue, boolean first) {
+ static Object sum(Iterator<?> self, Object initialValue, boolean first) {
Object result = initialValue;
Object[] param = new Object[1];
while (self.hasNext()) {
@@ -6700,41 +6264,6 @@
return result;
}
- @Deprecated
- public static byte sum(byte[] self, byte initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
- @Deprecated
- public static short sum(short[] self, short initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
- @Deprecated
- public static int sum(int[] self, int initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
- @Deprecated
- public static long sum(long[] self, long initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
- @Deprecated
- public static char sum(char[] self, char initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
- @Deprecated
- public static float sum(float[] self, float initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
- @Deprecated
- public static double sum(double[] self, double initialValue) {
- return ArrayGroovyMethods.sum(self, initialValue);
- }
-
/**
* Sums the result of applying a closure to each item of an Iterable.
* <code>coll.sum(closure)</code> is equivalent to:
@@ -6752,21 +6281,6 @@
}
/**
- * Sums the result of applying a closure to each item of an array.
- * <code>array.sum(closure)</code> is equivalent to:
- * <code>array.collect(closure).sum()</code>.
- *
- * @param self An array
- * @param closure a single parameter closure that returns a (typically) numeric value.
- * @return The sum of the values returned by applying the closure to each
- * item of the array.
- * @since 1.7.1
- */
- public static <T> Object sum(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- return sum(new ArrayIterator<>(self), null, closure, true);
- }
-
- /**
* Sums the result of applying a closure to each item returned from an iterator.
* <code>iter.sum(closure)</code> is equivalent to:
* <code>iter.collect(closure).sum()</code>. The iterator will become
@@ -6800,22 +6314,6 @@
}
/**
- * Sums the result of applying a closure to each item of an array to some initial value.
- * <code>array.sum(initVal, closure)</code> is equivalent to:
- * <code>array.collect(closure).sum(initVal)</code>.
- *
- * @param self an array
- * @param closure a single parameter closure that returns a (typically) numeric value.
- * @param initialValue the closure results will be summed to this initial value
- * @return The sum of the values returned by applying the closure to each
- * item of the array.
- * @since 1.7.1
- */
- public static <T> Object sum(T[] self, Object initialValue, @ClosureParams(FirstParam.Component.class) Closure closure) {
- return sum(new ArrayIterator<>(self), initialValue, closure, false);
- }
-
- /**
* Sums the result of applying a closure to each item of an Iterator to some initial value.
* <code>iter.sum(initVal, closure)</code> is equivalent to:
* <code>iter.collect(closure).sum(initVal)</code>. The iterator will become
@@ -6832,7 +6330,7 @@
return sum(self, initialValue, closure, false);
}
- private static Object sum(Iterator<?> self, Object initialValue, Closure closure, boolean first) {
+ static Object sum(Iterator<?> self, Object initialValue, Closure closure, boolean first) {
Object result = initialValue;
Object[] closureParam = new Object[1];
Object[] plusParam = new Object[1];
@@ -6868,26 +6366,6 @@
}
/**
- * 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>
- *
- * @param self The array of values to average
- * @return The average of all the items
- * @see #sum(java.lang.Object[])
- * @since 3.0.0
- */
- public static Object average(Object[] self) {
- Object result = sum(self);
- MetaClass metaClass = InvokerHelper.getMetaClass(result);
- result = metaClass.invokeMethod(result, "div", self.length);
- return result;
- }
-
- /**
* Averages the items from an Iterator. 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.
@@ -6937,36 +6415,6 @@
return result;
}
- @Deprecated
- public static BigDecimal average(byte[] self) {
- return ArrayGroovyMethods.average(self);
- }
-
- @Deprecated
- public static BigDecimal average(short[] self) {
- return ArrayGroovyMethods.average(self);
- }
-
- @Deprecated
- public static BigDecimal average(int[] self) {
- return ArrayGroovyMethods.average(self);
- }
-
- @Deprecated
- public static BigDecimal average(long[] self) {
- return ArrayGroovyMethods.average(self);
- }
-
- @Deprecated
- public static double average(float[] self) {
- return ArrayGroovyMethods.average(self);
- }
-
- @Deprecated
- public static double average(double[] self) {
- return ArrayGroovyMethods.average(self);
- }
-
/**
* Averages the result of applying a closure to each item of an Iterable.
* <code>iter.average(closure)</code> is equivalent to:
@@ -6987,27 +6435,6 @@
}
/**
- * Averages the result of applying a closure to each item of an array.
- * <code>array.average(closure)</code> is equivalent to:
- * <code>array.collect(closure).average()</code>.
- * <pre class="groovyTestCase">
- * def (nums, strings) = [[1, 3] as Integer[], ['to', 'from'] as String[]]
- * assert 20 == nums.average { it * 10 }
- * assert 3 == strings.average { it.size() }
- * assert 3 == strings.average (String::size)
- * </pre>
- *
- * @param self An array
- * @param closure a single parameter closure that returns a (typically) numeric value.
- * @return The average of the values returned by applying the closure to each
- * item of the array.
- * @since 3.0.0
- */
- public static <T> Object average(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- return average(new ArrayIterator<>(self), closure);
- }
-
- /**
* Averages the result of applying a closure to each item returned from an iterator.
* <code>iter.average(closure)</code> is equivalent to:
* <code>iter.collect(closure).average()</code>.
@@ -7083,60 +6510,6 @@
}
/**
- * Concatenates the <code>toString()</code> representation of each
- * item in this array, with the given String as a separator between each
- * item.
- *
- * @param self an array of Object
- * @param separator a String separator
- * @return the joined String
- * @since 1.0
- */
- public static <T> String join(T[] self, String separator) {
- return join(new ArrayIterator<>(self), separator);
- }
-
- @Deprecated
- public static String join(boolean[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(byte[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(char[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(double[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(float[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(int[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(long[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- @Deprecated
- public static String join(short[] self, String separator) {
- return ArrayGroovyMethods.join(self, separator);
- }
-
- /**
* Adds min() method to Collection objects.
* <pre class="groovyTestCase">assert 2 == [4,2,5].min()</pre>
*
@@ -7170,33 +6543,6 @@
}
/**
- * Adds min() method to Object arrays.
- *
- * @param self an array
- * @return the minimum value
- * @see #min(Iterator)
- * @since 1.5.5
- */
- public static <T> T min(T[] self) {
- return min(new ArrayIterator<>(self));
- }
-
- @Deprecated
- public static int min(int[] self) {
- return ArrayGroovyMethods.max(self);
- }
-
- @Deprecated
- public static long min(long[] self) {
- return ArrayGroovyMethods.max(self);
- }
-
- @Deprecated
- public static double min(double[] self) {
- return ArrayGroovyMethods.max(self);
- }
-
- /**
* Selects the minimum value found in the Iterable using the given comparator.
* <pre class="groovyTestCase">assert "hi" == ["hello","hi","hey"].min( { a, b {@code ->} a.length() {@code <=>} b.length() } as Comparator )</pre>
*
@@ -7235,19 +6581,6 @@
}
/**
- * Selects the minimum value found from the Object array using the given comparator.
- *
- * @param self an array
- * @param comparator a Comparator
- * @return the minimum value
- * @see #min(Iterator, java.util.Comparator)
- * @since 1.5.5
- */
- public static <T> T min(T[] self, Comparator<? super T> comparator) {
- return min(new ArrayIterator<>(self), comparator);
- }
-
- /**
* Selects the item in the iterable which when passed as a parameter to the supplied closure returns the
* minimum value. A null return value represents the least possible return value. If more than one item
* has the minimum value, an arbitrary choice is made between the items having the minimum value.
@@ -7404,29 +6737,6 @@
}
/**
- * Selects the minimum value found from the Object array
- * using the closure to determine the correct ordering.
- * <p>
- * If the closure has two parameters
- * it is used like a traditional Comparator. I.e. it should compare
- * its two parameters for order, returning a negative integer,
- * zero, or a positive integer when the first parameter is less than,
- * equal to, or greater than the second respectively. Otherwise,
- * the Closure is assumed to take a single parameter and return a
- * Comparable (typically an Integer) which is then used for
- * further comparison.
- *
- * @param self an array
- * @param closure a Closure used to determine the correct ordering
- * @return the minimum value
- * @see #min(Iterator, groovy.lang.Closure)
- * @since 1.5.5
- */
- public static <T> T min(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
- return min(new ArrayIterator<>(self), closure);
- }
-
- /**
* Adds max() method to Iterable objects.
* <pre class="groovyTestCase">
* assert 5 == [2,3,1,5,4].max()
@@ -7461,33 +6771,6 @@
}
/**
- * Adds max() method to Object arrays.
- *
- * @param self an array
- * @return the maximum value
- * @see #max(Iterator)
- * @since 1.5.5
- */
- public static <T> T max(T[] self) {
- return max(new ArrayIterator<>(self));
- }
-
- @Deprecated
- public static int max(int[] self) {
- return ArrayGroovyMethods.max(self);
- }
-
- @Deprecated
- public static long max(long[] self) {
- return ArrayGroovyMethods.max(self);
- }
-
- @Deprecated
- public static double max(double[] self) {
- return ArrayGroovyMethods.max(self);
- }
-
- /**
* Selects the item in the iterable which when passed as a parameter to the supplied closure returns the
* maximum value. A null return value represents the least possible return value, so any item for which
* the supplied closure returns null, won't be selected (unless all items return null). If more than one item
@@ -7561,29 +6844,6 @@
}
/**
- * Selects the maximum value found from the Object array
- * using the closure to determine the correct ordering.
- * <p>
- * If the closure has two parameters
- * it is used like a traditional Comparator. I.e. it should compare
- * its two parameters for order, returning a negative integer,
- * zero, or a positive integer when the first parameter is less than,
- * equal to, or greater than the second respectively. Otherwise,
- * the Closure is assumed to take a single parameter and return a
- * Comparable (typically an Integer) which is then used for
- * further comparison.
- *
- * @param self an array
- * @param closure a Closure used to determine the correct ordering
- * @return the maximum value
- * @see #max(Iterator, groovy.lang.Closure)
- * @since 1.5.5
- */
- public static <T> T max(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
- return max(new ArrayIterator<>(self), closure);
- }
-
- /**
* Selects the maximum value found in the Iterable using the given comparator.
* <pre class="groovyTestCase">
* assert "hello" == ["hello","hi","hey"].max( { a, b {@code ->} a.length() {@code <=>} b.length() } as Comparator )
@@ -7619,19 +6879,6 @@
}
/**
- * Selects the maximum value found from the Object array using the given comparator.
- *
- * @param self an array
- * @param comparator a Comparator
- * @return the maximum value
- * @see #max(Iterator, Comparator)
- * @since 1.5.5
- */
- public static <T> T max(T[] self, Comparator<? super T> comparator) {
- return max(new ArrayIterator<>(self), comparator);
- }
-
- /**
* Returns indices of the collection.
* <p>
* Example:
@@ -7648,63 +6895,6 @@
}
/**
- * Returns indices of the array.
- * <p>
- * Example:
- * <pre class="groovyTestCase">
- * String[] letters = ['a', 'b', 'c', 'd']
- * {@code assert 0..<4 == letters.indices}
- * </pre>
- *
- * @param self an array
- * @return an index range
- * @since 2.4.0
- */
- public static <T> IntRange getIndices(T[] self) {
- return new IntRange(false, 0, self.length);
- }
-
- @Deprecated
- public static IntRange getIndices(boolean[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(byte[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(char[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(double[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(float[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(int[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(long[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- @Deprecated
- public static IntRange getIndices(short[] self) {
- return ArrayGroovyMethods.getIndices(self);
- }
-
- /**
* Provide the standard Groovy <code>size()</code> method for <code>Iterator</code>.
* The iterator will become exhausted of elements after determining the size value.
*
@@ -7738,17 +6928,6 @@
}
/**
- * Provide the standard Groovy <code>size()</code> method for an array.
- *
- * @param self an Array of objects
- * @return the size (length) of the Array
- * @since 1.0
- */
- public static int size(Object[] self) {
- return self.length;
- }
-
- /**
* Check whether an <code>Iterable</code> has elements
* <pre class="groovyTestCase">
* def items = [1]
@@ -7907,30 +7086,6 @@
}
/**
- * Select a List of items from an array using a Collection to
- * identify the indices to be selected.
- *
- * @param self an array
- * @param indices a Collection of indices
- * @return a new list of the values at the given indices
- * @since 1.0
- */
- public static <T> List<T> getAt(T[] self, Collection indices) {
- List<T> answer = new ArrayList<>(indices.size());
- for (Object value : indices) {
- if (value instanceof Range) {
- answer.addAll(getAt(self, (Range) value));
- } else if (value instanceof Collection) {
- answer.addAll(getAt(self, (Collection) value));
- } else {
- int idx = DefaultTypeTransformation.intUnbox(value);
- answer.add(getAtImpl(self, idx));
- }
- }
- return answer;
- }
-
- /**
* Creates a sub-Map containing the given keys. This method is similar to
* List.subList() but uses keys rather than index ranges.
* <pre class="groovyTestCase">assert [1:10, 2:20, 4:40].subMap( [2, 4] ) == [2:20, 4:40]</pre>
@@ -8005,72 +7160,6 @@
}
/**
- * Support the range subscript operator for an Array
- *
- * @param array an Array of Objects
- * @param range a Range
- * @return a range of a list from the range's from index up to but not
- * including the range's to value
- * @since 1.0
- */
- public static <T> List<T> getAt(T[] array, Range range) {
- List<T> list = Arrays.asList(array);
- return getAt(list, range);
- }
-
- /**
- *
- * @param array an Array of Objects
- * @param range an IntRange
- * @return a range of a list from the range's from index up to but not
- * including the range's to value
- * @since 1.0
- */
- public static <T> List<T> getAt(T[] array, IntRange range) {
- List<T> list = Arrays.asList(array);
- return getAt(list, range);
- }
-
- /**
- *
- * @param array an Array of Objects
- * @param range an EmptyRange
- * @return an empty Range
- * @since 1.5.0
- */
- public static <T> List<T> getAt(T[] array, EmptyRange range) {
- return new ArrayList<>();
- }
-
- /**
- *
- * @param array an Array of Objects
- * @param range an ObjectRange
- * @return a range of a list from the range's from index up to but not
- * including the range's to value
- * @since 1.0
- */
- public static <T> List<T> getAt(T[] array, ObjectRange range) {
- List<T> list = Arrays.asList(array);
- return getAt(list, range);
- }
-
- private static <T> T getAtImpl(T[] array, int idx) {
- return array[normaliseIndex(idx, array.length)];
- }
-
- /**
- * Allows conversion of arrays into a mutable List.
- *
- * @param array an Array of Objects
- * @return the array as a List
- * @since 1.0
- */
- public static <T> List<T> toList(T[] array) {
- return new ArrayList<>(Arrays.asList(array));
- }
-
- /**
* Support the subscript operator for a List.
* <pre class="groovyTestCase">def list = [2, "a", 5.3]
* assert list[1] == "a"</pre>
@@ -8359,38 +7448,6 @@
}
}
- // todo: remove after putAt(Splice) gets deleted
- @Deprecated
- protected static List getSubList(List self, List splice) {
- int left /* = 0 */;
- int right = 0;
- boolean emptyRange = false;
- if (splice.size() == 2) {
- left = DefaultTypeTransformation.intUnbox(splice.get(0));
- right = DefaultTypeTransformation.intUnbox(splice.get(1));
- } else if (splice instanceof IntRange) {
- IntRange range = (IntRange) splice;
- left = range.getFrom();
- right = range.getTo();
- } else if (splice instanceof EmptyRange) {
- RangeInfo info = subListBorders(self.size(), (EmptyRange) splice);
- left = info.from;
- emptyRange = true;
- } else {
- throw new IllegalArgumentException("You must specify a list of 2 indexes to create a sub-list");
- }
- int size = self.size();
- left = normaliseIndex(left, size);
- right = normaliseIndex(right, size);
- List sublist /* = null */;
- if (!emptyRange) {
- sublist = self.subList(left, right + 1);
- } else {
- sublist = self.subList(left, left);
- }
- return sublist;
- }
-
/**
* Support the subscript operator for a Map.
* <pre class="groovyTestCase">def map = [1:10]
@@ -8912,11 +7969,6 @@
return withLazyDefault(self, init);
}
- @Deprecated
- public static <T> List<T> withDefault$$bridge(List<T> self, @ClosureParams(value=SimpleType.class, options = "int") Closure<T> init) {
- return withDefault(self, init);
- }
-
/**
* Decorates a list allowing it to grow when called with a non-existent index value.
* When called with such values, the list is grown in size and a default value
@@ -8963,11 +8015,6 @@
return ListWithDefault.newInstance(self, true, init);
}
- @Deprecated
- public static <T> List<T> withLazyDefault$$bridge(List<T> self, @ClosureParams(value=SimpleType.class, options = "int") Closure<T> init) {
- return ListWithDefault.newInstance(self, true, init);
- }
-
/**
* Decorates a list allowing it to grow when called with a non-existent index value.
* When called with such values, the list is grown in size and a default value
@@ -9008,11 +8055,6 @@
return ListWithDefault.newInstance(self, false, init);
}
- @Deprecated
- public static <T> List<T> withEagerDefault$$bridge(List<T> self, @ClosureParams(value=SimpleType.class, options = "int") Closure<T> init) {
- return ListWithDefault.newInstance(self, false, init);
- }
-
/**
* Zips an Iterable with indices in (value, index) order.
* <p/>
@@ -9094,36 +8136,6 @@
return result;
}
- @Deprecated
- public static Map<Integer, Integer> indexed(int[] self) {
- return ArrayGroovyMethods.indexed(self);
- }
-
- @Deprecated
- public static Map<Integer, Integer> indexed(int[] self, int offset) {
- return ArrayGroovyMethods.indexed(self, offset);
- }
-
- @Deprecated
- public static Map<Integer, Long> indexed(long[] self) {
- return ArrayGroovyMethods.indexed(self);
- }
-
- @Deprecated
- public static Map<Integer, Long> indexed(long[] self, int offset) {
- return ArrayGroovyMethods.indexed(self, offset);
- }
-
- @Deprecated
- public static Map<Integer, Double> indexed(double[] self) {
- return ArrayGroovyMethods.indexed(self);
- }
-
- @Deprecated
- public static Map<Integer, Double> indexed(double[] self, int offset) {
- return ArrayGroovyMethods.indexed(self, offset);
- }
-
/**
* Zips an iterator with indices in (value, index) order.
* <p/>
@@ -11711,59 +10723,6 @@
}
/**
- * Coerce an Object array to a boolean value.
- * An Object array is false if the array is of length 0.
- * and to true otherwise
- *
- * @param array the array
- * @return the boolean value
- * @since 1.7.0
- */
- public static boolean asBoolean(Object[] array) {
- return array != null && array.length > 0;
- }
-
- @Deprecated
- public static boolean asBoolean(byte[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(short[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(int[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(long[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(float[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(double[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(boolean[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- @Deprecated
- public static boolean asBoolean(char[] array) {
- return ArrayGroovyMethods.asBoolean(array);
- }
-
- /**
* Coerce a character to a boolean value.
* A character is coerced to false if it's character value is equal to 0,
* and to true otherwise.
@@ -11899,32 +10858,6 @@
}
/**
- * Converts the given array to either a List, Set, or
- * SortedSet. If the given class is something else, the
- * call is deferred to {@link #asType(Object,Class)}.
- *
- * @param ary an array
- * @param clazz the desired class
- * @return the object resulting from this type conversion
- * @see #asType(java.lang.Object, java.lang.Class)
- * @since 1.5.1
- */
- @SuppressWarnings("unchecked")
- public static <T> T asType(Object[] ary, Class<T> clazz) {
- if (clazz == List.class) {
- return (T) new ArrayList(Arrays.asList(ary));
- }
- if (clazz == Set.class) {
- return (T) new HashSet(Arrays.asList(ary));
- }
- if (clazz == SortedSet.class) {
- return (T) new TreeSet(Arrays.asList(ary));
- }
-
- return asType((Object) ary, clazz);
- }
-
- /**
* Coerces the closure to an implementation of the given class. The class
* is assumed to be an interface or class with a single method definition.
* The closure is used as the implementation of that single method.
@@ -13203,11 +12136,6 @@
return result;
}
- @Deprecated
- public static boolean equals(int[] left, int[] right) {
- return ArrayGroovyMethods.equals(left, right);
- }
-
/**
* Determines if the contents of this array are equal to the
* contents of the given list, in the same order. This returns
@@ -13898,47 +12826,6 @@
return flatten(toList(self), new ArrayList());
}
- @Deprecated
- public static Collection flatten(boolean[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
- @Deprecated
- public static Collection flatten(byte[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
- @Deprecated
- public static Collection flatten(char[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
- @Deprecated
- public static Collection flatten(short[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
- @Deprecated
- public static Collection flatten(int[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
-
- @Deprecated
- public static Collection flatten(long[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
- @Deprecated
- public static Collection flatten(float[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
- @Deprecated
- public static Collection flatten(double[] self) {
- return flatten(toList(self), new ArrayList());
- }
-
@SuppressWarnings("unchecked")
private static Collection flatten(Iterable elements, Collection addTo) {
for (Object element : elements) {
@@ -14151,166 +13038,6 @@
return NumberMath.rightShiftUnsigned(self, operand);
}
- @Deprecated
- public static List<Byte> getAt(byte[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Character> getAt(char[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Short> getAt(short[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Integer> getAt(int[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Long> getAt(long[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Float> getAt(float[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Double> getAt(double[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Boolean> getAt(boolean[] array, Range range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Byte> getAt(byte[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Character> getAt(char[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Short> getAt(short[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Integer> getAt(int[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Long> getAt(long[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Float> getAt(float[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Double> getAt(double[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Boolean> getAt(boolean[] array, IntRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Byte> getAt(byte[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Character> getAt(char[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Short> getAt(short[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Integer> getAt(int[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Long> getAt(long[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Float> getAt(float[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Double> getAt(double[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Boolean> getAt(boolean[] array, ObjectRange range) {
- return ArrayGroovyMethods.getAt(array, range);
- }
-
- @Deprecated
- public static List<Byte> getAt(byte[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Character> getAt(char[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Short> getAt(short[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Integer> getAt(int[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Long> getAt(long[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Float> getAt(float[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Double> getAt(double[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
- @Deprecated
- public static List<Boolean> getAt(boolean[] array, Collection indices) {
- return ArrayGroovyMethods.getAt(array, indices);
- }
-
/**
* Support the subscript operator for a Bitset
*
@@ -14383,126 +13110,6 @@
self.set(index, value);
}
- @Deprecated
- public static int size(boolean[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(byte[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(char[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(short[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(int[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(long[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(float[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static int size(double[] array) {
- return Array.getLength(array);
- }
-
- @Deprecated
- public static List<Byte> toList(byte[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Boolean> toList(boolean[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Character> toList(char[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Short> toList(short[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Integer> toList(int[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Long> toList(long[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Float> toList(float[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static List<Double> toList(double[] array) {
- return ArrayGroovyMethods.toList(array);
- }
-
- @Deprecated
- public static Set<Boolean> toSet(boolean[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Byte> toSet(byte[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Character> toSet(char[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Short> toSet(short[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Integer> toSet(int[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Long> toSet(long[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Float> toSet(float[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
- @Deprecated
- public static Set<Double> toSet(double[] array) {
- return ArrayGroovyMethods.toSet(array);
- }
-
/**
* Convert a Collection to a Set. Always returns a new Set
* even if the Collection is already a Set.
@@ -14575,65 +13182,6 @@
}
/**
- * Implements the getAt(int) method for primitive type arrays.
- *
- * @param self an array object
- * @param idx the index of interest
- * @return the returned value from the array
- * @since 1.5.0
- */
- @Deprecated
- protected static Object primitiveArrayGet(Object self, int idx) {
- return Array.get(self, normaliseIndex(idx, Array.getLength(self)));
- }
-
- /**
- * Implements the getAt(Range) method for primitive type arrays.
- *
- * @param self an array object
- * @param range the range of indices of interest
- * @return the returned values from the array corresponding to the range
- * @since 1.5.0
- */
- @SuppressWarnings("unchecked")
- @Deprecated
- protected static List primitiveArrayGet(Object self, Range range) {
- List answer = new ArrayList();
- for (Object next : range) {
- int idx = DefaultTypeTransformation.intUnbox(next);
- answer.add(primitiveArrayGet(self, idx));
- }
- return answer;
- }
-
- /**
- * Implements the getAt(Collection) method for primitive type arrays. Each
- * value in the collection argument is assumed to be a valid array index.
- * The value at each index is then added to a list which is returned.
- *
- * @param self an array object
- * @param indices the indices of interest
- * @return the returned values from the array
- * @since 1.0
- */
- @SuppressWarnings("unchecked")
- @Deprecated
- protected static List primitiveArrayGet(Object self, Collection indices) {
- List answer = new ArrayList();
- for (Object value : indices) {
- if (value instanceof Range) {
- answer.addAll(primitiveArrayGet(self, (Range) value));
- } else if (value instanceof List) {
- answer.addAll(primitiveArrayGet(self, (List) value));
- } else {
- int idx = DefaultTypeTransformation.intUnbox(value);
- answer.add(primitiveArrayGet(self, idx));
- }
- }
- return answer;
- }
-
- /**
* Implements the setAt(int idx) method for primitive type arrays.
*
* @param self an object
@@ -14658,46 +13206,6 @@
return self;
}
- @Deprecated
- public static boolean contains(boolean[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(byte[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(char[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(short[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(int[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(long[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(float[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
- @Deprecated
- public static boolean contains(double[] self, Object value) {
- return ArrayGroovyMethods.contains(self, value);
- }
-
/**
* Checks whether the array contains the given value.
*
@@ -14713,46 +13221,6 @@
return false;
}
- @Deprecated
- public static String toString(boolean[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(byte[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(char[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(short[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(int[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(long[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(float[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
- @Deprecated
- public static String toString(double[] self) {
- return ArrayGroovyMethods.toString(self);
- }
-
/**
* Returns the string representation of the given map.
*
@@ -14888,7 +13356,7 @@
* @since 1.0
*/
public static Number next(Number self) {
- return NumberNumberPlus.plus(self, ONE);
+ return NumberNumberPlus.plus(self, Integer.valueOf(1));
}
/**
@@ -14910,7 +13378,7 @@
* @since 1.0
*/
public static Number previous(Number self) {
- return NumberNumberMinus.minus(self, ONE);
+ return NumberNumberMinus.minus(self, Integer.valueOf(1));
}
/**
@@ -16579,7 +15047,7 @@
return NumberMath.toBigInteger(self);
}
- //-------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
// Boolean based methods
/**
@@ -16630,9 +15098,7 @@
return left ^ Boolean.TRUE.equals(right);
}
-// public static Boolean negate(Boolean left) {
-// return Boolean.valueOf(!left.booleanValue());
-// }
+ //--------------------------------------------------------------------------
/**
* Allows a simple syntax for using timers. This timer will execute the
@@ -16656,23 +15122,6 @@
}
/**
- * Traverse through each byte of this Byte array. Alias for each.
- *
- * @param self a Byte array
- * @param closure a closure
- * @see #each(java.lang.Object, groovy.lang.Closure)
- * @since 1.5.5
- */
- public static void eachByte(Byte[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- each(self, closure);
- }
-
- @Deprecated
- public static void eachByte(byte[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
- ArrayGroovyMethods.eachByte(self, closure);
- }
-
- /**
* Iterates over the elements of an aggregate of items and returns
* the index of the first item that matches the condition specified in the closure.
*
@@ -16781,34 +15230,6 @@
}
/**
- * Iterates over the elements of an Array and returns the index of the first item that satisfies the
- * condition specified by the closure.
- *
- * @param self an Array
- * @param condition the matching condition
- * @return an integer that is the index of the first matched object or -1 if no match was found
- * @since 2.5.0
- */
- public static <T> int findIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
- return findIndexOf(self, 0, condition);
- }
-
- /**
- * Iterates over the elements of an Array, starting from a
- * specified startIndex, and returns the index of the first item that satisfies the
- * condition specified by the closure.
- *
- * @param self an Array
- * @param startIndex start matching from this index
- * @param condition the matching condition
- * @return an integer that is the index of the first matched object or -1 if no match was found
- * @since 2.5.0
- */
- public static <T> int findIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
- return findIndexOf(new ArrayIterator<>(self), startIndex, condition);
- }
-
- /**
* Iterates over the elements of an aggregate of items and returns
* the index of the last item that matches the condition specified in the closure.
* Example (aggregate is {@code ChronoUnit} enum values):
@@ -16914,35 +15335,6 @@
}
/**
- * Iterates over the elements of an Array and returns
- * the index of the last item that matches the condition specified in the closure.
- *
- * @param self an Array
- * @param condition the matching condition
- * @return an integer that is the index of the last matched object or -1 if no match was found
- * @since 2.5.0
- */
- public static <T> int findLastIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
- return findLastIndexOf(new ArrayIterator<>(self), 0, condition);
- }
-
- /**
- * Iterates over the elements of an Array, starting
- * from a specified startIndex, and returns the index of the last item that
- * matches the condition specified in the closure.
- *
- * @param self an Array
- * @param startIndex start matching from this index
- * @param condition the matching condition
- * @return an integer that is the index of the last matched object or -1 if no match was found
- * @since 2.5.0
- */
- public static <T> int findLastIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
- // TODO could be made more efficient by using a reverse index
- return findLastIndexOf(new ArrayIterator<>(self), startIndex, condition);
- }
-
- /**
* Iterates over the elements of an aggregate of items and returns
* the index values of the items that match the condition specified in the closure.
*
@@ -17040,34 +15432,6 @@
}
/**
- * Iterates over the elements of an Array and returns
- * the index values of the items that match the condition specified in the closure.
- *
- * @param self an Array
- * @param condition the matching condition
- * @return a list of numbers corresponding to the index values of all matched objects
- * @since 2.5.0
- */
- public static <T> List<Number> findIndexValues(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
- return findIndexValues(self, 0, condition);
- }
-
- /**
- * Iterates over the elements of an Array, starting from
- * a specified startIndex, and returns the index values of the items that match
- * the condition specified in the closure.
- *
- * @param self an Array
- * @param startIndex start matching from this index
- * @param condition the matching condition
- * @return a list of numbers corresponding to the index values of all matched objects
- * @since 2.5.0
- */
- public static <T> List<Number> findIndexValues(T[] self, Number startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
- return findIndexValues(new ArrayIterator<>(self), startIndex, condition);
- }
-
- /**
* Iterates through the classloader parents until it finds a loader with a class
* named "org.codehaus.groovy.tools.RootLoader". If there is no such class
* <code>null</code> will be returned. The name is used for comparison because
@@ -17454,19 +15818,6 @@
* Attempts to create an Iterator for the given object by first
* converting it to a Collection.
*
- * @param a an array
- * @return an Iterator for the given Array.
- * @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object[])
- * @since 1.6.4
- */
- public static <T> Iterator<T> iterator(T[] a) {
- return DefaultTypeTransformation.asCollection(a).iterator();
- }
-
- /**
- * Attempts to create an Iterator for the given object by first
- * converting it to a Collection.
- *
* @param o an object
* @return an Iterator for the given Object.
* @see org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation#asCollection(java.lang.Object)
@@ -17657,67 +16008,6 @@
}
/**
- * Swaps two elements at the specified positions.
- * <p>
- * Example:
- * <pre class="groovyTestCase">
- * assert (["a", "c", "b", "d"] as String[]) == (["a", "b", "c", "d"] as String[]).swap(1, 2)
- * </pre>
- *
- * @param self an array
- * @param i a position
- * @param j a position
- * @return self
- * @since 2.4.0
- */
- public static <T> T[] swap(T[] self, int i, int j) {
- T tmp = self[i];
- self[i] = self[j];
- self[j] = tmp;
- return self;
- }
-
- @Deprecated
- public static boolean[] swap(boolean[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static byte[] swap(byte[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static char[] swap(char[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static double[] swap(double[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static float[] swap(float[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static int[] swap(int[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static long[] swap(long[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- @Deprecated
- public static short[] swap(short[] self, int i, int j) {
- return ArrayGroovyMethods.swap(self, i, j);
- }
-
- /**
* Modifies this list by removing the element at the specified position
* in this list. Returns the removed element. Essentially an alias for
* {@link List#remove(int)} but with no ambiguity for List<Integer>.
@@ -17789,4 +16079,1125 @@
return sw.toString();
}
+
+ //--------------------------------------------------------------------------
+ // attic
+
+ @Deprecated(since = "5.0.0")
+ public static <T> boolean any(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
+ return ArrayGroovyMethods.any(self, predicate);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(boolean[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(byte[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(char[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(short[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(int[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(long[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(float[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(double[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean asBoolean(Object[] self) {
+ return ArrayGroovyMethods.asBoolean(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T asType(Object[] self, Class<T> type) {
+ return ArrayGroovyMethods.asType(self, type);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static BigDecimal average(byte[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static BigDecimal average(short[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static BigDecimal average(int[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static BigDecimal average(long[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double average(float[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double average(double[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Object average(Object[] self) {
+ return ArrayGroovyMethods.average(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Object average(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ return ArrayGroovyMethods.average(self, closure);
+ }
+
+ @Deprecated
+ public static <T, K, V> Collection<T> collectMany$$bridge(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<? extends Collection<? extends T>> projection) {
+ return collectMany(self, projection);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(boolean[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(byte[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(char[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(short[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(int[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(long[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(float[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean contains(double[] self, Object value) {
+ return ArrayGroovyMethods.contains(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(boolean[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(byte[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(char[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(short[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(int[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(long[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(float[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(double[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Number count(Object[] self, Object value) {
+ return ArrayGroovyMethods.count(self, value);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Number count(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
+ return ArrayGroovyMethods.count(self, predicate);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <K,E> Map<K, Integer> countBy(E[] self, @ClosureParams(FirstParam.Component.class) Closure<K> closure) {
+ return ArrayGroovyMethods.countBy(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] each(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ return ArrayGroovyMethods.each(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static void eachByte(byte[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ ArrayGroovyMethods.eachByte(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static void eachByte(Byte[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ ArrayGroovyMethods.each(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] eachWithIndex(T[] self, @ClosureParams(value=FromString.class, options="T,Integer") Closure closure) {
+ return ArrayGroovyMethods.eachWithIndex(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean equals(int[] left, int[] right) {
+ return ArrayGroovyMethods.equals(left, right);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> boolean every(T[] self, @ClosureParams(FirstParam.Component.class) Closure predicate) {
+ return ArrayGroovyMethods.every(self, predicate);
+ }
+
+ @Deprecated
+ public static Collection findAll$$bridge(Object self) {
+ return findAll(self);
+ }
+
+ @Deprecated
+ public static <T> Collection<T> findAll$$bridge(T[] self) {
+ return findAll(self);
+ }
+
+ @Deprecated
+ public static Collection findAll$$bridge(Object self, Closure closure) {
+ return findAll(self, closure);
+ }
+
+ @Deprecated
+ public static <T> Collection<T> findAll$$bridge(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ return findAll(self, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<Number> findIndexValues(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ return findIndexValues(self, 0, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<Number> findIndexValues(T[] self, Number startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ return findIndexValues(new ArrayIterator<>(self), startIndex, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> int findIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ return findIndexOf(self, 0, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> int findIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ return findIndexOf(new ArrayIterator<>(self), startIndex, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> int findLastIndexOf(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ return findLastIndexOf(new ArrayIterator<>(self), 0, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> int findLastIndexOf(T[] self, int startIndex, @ClosureParams(FirstParam.Component.class) Closure condition) {
+ // TODO could be made more efficient by using a reverse index
+ return findLastIndexOf(new ArrayIterator<>(self), startIndex, condition);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(boolean[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(byte[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(char[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(short[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(int[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(long[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(float[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Collection flatten(double[] self) {
+ return ArrayGroovyMethods.flatten(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Boolean> getAt(boolean[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Byte> getAt(byte[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Character> getAt(char[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Short> getAt(short[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Integer> getAt(int[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Long> getAt(long[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Float> getAt(float[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Double> getAt(double[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<T> getAt(T[] self, Range range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Boolean> getAt(boolean[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Byte> getAt(byte[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Character> getAt(char[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Short> getAt(short[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Integer> getAt(int[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Long> getAt(long[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Float> getAt(float[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Double> getAt(double[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<T> getAt(T[] self, IntRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Boolean> getAt(boolean[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Byte> getAt(byte[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Character> getAt(char[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Short> getAt(short[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Integer> getAt(int[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Long> getAt(long[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Float> getAt(float[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Double> getAt(double[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<T> getAt(T[] self, ObjectRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<T> getAt(T[] self, EmptyRange range) {
+ return ArrayGroovyMethods.getAt(self, range);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Boolean> getAt(boolean[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Byte> getAt(byte[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Character> getAt(char[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Short> getAt(short[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Integer> getAt(int[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Long> getAt(long[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Float> getAt(float[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Double> getAt(double[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<T> getAt(T[] self, Collection indices) {
+ return ArrayGroovyMethods.getAt(self, indices);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(boolean[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(byte[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(char[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(short[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(int[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(long[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(float[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static IntRange getIndices(double[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> IntRange getIndices(T[] self) {
+ return ArrayGroovyMethods.getIndices(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Collection<T> grep(T[] self) {
+ return ArrayGroovyMethods.grep(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Collection<T> grep(T[] self, Object filter) {
+ return ArrayGroovyMethods.grep(self, filter);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Map<Integer, Integer> indexed(int[] self) {
+ return ArrayGroovyMethods.indexed(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Map<Integer, Long> indexed(long[] self) {
+ return ArrayGroovyMethods.indexed(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Map<Integer, Double> indexed(double[] self) {
+ return ArrayGroovyMethods.indexed(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Map<Integer, Integer> indexed(int[] self, int offset) {
+ return ArrayGroovyMethods.indexed(self, offset);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Map<Integer, Long> indexed(long[] self, int offset) {
+ return ArrayGroovyMethods.indexed(self, offset);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Map<Integer, Double> indexed(double[] self, int offset) {
+ return ArrayGroovyMethods.indexed(self, offset);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <E,T, V extends T> T inject(E[] self, @ClosureParams(value=FromString.class,options="E,E") Closure<V> closure) {
+ return ArrayGroovyMethods.inject(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <E, T, U extends T, V extends T> T inject(E[] self, U initialValue, @ClosureParams(value=FromString.class,options="U,E") Closure<V> closure) {
+ return ArrayGroovyMethods.inject(self, initialValue, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Iterator<T> iterator(T[] self) {
+ return ArrayGroovyMethods.iterator(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(boolean[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(byte[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(char[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(short[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(int[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(long[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(float[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String join(double[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> String join(T[] self, String separator) {
+ return ArrayGroovyMethods.join(self, separator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int max(int[] self) {
+ return ArrayGroovyMethods.max(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static long max(long[] self) {
+ return ArrayGroovyMethods.max(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double max(double[] self) {
+ return ArrayGroovyMethods.max(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T max(T[] self) {
+ return ArrayGroovyMethods.max(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T max(T[] self, Comparator<? super T> comparator) {
+ return ArrayGroovyMethods.max(self, comparator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T max(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
+ return ArrayGroovyMethods.max(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int min(int[] self) {
+ return ArrayGroovyMethods.min(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static long min(long[] self) {
+ return ArrayGroovyMethods.min(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double min(double[] self) {
+ return ArrayGroovyMethods.min(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T min(T[] self) {
+ return ArrayGroovyMethods.min(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T min(T[] self, Comparator<? super T> comparator) {
+ return ArrayGroovyMethods.min(self, comparator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T min(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
+ return ArrayGroovyMethods.min(self, closure);
+ }
+
+ /**
+ * Implements the getAt(int) method for primitive type arrays.
+ *
+ * @param self an array object
+ * @param idx the index of interest
+ * @return the returned value from the array
+ * @since 1.5.0
+ */
+ @Deprecated(since = "5.0.0")
+ protected static Object primitiveArrayGet(Object self, int idx) {
+ return Array.get(self, normaliseIndex(idx, Array.getLength(self)));
+ }
+
+ /**
+ * Implements the getAt(Range) method for primitive type arrays.
+ *
+ * @param self an array object
+ * @param range the range of indices of interest
+ * @return the returned values from the array corresponding to the range
+ * @since 1.5.0
+ */
+ @Deprecated(since = "5.0.0")
+ protected static List primitiveArrayGet(Object self, Range range) {
+ List answer = new ArrayList();
+ for (Object next : range) {
+ int idx = DefaultTypeTransformation.intUnbox(next);
+ answer.add(primitiveArrayGet(self, idx));
+ }
+ return answer;
+ }
+
+ /**
+ * Implements the getAt(Collection) method for primitive type arrays. Each
+ * value in the collection argument is assumed to be a valid array index.
+ * The value at each index is then added to a list which is returned.
+ *
+ * @param self an array object
+ * @param indices the indices of interest
+ * @return the returned values from the array
+ * @since 1.0
+ */
+ @Deprecated(since = "5.0.0")
+ protected static List primitiveArrayGet(Object self, Collection indices) {
+ List answer = new ArrayList();
+ for (Object value : indices) {
+ if (value instanceof Range) {
+ answer.addAll(primitiveArrayGet(self, (Range) value));
+ } else if (value instanceof List) {
+ answer.addAll(primitiveArrayGet(self, (List) value));
+ } else {
+ int idx = DefaultTypeTransformation.intUnbox(value);
+ answer.add(primitiveArrayGet(self, idx));
+ }
+ }
+ return answer;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] reverseEach(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ return ArrayGroovyMethods.reverseEach(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(boolean[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(byte[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(char[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(short[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(int[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(long[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(float[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(double[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int size(Object[] self) {
+ return self.length;
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static byte sum(byte[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static char sum(char[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static short sum(short[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int sum(int[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static long sum(long[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static float sum(float[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double sum(double[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Object sum(Object[] self) {
+ return ArrayGroovyMethods.sum(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static byte sum(byte[] self, byte initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static float sum(float[] self, float initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static short sum(short[] self, short initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int sum(int[] self, int initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static long sum(long[] self, long initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static char sum(char[] self, char initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double sum(double[] self, double initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Object sum(Object[] self, Object initialValue) {
+ return ArrayGroovyMethods.sum(self, initialValue);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Object sum(T[] self, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ return ArrayGroovyMethods.sum(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> Object sum(T[] self, Object initialValue, @ClosureParams(FirstParam.Component.class) Closure closure) {
+ return ArrayGroovyMethods.sum(self, initialValue, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static boolean[] swap(boolean[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static byte[] swap(byte[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static char[] swap(char[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static short[] swap(short[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int[] swap(int[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static long[] swap(long[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static float[] swap(float[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double[] swap(double[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] swap(T[] self, int i, int j) {
+ return ArrayGroovyMethods.swap(self, i, j);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Boolean> toList(boolean[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Byte> toList(byte[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Character> toList(char[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Short> toList(short[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Integer> toList(int[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Long> toList(long[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Float> toList(float[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static List<Double> toList(double[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> List<T> toList(T[] self) {
+ return ArrayGroovyMethods.toList(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Boolean> toSet(boolean[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Byte> toSet(byte[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Character> toSet(char[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Short> toSet(short[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Integer> toSet(int[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Long> toSet(long[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Float> toSet(float[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static Set<Double> toSet(double[] self) {
+ return ArrayGroovyMethods.toSet(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(boolean[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(byte[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(char[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(short[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(int[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(long[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(float[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static String toString(double[] self) {
+ return ArrayGroovyMethods.toString(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] toUnique(T[] self) {
+ return ArrayGroovyMethods.toUnique(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] toUnique(T[] self, Comparator<? super T> comparator) {
+ return ArrayGroovyMethods.toUnique(self, comparator);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static <T> T[] toUnique(T[] self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {
+ return ArrayGroovyMethods.toUnique(self, closure);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static int[][] transpose(int[][] self) {
+ return ArrayGroovyMethods.transpose(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static long[][] transpose(long[][] self) {
+ return ArrayGroovyMethods.transpose(self);
+ }
+
+ @Deprecated(since = "5.0.0")
+ public static double[][] transpose(double[][] self) {
+ return ArrayGroovyMethods.transpose(self);
+ }
+
+ @Deprecated
+ public static <T> List<T> withDefault$$bridge(List<T> self, @ClosureParams(value=SimpleType.class, options = "int") Closure<T> init) {
+ return withDefault(self, init);
+ }
+
+ @Deprecated
+ public static <T> List<T> withLazyDefault$$bridge(List<T> self, @ClosureParams(value=SimpleType.class, options = "int") Closure<T> init) {
+ return ListWithDefault.newInstance(self, true, init);
+ }
+
+ @Deprecated
+ public static <T> List<T> withEagerDefault$$bridge(List<T> self, @ClosureParams(value=SimpleType.class, options = "int") Closure<T> init) {
+ return ListWithDefault.newInstance(self, false, init);
+ }
}