0

I have an array which returns a set of events for the specific month. Some months can have different events on the same day. How do I detect duplicate dates and show both the events under the same date entries rather than two separate date entries.

Code:

public void setListView(int month, int year, int dv) {

        events = new HolidayEvents();
        _calendar = Calendar.getInstance(Locale.getDefault());
        int totalDays = _calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

        for(int i = 1; i <= totalDays; i++){
            if(isHoliday(i, month, year, dv))
            {
                date = i + " " + getMonthForInt(month-1) + " " + year;

                for (Event event : events.eventDetails(this, month, i) 
                {
                       summaries.add(new Summary(date, event.eventdetails));

                } 
            }
        }
}

Output:

11 January has two events. So it displays the result:

11 January 2013 
-Event Name-
11 January 2013
-Event Name-

I would like the output to show like this:

11 January 2013
-Event Name | Event Name-
2
  • 7
    What about a Map Date as keys and List<Event> as values? Commented Jan 6, 2013 at 18:53
  • @MrSmith42, can you show an example? Commented Jan 6, 2013 at 19:04

2 Answers 2

2

If you store your Events in in a structure like this:

Map<Date, List<Event>> eventMap= new HashMap<Date,List<Event>>();

you can get all event for a given date d like this:

List<Event> events = eventMap.get(d);
Sign up to request clarification or add additional context in comments.

Comments

0
ListMultiMap<Date,Event> eventMap = ArrayListMultiMap<Date,Event>.create();

Puts to the multimap will add the event to the list of events for that date. Getting with a date will return a list with all events for the date.

You can also do this manually with a regular map though it is a bit more cumbersome.

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ArrayListMultimap.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.