/** * Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth). * <p> * Example: * <pre class="groovyTestCase"> * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] * assert items.findAll() == [1, 2, true, 'foo', [4, 5]] * </pre> * * @param self a List * @return a List of the values found * @since 2.4.0 * @see Closure#IDENTITY */ public static <T> List<T> findAll(List<T> self) { return findAll(self, Closure.IDENTITY); }
/** * Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth). * <p> * Example: * <pre class="groovyTestCase"> * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] * assert items.findAll() == [1, 2, true, 'foo', [4, 5]] * </pre> * * @param self a Collection * @return a Collection of the values found * @since 1.8.1 * @see Closure#IDENTITY */ public static <T> Collection<T> findAll(Collection<T> self) { return findAll(self, Closure.IDENTITY); }
/** * Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth). * <p> * Example: * <pre class="groovyTestCase"> * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[] * assert items.findAll() == [1, 2, true, 'foo', [4, 5]] * </pre> * * @param self an array * @return a collection of the elements found * @see Closure#IDENTITY * @since 2.0 */ public static <T> Collection<T> findAll(T[] self) { return findAll(self, Closure.IDENTITY); }
/** * Finds all items matching the IDENTITY Closure (i.e. matching Groovy truth). * <p> * Example: * <pre class="groovyTestCase"> * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] * assert items.findAll() == [1, 2, true, 'foo', [4, 5]] * </pre> * * @param self an Object with an Iterator returning its values * @return a List of the values found * @since 1.8.1 * @see Closure#IDENTITY */ public static Collection findAll(Object self) { return findAll(self, Closure.IDENTITY); }
/** * Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth). * <p> * Example: * <pre class="groovyTestCase"> * def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Set * assert items.findAll() == [1, 2, true, 'foo', [4, 5]] as Set * </pre> * * @param self a Set * @return a Set of the values found * @since 2.4.0 * @see Closure#IDENTITY */ public static <T> Set<T> findAll(Set<T> self) { return findAll(self, Closure.IDENTITY); }
/** * Finds all values matching the closure condition. * <pre class="groovyTestCase">assert ([2,4] as Set) == ([1,2,3,4] as Set).findAll { it % 2 == 0 }</pre> * * @param self a Set * @param closure a closure condition * @return a Set of matching values * @since 2.4.0 */ public static <T> Set<T> findAll(Set<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { return (Set<T>) findAll((Collection<T>) self, closure); }
/** * Finds all values matching the closure condition. * <pre class="groovyTestCase">assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }</pre> * * @param self a List * @param closure a closure condition * @return a List of matching values * @since 2.4.0 */ public static <T> List<T> findAll(List<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { return (List<T>) findAll((Collection<T>) self, closure); }
/** * Finds all items matching the closure condition. * * @param self an Object with an Iterator returning its values * @param closure a closure condition * @return a List of the values found * @since 1.6.0 */ public static Collection findAll(Object self, Closure closure) { List answer = new ArrayList(); Iterator iter = InvokerHelper.asIterator(self); return findAll(closure, answer, iter); }
/** * Finds all values matching the closure condition. * <pre class="groovyTestCase">assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }</pre> * * @param self a Collection * @param closure a closure condition * @return a Collection of matching values * @since 1.5.6 */ public static <T> Collection<T> findAll(Collection<T> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure closure) { Collection<T> answer = createSimilarCollection(self); Iterator<T> iter = self.iterator(); return findAll(closure, answer, iter); }
/** * Finds all elements of the array matching the given Closure condition. * <pre class="groovyTestCase"> * def items = [1,2,3,4] as Integer[] * assert [2,4] == items.findAll { it % 2 == 0 } * </pre> * * @param self an array * @param condition a closure condition * @return a list of matching values * @since 2.0 */ public static <T> Collection<T> findAll(T[] self, @ClosureParams(FirstParam.Component.class) Closure condition) { Collection<T> answer = new ArrayList<T>(); return findAll(condition, answer, new ArrayIterator<T>(self)); }
public void testFindAllAndCurry() { Map<String, Integer> expected = new HashMap<String, Integer>(zoo); expected.remove("Lions"); Closure<Boolean> keyBiggerThan = new Closure<Boolean>(null) { public Boolean doCall(Map.Entry<String, Integer> e, Integer size) { return e.getKey().length() > size; } }; Closure<Boolean> keyBiggerThan6 = keyBiggerThan.rcurry(6); assertEquals(expected, findAll(zoo, keyBiggerThan6)); }
/** * Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence. * * @param self a CharSequence * @param pattern the compiled regex Pattern * @return a List containing all full matches of the Pattern within the CharSequence, an empty list will be returned if there are no matches * @see #findAll(String, Pattern) * @since 1.8.2 */ public static List<CharSequence> findAll(CharSequence self, Pattern pattern) { return new ArrayList<CharSequence>(findAll(self.toString(), pattern)); }
/** * Returns a (possibly empty) list of all occurrences of a regular expression (in CharSequence format) found within a CharSequence. * * @param self a CharSequence * @param regex the capturing regex CharSequence * @return a List containing all full matches of the regex within the CharSequence, an empty list will be returned if there are no matches * @see #findAll(String, String) * @since 1.8.2 */ public static List<CharSequence> findAll(CharSequence self, CharSequence regex) { return new ArrayList<CharSequence>(findAll(self.toString(), regex.toString())); }
/** * Finds all values matching the closure condition. * * @param self a Collection * @param closure a closure condition * @return a Collection of matching values */ public static Collection findAll(Collection self, Closure closure) { Collection answer = createSimilarCollection(self); Iterator iter = self.iterator(); return findAll(closure, answer, iter); }
/** * Finds all items matching the closure condition. * * @param self an Object with an Iterator returning its values * @param closure a closure condition * @return a List of the values found */ public static Collection findAll(Object self, Closure closure) { List answer = new ArrayList(); Iterator iter = InvokerHelper.asIterator(self); return findAll(closure, answer, iter); }
public static<T extends Object >List<T> findAll(List<T> self, Closure closure) { if ((!Caller.isAsynchronous(self, "findAll", closure))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "findAll", self, closure))) { return DefaultGroovyMethods.findAll(self, closure); } return CpsDefaultGroovyMethods.$findAll__java_util_List__groovy_lang_Closure(self, closure); }
public static<K extends Object, V extends Object >Map<K, V> findAll(Map<K, V> self, Closure closure) { if ((!Caller.isAsynchronous(self, "findAll", closure))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "findAll", self, closure))) { return DefaultGroovyMethods.findAll(self, closure); } return CpsDefaultGroovyMethods.$findAll__java_util_Map__groovy_lang_Closure(self, closure); }
public static<T extends Object >Collection<T> findAll(T[] self, Closure condition) { if ((!Caller.isAsynchronous(self, "findAll", condition))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "findAll", self, condition))) { return DefaultGroovyMethods.findAll(self, condition); } return CpsDefaultGroovyMethods.$findAll__java_lang_Object_array__groovy_lang_Closure(self, condition); }
public static<T extends Object >Set<T> findAll(Set<T> self, Closure closure) { if ((!Caller.isAsynchronous(self, "findAll", closure))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "findAll", self, closure))) { return DefaultGroovyMethods.findAll(self, closure); } return CpsDefaultGroovyMethods.$findAll__java_util_Set__groovy_lang_Closure(self, closure); }
public static Collection findAll(Object self, Closure closure) { if ((!Caller.isAsynchronous(self, "findAll", closure))&&(!Caller.isAsynchronous(CpsDefaultGroovyMethods.class, "findAll", self, closure))) { return DefaultGroovyMethods.findAll(self, closure); } return CpsDefaultGroovyMethods.$findAll__java_lang_Object__groovy_lang_Closure(self, closure); }