/** * Iterates through a List, passing each item to the given closure. * * @param self the List over which we iterate * @param closure the closure applied on each element found * @return the self List * @since 2.4.0 */ public static <T> List<T> each(List<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { return (List<T>) each((Iterable<T>) self, closure); }
/** * 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); }
/** * Iterates through a Collection, passing each item to the given closure. * * @param self the Collection over which we iterate * @param closure the closure applied on each element found * @return the self Collection * @since 2.4.0 */ public static <T> Collection<T> each(Collection<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { return (Collection<T>) each((Iterable<T>) self, closure); }
/** * 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); }
/** * Iterates through an Iterable, passing each item to the given closure. * * @param self the Iterable over which we iterate * @param closure the closure applied on each element found * @return the self Iterable */ public static <T> Iterable<T> each(Iterable<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { each(self.iterator(), closure); return self; }
/** * Iterates through a Set, passing each item to the given closure. * * @param self the Set over which we iterate * @param closure the closure applied on each element found * @return the self Set * @since 2.4.0 */ public static <T> Set<T> each(Set<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { return (Set<T>) each((Iterable<T>) self, closure); }
/** * Iterates through a SortedSet, passing each item to the given closure. * * @param self the SortedSet over which we iterate * @param closure the closure applied on each element found * @return the self SortedSet * @since 2.4.0 */ public static <T> SortedSet<T> each(SortedSet<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { return (SortedSet<T>) each((Iterable<T>) self, closure); }
/** * Applies a function on each combination of the input lists. * <p> * Example usage: * <pre class="groovyTestCase">[[2, 3],[4, 5, 6]].eachCombination { println "Found $it" }</pre> * * @param self a Collection of lists * @param function a closure to be called on each combination * @see groovy.util.GroovyCollections#combinations(Iterable) * @since 2.2.0 */ public static void eachCombination(Iterable self, Closure<?> function) { each(GroovyCollections.combinations(self), function); }
/** * Process each regex group matched substring of the given pattern. If the closure * parameter takes one argument, an array with all match groups is passed to it. * If the closure takes as many arguments as there are match groups, then each * parameter will be one match group. * * @param self the source string * @param pattern a regex Pattern * @param closure a closure with one parameter or as much parameters as groups * @return the source string * @since 1.6.1 */ public static String eachMatch(String self, Pattern pattern, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) { Matcher m = pattern.matcher(self); each(m, closure); 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 * from the resulting iterator will be passed to the closure. * <pre class="groovyTestCase"> * String result = '' * ['a', 'b', 'c'].each{ result += it } * assert result == 'abc' * </pre> * * @param self the object over which we iterate * @param closure the closure applied on each element found * @return the self Object * @since 1.0 */ public static <T> T each(T self, Closure closure) { each(InvokerHelper.asIterator(self), closure); 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) { each(new ReverseListIterator<T>(Arrays.asList(self)), closure); return self; }
/** * Iterate over each element of the list in the reverse order. * <pre class="groovyTestCase">def result = [] * [1,2,3].reverseEach { result << it } * assert result == [3,2,1]</pre> * * @param self a List * @param closure a closure to which each item is passed. * @return the original list * @since 1.5.0 */ public static <T> List<T> reverseEach(List<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { each(new ReverseListIterator<T>(self), closure); return self; }
public void testEachMap() { final List<String> result = new ArrayList<String>(); each(zoo, new Closure(null) { public void doCall(String k, Integer v) { result.add("k=" + k + ",v=" + v); } }); assertEquals(Arrays.asList("k=Monkeys,v=3", "k=Giraffe,v=2", "k=Lions,v=5" ), result); }
public void testEachList() { final List<Integer> result = new ArrayList<Integer>(); each(animals, new Closure(null) { public void doCall(String arg) { result.add(arg.length()); } }); assertEquals(Arrays.asList(3, 4, 5), result); }
/** * Traverse through each byte of this Byte array. Alias for each. * * @param self a Byte array * @param closure a closure * @see #each(Object,Closure) */ public static void eachByte(Byte[] self, Closure closure) { each(self, closure); }
/** * Traverse through each byte of this byte array. Alias for each. * * @param self a byte array * @param closure a closure * @see #each(Object,Closure) */ public static void eachByte(byte[] self, Closure closure) { each(self, closure); }
/** * Iterate over each element of the list in the reverse order. * * @param self a List * @param closure a closure to which each item is passed. * @return the original list * @since 1.5.0 */ public static List reverseEach(List self, Closure closure) { each(new ReverseListIterator(self), closure); return self; }
/** * Iterate over each element of the array in the reverse order. * * @param self an Object 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, Closure closure) { each(new ReverseListIterator<T>(Arrays.asList(self)), closure); return self; }
public static<T extends Object >Iterable<T> each(Iterable<T> self, Closure closure) { if ((!Caller.isAsynchronous(self, "each", closure))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "each", self, closure))) { return DefaultGroovyMethods.each(self, closure); } return CpsDefaultGroovyMethods.$each__java_lang_Iterable__groovy_lang_Closure(self, closure); }
public static<T extends Object >Collection<T> each(Collection<T> self, Closure closure) { if ((!Caller.isAsynchronous(self, "each", closure))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "each", self, closure))) { return DefaultGroovyMethods.each(self, closure); } return CpsDefaultGroovyMethods.$each__java_util_Collection__groovy_lang_Closure(self, closure); }