I'm looking for some advice on how to structure my collection for storing some images. Basically, I have 2 types of images, letters (Storing images of A - Z) and numbers (Storing 0 - 9). And each letter or number will have, say, 3 variations (all will have the same number of variatons). Now currently I have it set up that I have 3 folders, each with one variation of A- Z and 0 - 9. So I go through each folder, and store the letters and then the numbers in their own list. I then store each group of 3 lists in another list (So the 3 lists of letters in 1 list, and the other 3 lists of numbers in a second list). Lastly, I add these 2 lists to a Map using "lettter" and "numbers" as their key. I hope the code below will make it clearer:
private final static String[] dirs = { "/image_set_1", "/image_set_2", "/image_set_3" }; private final static String[] letters = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; private final static String[] numbers = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; public static Map<String, List<List<BufferedImage>>> loadTemplates() { final Map<String, List<List<BufferedImage>>> templates = new HashMap<>(); final List<List<BufferedImage>> letterTemplateSets = new LinkedList<>(); final List<List<BufferedImage>> numberTemplateSets = new LinkedList<>(); for(int x = 0; x < dirs.length; x++) { String directory = dirs[x]; // load letters List<BufferedImage> letterList = new LinkedList<>(); for(int i = 0; i < letters.length; i++) { String path = directory + "/" + letters[i] + ".jpg"; try { BufferedImage templateImage = ImageIO.read(ImageProcessor.class.getResource(path)); letterList.add(templateImage); } catch (IOException e) { e.printStackTrace(); } } letterTemplateSets.add(letterList); // load numbers List<BufferedImage> numberList = new LinkedList<>(); for(int i = 0; i < numbers.length; i++) { String path = directory + "/" + numbers[i] + ".jpg"; try { BufferedImage templateImage = ImageIO.read(ImageProcessor.class.getResource(path)); numberList.add(templateImage); } catch (IOException e) { e.printStackTrace(); } } numberTemplateSets.add(numberList); } templates.put("letters", letterTemplateSets); templates.put("numbers", numberTemplateSets); return templates; }
So at this point, I have a map of 2 lists, either letters or numbers, and each of those will have 3 lists, 1 for each folder.
Now my questions are this:
1. Have I gone overboard with a Map of list of list of images, or is it ok?
2. Any suggestions on a cleaner or more efficient way?
Thanks