packagecom.xkzhangsan.time.calendar;importjava.time.LocalDateTime;importjava.time.YearMonth;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;importjava.util.concurrent.ConcurrentHashMap;importcom.xkzhangsan.time.calculator.DateTimeCalculatorUtil;importcom.xkzhangsan.time.formatter.DateTimeFormatterUtil;/*** 日历工具类
*
* @ClassName: CalendarUtil
* @Description: CalendarUtil
*@authorxkzhangsan
* @date 2020年03月18日*/
public classCalendarUtil {privateCalendarUtil() {
}/*** 生成指定年月的日历
*@paramyear
*@parammonth
*@return
*/
public static CalendarWrapper generateCalendar(int year, intmonth){
CalendarWrapper calendarWrapper= newCalendarWrapper();
Map dayMap = new ConcurrentHashMap();
List localDateTimeList =DateTimeCalculatorUtil.getLocalDateTimeList(YearMonth.of(year, month));if(localDateTimeList == null ||localDateTimeList.isEmpty()){returncalendarWrapper;
}
List dayWrapperList = new ArrayList<>();
localDateTimeList.stream().forEach(localDateTime->{
DayWrapper dayWrapper= newDayWrapper(localDateTime);
dayWrapperList.add(dayWrapper);
dayMap.put(DateTimeFormatterUtil.formatToDateStr(localDateTime), dayWrapper);
});
MonthWrapper monthWrapper= newMonthWrapper(month, dayWrapperList);
List monthWrapperList = new ArrayList<>();
monthWrapperList.add(monthWrapper);
YearWrapper yearWrapper= newYearWrapper(year, monthWrapperList);
List yearWrapperList = new ArrayList<>();
yearWrapperList.add(yearWrapper);
calendarWrapper= newCalendarWrapper(yearWrapperList, dayMap);returncalendarWrapper;
}/*** 生成指定年的日历
*@paramyear
*@return
*/
public static CalendarWrapper generateCalendar(intyear){
CalendarWrapper calendarWrapper= newCalendarWrapper();
Map dayMap = new ConcurrentHashMap();
List monthWrapperList = new ArrayList<>();for(int i=1; i<=12; i++){
List localDateTimeList =DateTimeCalculatorUtil.getLocalDateTimeList(YearMonth.of(year, i));if(localDateTimeList == null ||localDateTimeList.isEmpty()){continue;
}
List dayWrapperList = new ArrayList<>();
localDateTimeList.stream().forEach(localDateTime->{
DayWrapper dayWrapper= newDayWrapper(localDateTime);
dayWrapperList.add(dayWrapper);
dayMap.put(DateTimeFormatterUtil.formatToDateStr(localDateTime), dayWrapper);
});
MonthWrapper monthWrapper= newMonthWrapper(i, dayWrapperList);
monthWrapperList.add(monthWrapper);
}
List yearWrapperList = new ArrayList<>();
YearWrapper yearWrapper= newYearWrapper(year, monthWrapperList);
yearWrapperList.add(yearWrapper);
calendarWrapper= newCalendarWrapper(yearWrapperList, dayMap);returncalendarWrapper;
}
}