Difference between revisions of "Any and All Assignment"
Jump to navigation
Jump to search
(→Any) |
|||
(One intermediate revision by the same user not shown) | |||
Line 24: | Line 24: | ||
public static <T> boolean all(Predicate<T> predicate, ImList<T> values) | public static <T> boolean all(Predicate<T> predicate, ImList<T> values) | ||
+ | |||
+ | = Clients = | ||
+ | == AllInRange == | ||
+ | <nowiki>private static boolean allInRange(int min, int maxExclusive, ImList<Integer> xs) { | ||
+ | return All.all((x) -> { | ||
+ | return min <= x && x < maxExclusive; | ||
+ | }, xs); | ||
+ | }</nowiki> | ||
+ | == AnyContains == | ||
+ | <nowiki>private static boolean anyContains(String target, ImList<String> texts) { | ||
+ | return Any.any((text) -> { | ||
+ | return text.contains(target); | ||
+ | }, texts); | ||
+ | } | ||
+ | </nowiki> | ||
=Test= | =Test= | ||
− | |||
{{TestSuite|AnyAndAllTestSuite|anyandall.group}} | {{TestSuite|AnyAndAllTestSuite|anyandall.group}} |
Latest revision as of 08:59, 9 February 2022
Contents
Group Warmup
Background
Code To Implement
Any
class: | Any.java | ![]() |
methods: | any any any |
|
package: | anyandall.group | |
source folder: | src/main/java |
public static boolean any(boolean... values)
public static boolean any(ImList<Boolean> values)
public static <T> boolean any(Predicate<T> predicate, ImList<T> values)
All
class: | All.java | ![]() |
methods: | all all all |
|
package: | anyandall.group | |
source folder: | src/main/java |
public static boolean all(boolean... values)
public static boolean all(ImList<Boolean> values)
public static <T> boolean all(Predicate<T> predicate, ImList<T> values)
Clients
AllInRange
private static boolean allInRange(int min, int maxExclusive, ImList<Integer> xs) { return All.all((x) -> { return min <= x && x < maxExclusive; }, xs); }
AnyContains
private static boolean anyContains(String target, ImList<String> texts) { return Any.any((text) -> { return text.contains(target); }, texts); }
Test
class: | AnyAndAllTestSuite.java | ![]() |
package: | anyandall.group | |
source folder: | src/test/java |