| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RelativeToWeekdayInMonthParser |
|
| 5.0;5 |
| 1 | /** | |
| 2 | * Copyright 2010 Sven Diedrichsen | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an | |
| 12 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | |
| 13 | * express or implied. See the License for the specific language | |
| 14 | * governing permissions and limitations under the License. | |
| 15 | */ | |
| 16 | package de.jollyday.parser.impl; | |
| 17 | ||
| 18 | import java.time.LocalDate; | |
| 19 | import java.util.Set; | |
| 20 | ||
| 21 | import de.jollyday.Holiday; | |
| 22 | import de.jollyday.HolidayType; | |
| 23 | import de.jollyday.config.Holidays; | |
| 24 | import de.jollyday.config.RelativeToWeekdayInMonth; | |
| 25 | import de.jollyday.config.When; | |
| 26 | ||
| 27 | /** | |
| 28 | * <p> | |
| 29 | * RelativeToWeekdayInMonthParser class. | |
| 30 | * </p> | |
| 31 | * | |
| 32 | * @author Sven | |
| 33 | * @version $Id: $ | |
| 34 | */ | |
| 35 | 5 | public class RelativeToWeekdayInMonthParser extends FixedWeekdayInMonthParser { |
| 36 | ||
| 37 | /* | |
| 38 | * (non-Javadoc) | |
| 39 | * | |
| 40 | * @see de.jollyday.parser.impl.FixedWeekdayInMonthParser#parse(int, | |
| 41 | * java.util.Set, de.jollyday.config.Holidays) | |
| 42 | */ | |
| 43 | /** {@inheritDoc} */ | |
| 44 | @Override | |
| 45 | public void parse(int year, Set<Holiday> holidays, final Holidays config) { | |
| 46 | 19 | for (RelativeToWeekdayInMonth rtfw : config.getRelativeToWeekdayInMonth()) { |
| 47 | 20 | if (!isValid(rtfw, year)) { |
| 48 | 1 | continue; |
| 49 | } | |
| 50 | 19 | LocalDate date = parse(year, rtfw.getFixedWeekday()); |
| 51 | 19 | int direction = (rtfw.getWhen() == When.BEFORE ? -1 : 1); |
| 52 | 63 | while (date.getDayOfWeek() != xmlUtil.getWeekday(rtfw.getWeekday())) { |
| 53 | 44 | date = date.plusDays(direction); |
| 54 | } | |
| 55 | 19 | HolidayType type = xmlUtil.getType(rtfw.getLocalizedType()); |
| 56 | 19 | holidays.add(new Holiday(date, rtfw.getDescriptionPropertiesKey(), type)); |
| 57 | 19 | } |
| 58 | 19 | } |
| 59 | ||
| 60 | } |