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.joda;
34
35 import net.objectlab.kit.datecalc.common.DateCalculator;
36 import net.objectlab.kit.datecalc.common.HolidayHandler;
37
38 import org.joda.time.LocalDate;
39 import org.joda.time.YearMonthDay;
40
41 /**
42 * A Wrapper to handle any HolidayHandler<LocalDate> types via a HolidayHandler<YearMonthDay>
43 * delegate
44 *
45 * @author Benoit Xhenseval
46 *
47 */
48 public class HolidayHandlerYearMonthDayWrapper implements HolidayHandler<LocalDate> {
49
50 private HolidayHandler<YearMonthDay> delegate;
51
52 private DateCalculator<YearMonthDay> calculator;
53
54 /**
55 * If the current date of the give calculator is a non-working day, it will
56 * be moved according to the algorithm implemented.
57 *
58 * @param calculator
59 * the calculator
60 */
61 public HolidayHandlerYearMonthDayWrapper(final HolidayHandler<YearMonthDay> delegate,
62 final DateCalculator<YearMonthDay> calculator) {
63 this.delegate = delegate;
64 this.calculator = calculator;
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 * (non-Javadoc)
77 *
78 * @see net.objectlab.kit.datecalc.common.HolidayHandler#getType()
79 */
80 public String getType() {
81 return delegate.getType();
82 }
83
84 /*
85 * (non-Javadoc)
86 *
87 * @see net.objectlab.kit.datecalc.common.HolidayHandler#moveCurrentDate(net.objectlab.kit.datecalc.common.DateCalculator)
88 */
89 public LocalDate moveCurrentDate(final DateCalculator<LocalDate> calc) {
90 LocalDate ret = calc.getCurrentBusinessDate();
91 if (delegate != null) {
92 final YearMonthDay day = delegate.moveCurrentDate(calculator);
93 if (day != null) {
94 ret = day.toLocalDate();
95 }
96 }
97 return ret;
98 }
99 }
100
101 /*
102 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
103 *
104 * Based in London, we are world leaders in the design and development
105 * of bespoke applications for the securities financing markets.
106 *
107 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
108 * ___ _ _ _ _ _
109 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
110 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
111 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
112 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
113 * |__/
114 *
115 * www.ObjectLab.co.uk
116 */