Coverage Report - net.objectlab.kit.datecalc.joda.LocalDateKitCalculatorsFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalDateKitCalculatorsFactory
100%
23/23
100%
12/12
2.75
 
 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: LocalDateKitCalculatorsFactory.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_UNLESS_MOVING_BACK;
 37  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.MODIFIED_FOLLOWING;
 38  
 import static net.objectlab.kit.datecalc.common.HolidayHandlerType.MODIFIED_PRECEDING;
 39  
 import net.objectlab.kit.datecalc.common.AbstractKitCalculatorsFactory;
 40  
 import net.objectlab.kit.datecalc.common.HolidayHandlerType;
 41  
 import net.objectlab.kit.datecalc.common.IMMDateCalculator;
 42  
 import net.objectlab.kit.datecalc.common.PeriodCountCalculator;
 43  
 
 44  
 import org.joda.time.LocalDate;
 45  
 
 46  
 /**
 47  
  * The default factory for getting Joda <code>LocalDate</code> based
 48  
  * calculators.
 49  
  * 
 50  
  * @author Benoit Xhenseval
 51  
  * @author $LastChangedBy: marchy $
 52  
  * @version $Revision: 271 $ $Date: 2009-03-17 13:50:59 -0400 (Tue, 17 Mar 2009) $
 53  
  * 
 54  
  */
 55  368
 public class LocalDateKitCalculatorsFactory extends AbstractKitCalculatorsFactory<LocalDate> {
 56  
 
 57  1
     private static final LocalDateKitCalculatorsFactory DEFAULT = new LocalDateKitCalculatorsFactory();
 58  
 
 59  1
     private static final PeriodCountCalculator<LocalDate> PCC = new LocalDatePeriodCountCalculator();
 60  
 
 61  1
     private static final IMMDateCalculator<LocalDate> IMMDC = new LocalDateIMMDateCalculator();
 62  
 
 63  
     public static LocalDateKitCalculatorsFactory getDefaultInstance() {
 64  417
         return DEFAULT;
 65  
     }
 66  
 
 67  
     // -----------------------------------------------------------------------
 68  
     //
 69  
     //    ObjectLab, world leaders in the design and development of bespoke 
 70  
     //          applications for the securities financing markets.
 71  
     //                         www.ObjectLab.co.uk
 72  
     //
 73  
     // -----------------------------------------------------------------------
 74  
 
 75  
     /**
 76  
      * Create a new DateCalculator for a given name and type of handling.
 77  
      * 
 78  
      * @param name
 79  
      *            calendar name (holidays set interested in). If there is set of
 80  
      *            holidays with that name, it will return a DateCalculator with
 81  
      *            an empty holiday set (will work on Weekend only).
 82  
      * @param holidayHandlerType
 83  
      *            typically one of the value of HolidayHandlerType
 84  
      * @return a new DateCalculator
 85  
      */
 86  
     public LocalDateCalculator getDateCalculator(final String name, final String holidayHandlerType) {
 87  367
         final LocalDateCalculator cal = new LocalDateCalculator();
 88  367
         cal.setName(name);
 89  367
         setHolidays(name, cal);
 90  
 
 91  367
         if (HolidayHandlerType.FORWARD.equals(holidayHandlerType)) {
 92  137
             cal.setHolidayHandler(new LocalDateForwardHandler());
 93  230
         } else if (BACKWARD.equals(holidayHandlerType)) {
 94  13
             cal.setHolidayHandler(new LocalDateBackwardHandler());
 95  217
         } else if (MODIFIED_FOLLOWING.equals(holidayHandlerType)) {
 96  97
             cal.setHolidayHandler(new LocalDateModifiedFollowingHandler());
 97  120
         } else if (MODIFIED_PRECEDING.equals(holidayHandlerType)) {
 98  13
             cal.setHolidayHandler(new LocalDateModifiedPrecedingHandler());
 99  107
         } else if (FORWARD_UNLESS_MOVING_BACK.equals(holidayHandlerType)) {
 100  96
             cal.setHolidayHandler(new LocalDateForwardUnlessNegativeHandler());
 101  11
         } else if (holidayHandlerType != null) {
 102  1
             throw new IllegalArgumentException("Unsupported HolidayHandler: " + holidayHandlerType);
 103  
         }
 104  366
         return cal;
 105  
     }
 106  
 
 107  
     public PeriodCountCalculator<LocalDate> getPeriodCountCalculator() {
 108  7
         return PCC;
 109  
     }
 110  
 
 111  
     public IMMDateCalculator<LocalDate> getIMMDateCalculator() {
 112  8
         return IMMDC;
 113  
     }
 114  
 }
 115  
 
 116  
 /*
 117  
  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
 118  
  * 
 119  
  * Based in London, we are world leaders in the design and development 
 120  
  * of bespoke applications for the securities financing markets.
 121  
  * 
 122  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
 123  
  *           ___  _     _           _   _          _
 124  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 125  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 126  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 127  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 128  
  *                   |__/
 129  
  *
 130  
  *                     www.ObjectLab.co.uk
 131  
  */