Coverage Report - net.objectlab.kit.datecalc.joda.LocalDateModifiedFollowingHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalDateModifiedFollowingHandler
100%
12/12
100%
4/4
1.667
 
 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: LocalDateModifiedFollowingHandler.java 298 2010-03-13 00:49:41Z benoitx $
 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 net.objectlab.kit.datecalc.common.DateCalculator;
 36  
 import net.objectlab.kit.datecalc.common.HolidayHandler;
 37  
 import net.objectlab.kit.datecalc.common.HolidayHandlerType;
 38  
 
 39  
 import org.joda.time.LocalDate;
 40  
 
 41  
 /**
 42  
  * A modified following handler will move the date forward if it falls on a non
 43  
  * working day BUT, if the new date falls into another month, it will revert to
 44  
  * moving backward until it finds a working day.
 45  
  * 
 46  
  * @author Benoit Xhenseval
 47  
  * @author $LastChangedBy: benoitx $
 48  
  * @version $Revision: 298 $ $Date: 2010-03-12 19:49:41 -0500 (Fri, 12 Mar 2010) $
 49  
  * 
 50  
  */
 51  878
 public class LocalDateModifiedFollowingHandler implements HolidayHandler<LocalDate> {
 52  
 
 53  
     /**
 54  
      * If the current date of the give calculator is a non-working day, it will
 55  
      * be moved according to the algorithm implemented.
 56  
      * 
 57  
      * @param calculator
 58  
      *            the calculator
 59  
      * @return the date which may have moved.
 60  
      */
 61  
     public LocalDate moveCurrentDate(final DateCalculator<LocalDate> calculator) {
 62  768
         return move(calculator, 1);
 63  
     }
 64  
 
 65  
     // -----------------------------------------------------------------------
 66  
     //
 67  
     //    ObjectLab, world leaders in the design and development of bespoke 
 68  
     //          applications for the securities financing markets.
 69  
     //                         www.ObjectLab.co.uk
 70  
     //
 71  
     // -----------------------------------------------------------------------
 72  
 
 73  
    protected LocalDate move(final DateCalculator<LocalDate> calculator, final int step) {
 74  846
         LocalDate date = calculator.getCurrentBusinessDate();
 75  846
         final int month = date.getMonthOfYear();
 76  846
         int stepToUse = step;
 77  1031
         while (calculator.isNonWorkingDay(date)) {
 78  185
             date = date.plusDays(stepToUse);
 79  185
             if (date.getMonthOfYear() != month) {
 80  
                 // flick to backward
 81  8
                 stepToUse *= -1;
 82  8
                 date = date.plusDays(stepToUse);
 83  
             }
 84  
         }
 85  846
         return date;
 86  
     }
 87  
 
 88  
     /**
 89  
      * Give the type name for this algorithm.
 90  
      * 
 91  
      * @return algorithm name.
 92  
      */
 93  
     public String getType() {
 94  125
         return HolidayHandlerType.MODIFIED_FOLLOWING;
 95  
     }
 96  
 }
 97  
 
 98  
 /*
 99  
  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
 100  
  * 
 101  
  * Based in London, we are world leaders in the design and development 
 102  
  * of bespoke applications for the securities financing markets.
 103  
  * 
 104  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
 105  
  *           ___  _     _           _   _          _
 106  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 107  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 108  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 109  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 110  
  *                   |__/
 111  
  *
 112  
  *                     www.ObjectLab.co.uk
 113  
  */