I'm implementing argument check in a method where one parameter is a List of LocalDate objects (from Joda-Time). I want to make sure that List contains at most one LocalDate per month. public List<LocalDate> generateAllDates(List<LocalDate> firstYearDates, ...) { }Thus, for exampleArrays.asList(    new LocalDate(2012, 3, 25),    new LocalDate(2012, 4, 30),    new LocalDate(2013, 3, 26))would be an illegal argument because there are two dates whose month is March.Currently I have something like this (making use of Guava's Multimap):Multimap<Integer, LocalDate> monthToDates = HashMultimap.create();for (LocalDate date : firstYearDates) {    monthToDates.put(date.getMonthOfYear(), date);}for (Integer i : monthToDates.keySet()) {    if (monthToDates.get(i).size() > 1) {        throw new IllegalArgumentException(            firstYearDates must contain at most one entry per month);    }}Question is, how would you simplify that? Using any API features of JDK 1.6, Guava or Joda-Time is fine.
At most one LocalDate per month in a list
java;guava;jodatime
Bit late but there is Guava built-in method for that - Maps.uniqueIndex - given:List<LocalDate> dates = Arrays.asList(     new LocalDate(2012,3,25), new LocalDate(2012,4,30), new LocalDate(2013,3,26);with JDK 8:Maps.uniqueIndex(dates, LocalDate::getMonthOfYear);or with JDK <7:Maps.uniqueIndex(dates, new Function<LocalDate, Integer>() {    @Override    public Integer apply(final LocalDate date) {      return date.getMonthOfYear();    }});It will throw java.lang.IllegalArgumentException: duplicate key: 3in this example.