Consider the following class I have currently:
public interface Drawable { public void compileProgram(); public Program getProgram(); public int getDataSize(); public FloatBuffer putData(final FloatBuffer dataBuffer); public int getDataMode(); public static int countDataSize(final Collection<Drawable> drawables) { return drawables.stream().mapToInt((drawable) -> drawable.getDataSize()).sum(); } public static FloatBuffer putAllData(final List<Drawable> drawables) { FloatBuffer dataBuffer = BufferUtils.createFloatBuffer(countDataSize(drawables) * 3); drawables.stream().forEachOrdered((drawable) -> dataBuffer.put(drawable.putData(dataBuffer))); return (FloatBuffer)dataBuffer.clear(); } } Now take a look at countDataSize:
- I have as input
Collection<Drawable>, because I do not care about the order, I just want to sum up their size. - I use
drawables.stream(), which would be redundant if I would've passed in aStream<Drawable>argument.
And next take a look at putAllData:
- As in put here I have
List<Drawable> drawables, as the order this time does matter. - I use
drawables.stream()to access them, this happens in order withforEachOrdered().
I wush to use Stream<Drawable> as input, however does passing in a Collection<Drawable> or List<Drawable> even work then? If it does, how can I ensure that in the first case the order does not matter, while in the second case it does matter?
drawables.stream().mapToInt((drawable) -> drawable.getDataSize()).sum();can be writtendrawables.stream().mapToInt(Drawable::getDataSize).sum();