Coverage Report - de.jollyday.parser.impl.ChristianHolidayParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ChristianHolidayParser
97%
41/42
95%
19/20
23
ChristianHolidayParser$1
100%
1/1
N/A
23
 
 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.config.ChristianHoliday;
 23  
 import de.jollyday.config.Holidays;
 24  
 
 25  
 /**
 26  
  * This parser creates christian holidays for the given year relative to easter
 27  
  * sunday.
 28  
  *
 29  
  * @author Sven Diedrichsen
 30  
  * @version $Id: $
 31  
  */
 32  18
 public class ChristianHolidayParser extends RelativeToEasterSundayParser {
 33  
 
 34  
         /**
 35  
          * {@inheritDoc}
 36  
          *
 37  
          * Parses all christian holidays relative to eastern.
 38  
          */
 39  
         @Override
 40  
         public void parse(int year, Set<Holiday> holidays, final Holidays config) {
 41  132
                 for (ChristianHoliday ch : config.getChristianHoliday()) {
 42  329
                         if (!isValid(ch, year)) {
 43  9
                                 continue;
 44  
                         }
 45  320
                         LocalDate easterSunday = getEasterSunday(year, ch.getChronology());
 46  1
                         switch (ch.getType()) {
 47  
                         case EASTER:
 48  66
                                 break;
 49  
                         case CLEAN_MONDAY:
 50  
                         case SHROVE_MONDAY:
 51  1
                                 easterSunday = easterSunday.minusDays(48);
 52  1
                                 break;
 53  
                         case MARDI_GRAS:
 54  
                         case CARNIVAL:
 55  1
                                 easterSunday = easterSunday.minusDays(47);
 56  1
                                 break;
 57  
                         case ASH_WEDNESDAY:
 58  7
                                 easterSunday = easterSunday.minusDays(46);
 59  7
                                 break;
 60  
                         case MAUNDY_THURSDAY:
 61  17
                                 easterSunday = easterSunday.minusDays(3);
 62  17
                                 break;
 63  
                         case GOOD_FRIDAY:
 64  77
                                 easterSunday = easterSunday.minusDays(2);
 65  77
                                 break;
 66  
                         case EASTER_SATURDAY:
 67  1
                                 easterSunday = easterSunday.minusDays(1);
 68  1
                                 break;
 69  
                         case EASTER_MONDAY:
 70  56
                                 easterSunday = easterSunday.plusDays(1);
 71  56
                                 break;
 72  
                         case EASTER_TUESDAY:
 73  1
                                 easterSunday = easterSunday.plusDays(2);
 74  1
                                 break;
 75  
                         case GENERAL_PRAYER_DAY:
 76  1
                                 easterSunday = easterSunday.plusDays(26);
 77  1
                                 break;
 78  
                         case ASCENSION_DAY:
 79  29
                                 easterSunday = easterSunday.plusDays(39);
 80  29
                                 break;
 81  
                         case PENTECOST:
 82  
                         case WHIT_SUNDAY:
 83  20
                                 easterSunday = easterSunday.plusDays(49);
 84  20
                                 break;
 85  
                         case WHIT_MONDAY:
 86  
                         case PENTECOST_MONDAY:
 87  28
                                 easterSunday = easterSunday.plusDays(50);
 88  28
                                 break;
 89  
                         case CORPUS_CHRISTI:
 90  14
                                 easterSunday = easterSunday.plusDays(60);
 91  14
                                 break;
 92  
                         case SACRED_HEART:
 93  1
                                 easterSunday = easterSunday.plusDays(68);
 94  1
                                 break;
 95  
                         default:
 96  0
                                 throw new IllegalArgumentException(
 97  18
                                                 "Unknown christian holiday type " + ch.getType());
 98  
                         }
 99  320
             easterSunday = moveDate(ch, easterSunday);
 100  320
                         String propertiesKey = "christian." + ch.getType().name();
 101  320
                         addChristianHoliday(easterSunday, propertiesKey, ch.getLocalizedType(), holidays);
 102  320
                 }
 103  132
         }
 104  
 
 105  
 }