Coverage Report - de.jollyday.parser.impl.RelativeToEasterSundayParser
 
Classes in this File Line Coverage Branch Coverage Complexity
RelativeToEasterSundayParser
92%
12/13
75%
3/4
2
 
 1  
 /**
 2  
  * Copyright 2011 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.config.HolidayType;
 23  
 import de.jollyday.config.Holidays;
 24  
 import de.jollyday.config.RelativeToEasterSunday;
 25  
 import de.jollyday.parser.AbstractHolidayParser;
 26  
 
 27  
 /**
 28  
  * This parser creates holidays relative to easter sunday.
 29  
  * 
 30  
  * @author Sven Diedrichsen
 31  
  * @version $Id: $
 32  
  */
 33  21
 public class RelativeToEasterSundayParser extends AbstractHolidayParser {
 34  
 
 35  
         /**
 36  
          * Properties prefix for christian holidays names.
 37  
          */
 38  
         private static final String PREFIX_PROPERTY_CHRISTIAN = "christian.";
 39  
 
 40  
         /**
 41  
          * {@inheritDoc}
 42  
          * 
 43  
          * Parses relative to easter sunday holidays.
 44  
          */
 45  
         @Override
 46  
         public void parse(int year, Set<Holiday> holidays, Holidays config) {
 47  3
                 for (RelativeToEasterSunday ch : config.getRelativeToEasterSunday()) {
 48  3
                         if (!isValid(ch, year)) {
 49  0
                                 continue;
 50  
                         }
 51  3
                         LocalDate easterSunday = getEasterSunday(year, ch.getChronology()).plusDays(ch.getDays());
 52  3
                         String propertiesKey = PREFIX_PROPERTY_CHRISTIAN + ch.getDescriptionPropertiesKey();
 53  3
                         addChristianHoliday(easterSunday, propertiesKey, ch.getLocalizedType(), holidays);
 54  3
                 }
 55  3
         }
 56  
 
 57  
         /**
 58  
          * Adds the given day to the list of holidays.
 59  
          * 
 60  
          * @param day
 61  
          *            a {@link LocalDate} object.
 62  
          * @param propertiesKey
 63  
          *            a {@link java.lang.String} object.
 64  
          * @param holidayType
 65  
          *            a {@link de.jollyday.config.HolidayType} object.
 66  
          * @param holidays
 67  
          *            a {@link java.util.Set} object.
 68  
          */
 69  
         protected void addChristianHoliday(LocalDate day, String propertiesKey, HolidayType holidayType,
 70  
                         Set<Holiday> holidays) {
 71  323
                 de.jollyday.HolidayType type = xmlUtil.getType(holidayType);
 72  323
                 Holiday h = new Holiday(day, propertiesKey, type);
 73  323
                 holidays.add(h);
 74  323
         }
 75  
 
 76  
 }