Coverage Report - de.jollyday.parser.impl.IslamicHolidayParser
 
Classes in this File Line Coverage Branch Coverage Complexity
IslamicHolidayParser
96%
31/32
87%
14/16
14
IslamicHolidayParser$1
100%
1/1
N/A
14
 
 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.IslamicHoliday;
 25  
 import de.jollyday.parser.AbstractHolidayParser;
 26  
 
 27  
 /**
 28  
  * This parser calculates gregorian dates for the different islamic holidays.
 29  
  * 
 30  
  * @author Sven Diedrichsen
 31  
  * @version $Id: $
 32  
  */
 33  3
 public class IslamicHolidayParser extends AbstractHolidayParser {
 34  
 
 35  
         /**
 36  
          * Properties prefix for islamic holidays.
 37  
          */
 38  
         private static final String PREFIX_PROPERTY_ISLAMIC = "islamic.";
 39  
 
 40  
         /*
 41  
          * (non-Javadoc)
 42  
          * 
 43  
          * @see de.jollyday.parser.HolidayParser#parse(int, java.util.Set,
 44  
          * de.jollyday.config.Holidays)
 45  
          */
 46  
         /** {@inheritDoc} */
 47  
         @Override
 48  
         public void parse(int year, Set<Holiday> holidays, final Holidays config) {
 49  4
                 for (IslamicHoliday i : config.getIslamicHoliday()) {
 50  12
                         if (!isValid(i, year)) {
 51  0
                                 continue;
 52  
                         }
 53  12
                         Set<LocalDate> islamicHolidays = null;
 54  1
                         switch (i.getType()) {
 55  
                         case NEWYEAR:
 56  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 1, 1);
 57  1
                                 break;
 58  
                         case ASCHURA:
 59  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 1, 10);
 60  1
                                 break;
 61  
                         case ID_AL_FITR:
 62  2
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 10, 1);
 63  2
                                 break;
 64  
                         case ID_UL_ADHA:
 65  3
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 12, 10);
 66  3
                                 break;
 67  
                         case LAILAT_AL_BARAT:
 68  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 8, 15);
 69  1
                                 break;
 70  
                         case LAILAT_AL_MIRAJ:
 71  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 7, 27);
 72  1
                                 break;
 73  
                         case LAILAT_AL_QADR:
 74  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 9, 27);
 75  1
                                 break;
 76  
                         case MAWLID_AN_NABI:
 77  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 3, 12);
 78  1
                                 break;
 79  
                         case RAMADAN:
 80  1
                                 islamicHolidays = calendarUtil.getIslamicHolidaysInGregorianYear(year, 9, 1);
 81  1
                                 break;
 82  
                         default:
 83  3
                                 throw new IllegalArgumentException("Unknown islamic holiday " + i.getType());
 84  
                         }
 85  12
                         String propertiesKey = PREFIX_PROPERTY_ISLAMIC + i.getType().name();
 86  12
                         HolidayType type = xmlUtil.getType(i.getLocalizedType());
 87  12
                         for (LocalDate d : islamicHolidays) {
 88  12
                                 holidays.add(new Holiday(d, propertiesKey, type));
 89  12
                         }
 90  12
                 }
 91  4
         }
 92  
 
 93  
 }