Coverage Report - de.jollyday.parser.impl.RelativeToFixedParser
 
Classes in this File Line Coverage Branch Coverage Complexity
RelativeToFixedParser
100%
16/16
92%
13/14
8
 
 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.DayOfWeek;
 19  
 import java.time.LocalDate;
 20  
 import java.util.Set;
 21  
 
 22  
 import de.jollyday.Holiday;
 23  
 import de.jollyday.HolidayType;
 24  
 import de.jollyday.config.Holidays;
 25  
 import de.jollyday.config.RelativeToFixed;
 26  
 import de.jollyday.config.When;
 27  
 import de.jollyday.parser.AbstractHolidayParser;
 28  
 
 29  
 /**
 30  
  * The Class RelativeToFixedParser.
 31  
  * 
 32  
  * @author tboven
 33  
  * @version $Id: $
 34  
  */
 35  6
 public class RelativeToFixedParser extends AbstractHolidayParser {
 36  
 
 37  
         /*
 38  
          * (non-Javadoc)
 39  
          * 
 40  
          * @see de.jollyday.parser.HolidayParser#parse(int, java.util.Set,
 41  
          * de.jollyday.config.Holidays)
 42  
          */
 43  
         /** {@inheritDoc} */
 44  
         @Override
 45  
         public void parse(int year, Set<Holiday> holidays, final Holidays config) {
 46  12
                 for (RelativeToFixed rf : config.getRelativeToFixed()) {
 47  18
                         if (!isValid(rf, year)) {
 48  1
                                 continue;
 49  
                         }
 50  17
                         LocalDate fixed = calendarUtil.create(year, rf.getDate());
 51  17
                         if (rf.getWeekday() != null) {
 52  
                                 // if weekday is set -> move to weekday
 53  9
                                 DayOfWeek day = xmlUtil.getWeekday(rf.getWeekday());
 54  9
                                 int direction = (rf.getWhen() == When.BEFORE ? -1 : 1);
 55  53
                                 while (fixed.getDayOfWeek() != day){
 56  44
                                         fixed = fixed.plusDays(direction);
 57  
                                 }
 58  9
                         } else if (rf.getDays() != null) {
 59  
                                 // if number of days set -> move number of days
 60  8
                                 fixed = fixed.plusDays(rf.getWhen() == When.BEFORE ? -rf.getDays() : rf.getDays());
 61  
                         }
 62  17
                         HolidayType type = xmlUtil.getType(rf.getLocalizedType());
 63  17
                         holidays.add(new Holiday(fixed, rf.getDescriptionPropertiesKey(), type));
 64  17
                 }
 65  12
         }
 66  
 
 67  
 }