Coverage Report - net.objectlab.kit.datecalc.joda.YearMonthDayModifiedFollowingHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
YearMonthDayModifiedFollowingHandler
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: YearMonthDayModifiedFollowingHandler.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.YearMonthDay;
 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  466
 public class YearMonthDayModifiedFollowingHandler implements HolidayHandler<YearMonthDay> {
 52  
 
 53  
     /**
 54  
      * Give the type name for this algorithm.
 55  
      * 
 56  
      * @return algorithm name.
 57  
      */
 58  
     public String getType() {
 59  125
         return HolidayHandlerType.MODIFIED_FOLLOWING;
 60  
     }
 61  
 
 62  
     /**
 63  
      * If the current date of the give calculator is a non-working day, it will
 64  
      * be moved according to the algorithm implemented.
 65  
      * 
 66  
      * @param calculator
 67  
      *            the calculator
 68  
      * @return the date which may have moved.
 69  
      */
 70  
     public YearMonthDay moveCurrentDate(final DateCalculator<YearMonthDay> calculator) {
 71  356
         return move(calculator, 1);
 72  
     }
 73  
 
 74  
     // -----------------------------------------------------------------------
 75  
     //
 76  
     //    ObjectLab, world leaders in the design and development of bespoke 
 77  
     //          applications for the securities financing markets.
 78  
     //                         www.ObjectLab.co.uk
 79  
     //
 80  
     // -----------------------------------------------------------------------
 81  
 
 82  
     protected YearMonthDay move(final DateCalculator<YearMonthDay> calculator, final int step) {
 83  410
         YearMonthDay date = calculator.getCurrentBusinessDate();
 84  410
         final int month = date.getMonthOfYear();
 85  410
         int stepToUse = step;
 86  595
         while (calculator.isNonWorkingDay(date)) {
 87  185
             date = date.plusDays(stepToUse);
 88  185
             if (date.getMonthOfYear() != month) {
 89  
                 // flick to backward
 90  8
                 stepToUse *= -1;
 91  8
                 date = date.plusDays(stepToUse);
 92  
             }
 93  
         }
 94  410
         return date;
 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  
  */