View Javadoc
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$
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.jdk;
34  
35  import java.util.Calendar;
36  import java.util.Date;
37  
38  import net.objectlab.kit.datecalc.common.BaseCalculator;
39  import net.objectlab.kit.datecalc.common.HolidayHandler;
40  import net.objectlab.kit.datecalc.common.NonWorkingDayChecker;
41  import net.objectlab.kit.datecalc.common.Utils;
42  
43  /**
44   * A Wrapper to handle any HolidayHandler&lt;Calendar&gt; types via a HolidayHandler&lt;Date&gt;
45   * delegate
46   *
47   * @author Marcin Jekot
48   *
49   */
50  public class HolidayHandlerDateWrapper implements HolidayHandler<Calendar> {
51  
52      private final HolidayHandler<Date> delegate;
53  
54      private final BaseCalculator<Date> calculator;
55  
56      public HolidayHandlerDateWrapper(final HolidayHandler<Date> holidayHandler, final BaseCalculator<Date> dateCalculator) {
57          delegate = holidayHandler;
58          calculator = dateCalculator;
59      }
60  
61      // -----------------------------------------------------------------------
62      //
63      // ObjectLab, world leaders in the design and development of bespoke
64      // applications for the securities financing markets.
65      // www.ObjectLab.co.uk
66      //
67      // -----------------------------------------------------------------------
68  
69      /**
70       * If the current date of the give calculator is a non-working day, it will
71       * be moved according to the algorithm implemented.
72       *
73       * @param calc
74       *            the calculator
75       * @return the date which may have moved.
76       */
77      public Calendar moveCurrentDate(final BaseCalculator<Calendar> calc) {
78          return adjustDate(calc.getCurrentBusinessDate(), 1, calc);
79      }
80  
81      public Calendar adjustDate(final Calendar startDate, final int increment, final NonWorkingDayChecker<Calendar> checker) {
82          Calendar ret = startDate;
83          if (delegate != null) {
84              final Date day = delegate.moveCurrentDate(calculator);
85              if (day != null) {
86                  ret = Utils.getCal(day);
87              }
88          }
89          return ret;
90      }
91  
92      /**
93       * Give the type name for this algorithm.
94       *
95       * @return algorithm name.
96       */
97      public String getType() {
98          return delegate.getType();
99      }
100 }
101 
102 /*
103  * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
104  *
105  * Based in London, we are world leaders in the design and development
106  * of bespoke applications for the securities financing markets.
107  *
108  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
109  *           ___  _     _           _   _          _
110  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
111  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
112  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
113  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
114  *                   |__/
115  *
116  *                     www.ObjectLab.co.uk
117  */