I created a function to create a colour map in java.
final void setDefaultColourMap() {
colourMap = new HashMap<>();
colourMap.put(0, Color.BLACK);
colourMap.put(1, Color.RED);
colourMap.put(2, Color.GREEN);
colourMap.put(3, Color.BLUE);
colourMap.put(4, Color.PINK);
colourMap.put(5, Color.YELLOW);
colourMap.put(6, Color.CYAN);
colourMap.put(7, Color.ORANGE);
colourMap.put(8, Color.MAGENTA);
colourMap.put(9, Color.DARK_GRAY);
colourMap.put(10, Color.WHITE);
colourMap.put(11, Color.GRAY);
colourMap.put(12, Color.LIGHT_GRAY);
}
I want to create a java stream, which when requested for a colour generates a new random number and returns a random color lazily.
Something like lazy lists.
Edit:
I have read that functional programming paradigm supports lazy lists. For example, there is a list for Fibonacci series, the list theoretically stores all the elements in the list, but practically, will generate the nth element when requested.
I want to simulate lazy color map with some logic. The color map I generated has input only for 13 colors. I don't want to manually enter values upto hundred or so.
I want to simulate a lazy color map. So, when I request for a color with key 35, the colorMap is formulated with some random colors upto 35 and the 35th value is returned.
I could basically return only 35 and store it but, ideally, if a 35 is access, in my extended program, you can assume that values upto 35 exist.