Coverage Report - de.jollyday.parser.impl.FixedWeekdayBetweenFixedParser
 
Classes in this File Line Coverage Branch Coverage Complexity
FixedWeekdayBetweenFixedParser
100%
17/17
80%
8/10
6
 
 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.FixedWeekdayBetweenFixed;
 24  
 import de.jollyday.config.Holidays;
 25  
 import de.jollyday.parser.AbstractHolidayParser;
 26  
 
 27  
 /**
 28  
  * Parses the configuration for fixed weekdays between two fixed dates.
 29  
  * 
 30  
  * @author Sven Diedrichsen
 31  
  * @version $Id: $
 32  
  */
 33  9
 public class FixedWeekdayBetweenFixedParser extends AbstractHolidayParser {
 34  
 
 35  
         /**
 36  
          * {@inheritDoc}
 37  
          * 
 38  
          * Parses the provided configuration and creates holidays for the provided
 39  
          * year.
 40  
          */
 41  
         @Override
 42  
         public void parse(int year, Set<Holiday> holidays, final Holidays config) {
 43  5
                 for (FixedWeekdayBetweenFixed fwm : config.getFixedWeekdayBetweenFixed()) {
 44  6
                         if (!isValid(fwm, year)) {
 45  1
                                 continue;
 46  
                         }
 47  5
                         LocalDate from = calendarUtil.create(year, fwm.getFrom());
 48  5
                         LocalDate to = calendarUtil.create(year, fwm.getTo());
 49  5
                         LocalDate result = null;
 50  28
                         for (; !from.isAfter(to);) {
 51  28
                                 if (from.getDayOfWeek() == xmlUtil.getWeekday(fwm.getWeekday())) {
 52  5
                                         result = from;
 53  5
                                         break;
 54  
                                 }
 55  23
                                 from = from.plusDays(1);
 56  
                         }
 57  5
                         if (result != null) {
 58  5
                                 HolidayType type = xmlUtil.getType(fwm.getLocalizedType());
 59  5
                                 holidays.add(new Holiday(result, fwm.getDescriptionPropertiesKey(), type));
 60  
                         }
 61  5
                 }
 62  5
         }
 63  
 
 64  
 }