I could use some help with this method I'm trying to make. I have a Problem Object, which has a target date and i need to find out how many days this problem is late divided/split by months, compared to today's date.

Image this situation:
Lets say that today's date is **05-02-2013**.

```
ID  Target date
P1  02-02-2013
P2  27-01-2013
P3  26-01-2013
P4  05-12-2012

```

This means that each problem is this many days late in the following months:

```
    DEC JAN FEB
P1          3
P2      4   5
P3      5   5
P4  26  31  5

```

A problem can not be older than 12 months.

Now i need a method to sum these numbers storing the month name and a summed number of late days. If the target month and now month are the same, its an easy case, because i can just substract the days and store the month, but what to do when its not the case? I have the following code:

```
List<Problem> problems = problemQuery.getResultList(); //Problems list is already filtered and contain only late problems. 

Calendar now = Calendar.getInstance();
Calendar before = Calendar.getInstance();
Map<Integer, Integer> newMap = new TreeMap<Integer, Integer>(); //map that contains month number and daysLateCount

for (Problem p : problems) {
    before.setTime(p.getTarget_date());
    int nowMonth = now.get(Calendar.MONTH);
    int beforeMonth = before.get(Calendar.MONTH);
    if (beforeMonth == nowMonth) { //easy case when both dates have same month
        int result = now.get(Calendar.DAY_OF_MONTH) - before.get(Calendar.DAY_OF_MONTH);
        if (newMap.containsKey(nowMonth)) {
            int newLateDaysValue = newMap.get(nowMonth)+result; //get old result and add the new
            newMap.put(nowMonth, newLateDaysValue);
        }                   
        else {
            newMap.put(nowMonth, result);
        }
    }
    else {
                         //What to do here???
    }
}

```

Perhaps i could even skip the if-else clause and make an algorithm that could handle both cases? I don't know please help :)