Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Water stream example code.
import java.util.ArrayList;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* Created by waleed on 12/03/2017.
*/
public class WaterStream {
public static void main(String[] args) {
Water water = new Water("water", 10, "big stone", 1, "small stone", 3);
water.stream()
.filter(BigStoneFilter)
.filter(SmallStoneFilter)
.map(convertWaterColour)
.forEach(s -> System.out.println(s));
}
private static Predicate<String> BigStoneFilter = s -> !s.equals("big stone");
private static Predicate<String> SmallStoneFilter = s -> !s.equals("small stone");
private static Function<String, String> convertWaterColour = s -> s + " black";
public static class Water extends ArrayList<String> {
public Water(String water, int litre, String s1, int bigStone, String s, int smallStone) {
super(litre + bigStone + smallStone);
for (int i = 0; i < litre; i++) {
add("water");
}
add(2, "big stone");
add(5, "small stone");
add(7, "small stone");
add(8, "small stone");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.