froehli
froehli

Reputation: 944

Looking for adequate Data Structure (Collection, Map, LocalDateTime)

I want a data structure that contain the following:

The Timeslot needs to be connected to a boolean. The program needs to know if a timeslot is available. It will be used in a knapsack problem solving algorithm for work scheduling.

What I've got so far:

ArrayList<Map<List<LocalDateTime>, Boolean>>

But it looks pretty complicated and a Map might not be the best way to iterate through if I don't know the key. I tought about a ArrayList instead of a Map but I don't know how to initialize it with different Data Types.

Upvotes: 0

Views: 91

Answers (1)

Makoto
Makoto

Reputation: 106390

Table from Google Guava sounds like a perfect fit for this.

Table<LocalDateTime, LocalDateTime, Boolean> dateTable
                       = TreeBasedTable.create();

The reason for it is that it gives you access to row, column, and value (in parameter order), and will allow you to do relatively straightforward lookups.

An example: If you want to find all of the values for a given LocalDateTime row, then you would do this:

LocalDateTime today = LocalDateTime.of(2014, Month.JULY, 26, 0, 0);
// prints a map of all of today's values
System.out.println(dateTable.row(today)); 

Upvotes: 1

Related Questions