* minor fixes and cleaning duties
This commit is contained in:
committed by
José Carlos Valero Sánchez
parent
6b2fb615a7
commit
81027b7fbd
@@ -39,12 +39,12 @@
|
||||
<dependency>
|
||||
<groupId>org.eclipse.collections</groupId>
|
||||
<artifactId>eclipse-collections-api</artifactId>
|
||||
<version>9.2.0</version>
|
||||
<version>${eclipse.collections.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.collections</groupId>
|
||||
<artifactId>eclipse-collections</artifactId>
|
||||
<version>9.2.0</version>
|
||||
<version>${eclipse.collections.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
@@ -67,5 +67,6 @@
|
||||
<collections-generic.version>4.01</collections-generic.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<eclipse.collections.version>9.2.0</eclipse.collections.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
+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());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -27,15 +27,13 @@ public class CollectionFiltersUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAnIntegerCollection_whenFilteringEvenValues_thenObtainTheFilteredCollectionForAllCases() {
|
||||
Collection<Integer> filteredWithStreams1 = StreamsCollectionFilter.findEvenNumbersUsingLambda(BASE_INTEGER_COLLECTION);
|
||||
Collection<Integer> filteredWithStreams2 = StreamsCollectionFilter.findEvenNumbersUsingPredicate(BASE_INTEGER_COLLECTION);
|
||||
Collection<Integer> filteredWithStreams1 = StreamsCollectionFilter.findEvenNumbers(BASE_INTEGER_COLLECTION);
|
||||
Collection<Integer> filteredWithCollectionUtils = CollectionUtilsCollectionFilter.findEvenNumbers(new ArrayList<>(BASE_INTEGER_COLLECTION));
|
||||
Collection<Integer> filteredWithEclipseCollections = EclipseCollectionsCollectionFilter.findEvenNumbers(BASE_INTEGER_COLLECTION);
|
||||
Collection<Integer> filteredWithEclipseCollectionsUsingIterate = EclipseCollectionsCollectionFilter.findEvenNumbersUsingIterate(BASE_INTEGER_COLLECTION);
|
||||
Collection<Integer> filteredWithGuava = GuavaCollectionFilter.findEvenNumbers(BASE_INTEGER_COLLECTION);
|
||||
|
||||
assertThat(filteredWithStreams1).hasSameElementsAs(filteredWithStreams2)
|
||||
.hasSameElementsAs(filteredWithCollectionUtils)
|
||||
assertThat(filteredWithStreams1).hasSameElementsAs(filteredWithCollectionUtils)
|
||||
.hasSameElementsAs(filteredWithEclipseCollections)
|
||||
.hasSameElementsAs(filteredWithEclipseCollectionsUsingIterate)
|
||||
.hasSameElementsAs(filteredWithEclipseCollectionsUsingIterate)
|
||||
|
||||
Reference in New Issue
Block a user