List containing another list

java

Solution

What about using guava `Multimap` and an `enum` for `Customer`'s items:

public static enum Weekday { 
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}

public class Customer {
    private Multimap<WeekDay, String> items = ArrayListMultimap.create();
    // getters, setters etc
}

then:

// monday items:
customer.getItems().get(Weekday.MONDAY);

// week items:
customer.getItems().values();

Problem

I have an object in my application, Customer, that has a list of customers. ``` public class CustomerList { private List<Customer> } ``` The customer class in turn has a list of all the items they have shopped at a store on a given day of the week. ``` public class Customer { private List<String> itemsOnMonday; private List<String> itemsOnTuesday; private List<String> itemsOnWednesday; private List<String> itemsOnThursday; private List<String> itemsOnFriday; } ``` Now, I want to get the list of all the items the customer has shopped in a given week. What is the best way to do this? My colleague suggests I create another list, and add items to this list. I am not convinced this is a good approach. I have over 1000 customers, and each customer shops over 500 items/week. He suggests something like this - ``` for(Customer customer:customerList) { List<String> items = new ArrayList<String>(); items.addAll(itemsOnMonday); //So on until Friday. } ``` This is crazy, because I would end up creating over 1000 objects inside the for loop. Any thoughts on a better way to do this? We have been brain storming for a while now, and can't come up with an efficient implementation to achieve this. Any help will be much appreciated.

Original source