* minor fixes and cleaning duties
This commit is contained in:
committed by
José Carlos Valero Sánchez
parent
6b2fb615a7
commit
81027b7fbd
+1
-7
@@ -8,13 +8,7 @@ import org.apache.commons.collections4.Predicate;
|
||||
public class CollectionUtilsCollectionFilter {
|
||||
|
||||
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
|
||||
Predicate<Integer> apacheEventNumberPredicate = new Predicate<Integer>() {
|
||||
|
||||
@Override
|
||||
public boolean evaluate(Integer object) {
|
||||
return object % 2 == 0;
|
||||
}
|
||||
};
|
||||
Predicate<Integer> apacheEventNumberPredicate = item -> item % 2 == 0;
|
||||
|
||||
CollectionUtils.filter(baseCollection, apacheEventNumberPredicate);
|
||||
return baseCollection;
|
||||
|
||||
+1
-6
@@ -8,13 +8,8 @@ import com.google.common.collect.Collections2;
|
||||
public class GuavaCollectionFilter {
|
||||
|
||||
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
|
||||
Predicate<Integer> guavaPredicate = new Predicate<Integer>() {
|
||||
Predicate<Integer> guavaPredicate = item -> item % 2 == 0;
|
||||
|
||||
@Override
|
||||
public boolean apply(Integer input) {
|
||||
return input % 2 == 0;
|
||||
}
|
||||
};
|
||||
Collection<Integer> filteredCollection = Collections2.filter(baseCollection, guavaPredicate);
|
||||
return filteredCollection;
|
||||
}
|
||||
|
||||
+3
-14
@@ -16,22 +16,11 @@ public class StreamsCollectionFilter {
|
||||
return filterCollectionHelperMethod(baseCollection, item -> item % 2 == 0);
|
||||
}
|
||||
|
||||
static public Collection<Integer> findEvenNumbersUsingLambda(Collection<Integer> baseCollection) {
|
||||
return baseCollection.stream()
|
||||
.filter(item -> item % 2 == 0)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static public Collection<Integer> findEvenNumbersUsingPredicate(Collection<Integer> baseCollection) {
|
||||
Predicate<Integer> evenNumberPredicate = new Predicate<Integer>() {
|
||||
@Override
|
||||
public boolean test(Integer i) {
|
||||
return i % 2 == 0;
|
||||
}
|
||||
};
|
||||
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
|
||||
Predicate<Integer> streamsPredicate = item -> item % 2 == 0;
|
||||
|
||||
return baseCollection.stream()
|
||||
.filter(evenNumberPredicate)
|
||||
.filter(streamsPredicate)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user