Skip to content

Commit 79d7313

Browse files
author
Eugen Paraschiv
committed
guava functional work
1 parent 3d0def7 commit 79d7313

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.baeldung.guava;
2+
3+
import static org.hamcrest.Matchers.lessThan;
4+
import static org.junit.Assert.assertThat;
5+
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
import org.junit.Test;
10+
11+
import com.google.common.base.Predicate;
12+
import com.google.common.collect.Collections2;
13+
import com.google.common.collect.Lists;
14+
15+
public class GuavaFunctionalExamplesTest {
16+
17+
// tests
18+
19+
// predicates
20+
21+
@Test
22+
public final void whenFilteringStringsAccordingToACondition_thenCorrectResults() {
23+
final List<Integer> randomNumbers = Lists.newArrayList(1, 2, 3, 6, 8, 10, 34, 57, 89);
24+
final Predicate<Integer> acceptEvenNumber = new Predicate<Integer>() {
25+
@Override
26+
public final boolean apply(final Integer number) {
27+
return (number % 2) == 0;
28+
}
29+
};
30+
final List<Integer> evenNumbers = Lists.newArrayList(Collections2.filter(randomNumbers, acceptEvenNumber));
31+
32+
final Integer found = Collections.binarySearch(evenNumbers, 57);
33+
assertThat(found, lessThan(0));
34+
}
35+
36+
}

0 commit comments

Comments
 (0)