Created
August 7, 2018 04:04
-
-
Save siwonred/59d49b0b06c838a4e0d4e3297c4599f0 to your computer and use it in GitHub Desktop.
Stream Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import org.apache.commons.lang3.BooleanUtils; | |
public class Test { | |
private boolean push(int i) { | |
System.out.println(String.format("push message: %d", i)); | |
return i % 3 == 2; | |
} | |
public boolean run(int n) { | |
System.out.println(String.format("run for %d", n)); | |
ArrayList<Integer> list = new ArrayList<>(); | |
for (int i = 0; i < n; ++i) { | |
list.add(i); | |
} | |
return list.stream() | |
.map(this::push) | |
.filter(BooleanUtils::isTrue) | |
.findAny() | |
.orElse(false); | |
} | |
public static void main(String[] args) { | |
Test test = new Test(); | |
test.run(1); | |
test.run(3); | |
test.run(5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment