Coverage Report - net.objectlab.kit.datecalc.joda.YearMonthDayKitCalculatorsFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
YearMonthDayKitCalculatorsFactory
96%
24/25
92%
13/14
3.25
 
 1  
 /*
 2  
  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
 3  
  * 
 4  
  * Based in London, we are world leaders in the design and development 
 5  
  * of bespoke applications for the securities financing markets.
 6  
  * 
 7  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
 8  
  *           ___  _     _           _   _          _
 9  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 10  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 11  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 12  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 13  
  *                   |__/
 14  
  *
 15  
  *                     www.ObjectLab.co.uk
 16  
  *
 17  
  * $Id: YearMonthDayKitCalculatorsFactory.java 271 2009-03-17 17:50:59Z marchy $
 18  
  * 
 19  
  * Copyright 2006 the original author or authors.
 20  
  *
 21  
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 22  
  * use this file except in compliance with the License. You may obtain a copy of
 23  
  * the License at
 24  
  *
 25  
  * http://www.apache.org/licenses/LICENSE-2.0
 26  
  *
 27  
  * Unless required by applicable law or agreed to in writing, software
 28  
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 29  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 30  
  * License for the specific language governing permissions and limitations under
 31  
  * the License.
 32  
  */
 33  
 package net.objectlab.kit.datecalc.joda;
 34  
 
 35  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.BACKWARD;
 36  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.FORWARD;
 37  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK;
 38  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.MODIFIED_FOLLOWING;
 39  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.MODIFIED_PRECEDING;
 40  
 import net.objectlab.kit.datecalc.common.AbstractKitCalculatorsFactory;
 41  
 import net.objectlab.kit.datecalc.common.DateCalculator;
 42  
 import net.objectlab.kit.datecalc.common.IMMDateCalculator;
 43  
 import net.objectlab.kit.datecalc.common.KitCalculatorsFactory;
 44  
 import net.objectlab.kit.datecalc.common.PeriodCountCalculator;
 45  
 
 46  
 import org.joda.time.YearMonthDay;
 47  
 
 48  
 /**
 49  
  * The default factory for getting Joda <code>YearMonthDay</code> based
 50  
  * calculators.
 51  
  * 
 52  
  * @author Benoit Xhenseval
 53  
  * @author $LastChangedBy: marchy $
 54  
  * @version $Revision: 271 $ $Date: 2009-03-17 13:50:59 -0400 (Tue, 17 Mar 2009) $
 55  
  * 
 56  
  */
 57  1
 public class YearMonthDayKitCalculatorsFactory extends AbstractKitCalculatorsFactory<YearMonthDay> {
 58  
 
 59  1
     private static final KitCalculatorsFactory<YearMonthDay> DEFAULT = new YearMonthDayKitCalculatorsFactory();
 60  
 
 61  1
     private static final PeriodCountCalculator<YearMonthDay> PCC = new YearMonthDayPeriodCountCalculator();
 62  
 
 63  1
     private static final IMMDateCalculator<YearMonthDay> IMMDC = new YearMonthDayIMMDateCalculator();
 64  
 
 65  
     public static KitCalculatorsFactory<YearMonthDay> getDefaultInstance() {
 66  417
         return DEFAULT;
 67  
     }
 68  
 
 69  
     // -----------------------------------------------------------------------
 70  
     //
 71  
     //    ObjectLab, world leaders in the design and development of bespoke 
 72  
     //          applications for the securities financing markets.
 73  
     //                         www.ObjectLab.co.uk
 74  
     //
 75  
     // -----------------------------------------------------------------------
 76  
 
 77  
    /**
 78  
      * Create a new DateCalculator for a given name and type of handling.
 79  
      * 
 80  
      * @param name
 81  
      *            calendar name (holidays set interested in). If there is set of
 82  
      *            holidays with that name, it will return a DateCalculator with
 83  
      *            an empty holiday set (will work on Weekend only).
 84  
      * @param holidayHandlerType
 85  
      *            typically one of the value of HolidayHandlerType
 86  
      * @return a new DateCalculator
 87  
      * @throws IllegalArgumentException if name is null
 88  
      */
 89  
     public DateCalculator<YearMonthDay> getDateCalculator(final String name, final String holidayHandlerType) {
 90  367
         if (name == null) {
 91  0
             throw new IllegalArgumentException("name cannot be null, use anything.");
 92  
         }
 93  367
         final YearMonthDayDateCalculator cal = new YearMonthDayDateCalculator();
 94  367
         cal.setName(name);
 95  367
         setHolidays(name, cal);
 96  
 
 97  367
         if (FORWARD.equals(holidayHandlerType)) {
 98  137
             cal.setHolidayHandler(new YearMonthDayForwardHandler());
 99  230
         } else if (BACKWARD.equals(holidayHandlerType)) {
 100  13
             cal.setHolidayHandler(new YearMonthDayBackwardHandler());
 101  217
         } else if (MODIFIED_FOLLOWING.equals(holidayHandlerType)) {
 102  97
             cal.setHolidayHandler(new YearMonthDayModifiedFollowingHandler());
 103  120
         } else if (MODIFIED_PRECEDING.equals(holidayHandlerType)) {
 104  13
             cal.setHolidayHandler(new YearMonthDayModifiedPrecedingHandler());
 105  107
         } else if (FORWARD_UNLESS_MOVING_BACK.equals(holidayHandlerType)) {
 106  96
             cal.setHolidayHandler(new YearMonthDayForwardUnlessNegativeHandler());
 107  11
         } else if (holidayHandlerType != null) {
 108  1
             throw new IllegalArgumentException("Unsupported HolidayHandler: " + holidayHandlerType);
 109  
         }
 110  366
         return cal;
 111  
     }
 112  
 
 113  
     public PeriodCountCalculator<YearMonthDay> getPeriodCountCalculator() {
 114  7
         return PCC;
 115  
     }
 116  
 
 117  
     public IMMDateCalculator<YearMonthDay> getIMMDateCalculator() {
 118  8
         return IMMDC;
 119  
     }
 120  
 }
 121  
 
 122  
 /*
 123  
  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
 124  
  * 
 125  
  * Based in London, we are world leaders in the design and development 
 126  
  * of bespoke applications for the securities financing markets.
 127  
  * 
 128  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
 129  
  *           ___  _     _           _   _          _
 130  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 131  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 132  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 133  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 134  
  *                   |__/
 135  
  *
 136  
  *                     www.ObjectLab.co.uk
 137  
  */