@Override public ImmutableHolidayCalendar build() { return new ImmutableHolidayCalendar( id, weekends, startYear, lookup); }
static ImmutableHolidayCalendar readExternal(DataInput in) throws IOException { String id = in.readUTF(); int weekendDays = in.readShort(); int startYear = in.readShort(); int lookupSize = in.readShort(); // this logic was found to be the fastest way to deserialize the int array byte[] bytes = new byte[lookupSize * 4]; int[] lookup = new int[lookupSize]; in.readFully(bytes); int offset = 0; for (int i = 0; i < lookupSize; i++) { lookup[i] = ((bytes[offset++] & 0xFF) << 24) | ((bytes[offset++] & 0xFF) << 16) | ((bytes[offset++] & 0xFF) << 8) | (bytes[offset++] & 0xFF); } return new ImmutableHolidayCalendar(HolidayCalendarId.of(id), weekendDays, startYear, lookup, false); }
static ImmutableHolidayCalendar of(HolidayCalendarId id, SortedSet<LocalDate> holidays, Set<DayOfWeek> weekendDays) { ArgChecker.notNull(id, "id"); ArgChecker.notNull(holidays, "holidays"); ArgChecker.notNull(weekendDays, "weekendDays"); int weekends = weekendDays.stream().mapToInt(dow -> 1 << (dow.getValue() - 1)).sum(); int startYear = 0; int[] lookup = new int[0]; if (holidays.isEmpty()) { // special case where no holiday dates are specified startYear = 0; lookup = new int[0]; } else { // normal case where holidays are specified startYear = holidays.first().getYear(); int endYearExclusive = holidays.last().getYear() + 1; lookup = buildLookupArray(holidays, weekendDays, startYear, endYearExclusive); } return new ImmutableHolidayCalendar(id, weekends, startYear, lookup); }
return new ImmutableHolidayCalendar(newId, newWeekends, newStartYear, newLookup, false);
@Override public Object build(Class<?> beanType, BeanBuilder<?> builder) { ConcurrentMap<MetaProperty<?>, Object> buffer = ((BufferingBeanBuilder<?>) builder).getBuffer(); HolidayCalendarId id = builder.get(ID); if (buffer.containsKey(HOLIDAYS) && buffer.containsKey(WEEKEND_DAYS)) { Set<LocalDate> holidays = builder.get(HOLIDAYS); Set<DayOfWeek> weekendDays = builder.get(WEEKEND_DAYS); return ImmutableHolidayCalendar.of(id, holidays, weekendDays); } else { int weekends = builder.get(WEEKENDS); int startYear = builder.get(START_YEAR); int[] lookup = builder.get(LOOKUP); return new ImmutableHolidayCalendar(id, weekends, startYear, lookup, false); } }