/* package whatever; // don't place package name! */

import java.util.*;
import java.util.stream.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Box boxContainer = new BoxContainer(
				new Leaf("red","fresh"),
                new Leaf("white","dry"),
                new Leaf("black","dry"),
                new Leaf("green", "fresh"),
                new BoxContainer(
                		new Leaf("red","fresh"),
		                new Leaf("white","dry"),
		                new Leaf("black","dry"),
		                new Leaf("green", "fresh")));
                
        List<Leaf> leaves = boxContainer.leaves().collect(Collectors.toList());
        System.out.println(leaves);
	}
	
	interface Box {
		Stream<Leaf> leaves();
	}
	
	static class BoxContainer implements Box {
		final List<Box> allBoxes;
		
		BoxContainer(Box... boxes) {
			this.allBoxes = Arrays.asList(boxes);
		}
		
		@Override
		public Stream<Leaf> leaves() {
			return allBoxes.stream().flatMap(Box::leaves);
		}
	}
	
	static class Leaf implements Box {
		final String color;
		final String state;
		
		Leaf(String color, String state) {
			this.color = color;
			this.state = state;
		}
		
		@Override
		public Stream<Leaf> leaves() {
			return Stream.of(this);
		}
		
		@Override
		public String toString() {
			return "{color: " + color + ", state: " + state + "}";
		}
	}
}