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 import java.util.List;
38 import java.util.stream.Collectors;
39
40 import net.objectlab.kit.datecalc.common.AbstractIMMDateCalculator;
41 import net.objectlab.kit.datecalc.common.IMMPeriod;
42 import net.objectlab.kit.datecalc.common.Utils;
43
44 /**
45 * Jdk <code>Date</code> based implementation of the
46 * {@link net.objectlab.kit.datecalc.common.IMMDateCalculator}. It simply
47 * delegates to the Calendar implementation.
48 *
49 * @author Marcin Jekot
50 *
51 */
52 public class DateIMMDateCalculator extends AbstractIMMDateCalculator<Date> {
53
54 private static final CalendarIMMDateCalculator DELEGATE = new CalendarIMMDateCalculator();
55
56 @Override
57 protected Date getNextIMMDate(final boolean requestNextIMM, final Date theStartDate, final IMMPeriod period) {
58 return DELEGATE.getNextIMMDate(requestNextIMM, Utils.getCal(theStartDate), period).getTime();
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 @Override
70 public List<Date> getIMMDates(final Date start, final Date end, final IMMPeriod period) {
71 return buildList(DELEGATE.getIMMDates(Utils.getCal(start), Utils.getCal(end), period));
72 }
73
74 @Override
75 public boolean isIMMDate(final Date date) {
76 return DELEGATE.isIMMDate(Utils.getCal(date));
77 }
78
79 private static List<Date> buildList(final List<Calendar> dates) {
80 return dates.stream().map(Calendar::getTime).collect(Collectors.toList());
81 }
82 }
83
84 /*
85 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
86 *
87 * Based in London, we are world leaders in the design and development
88 * of bespoke applications for the securities financing markets.
89 *
90 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
91 * ___ _ _ _ _ _
92 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
93 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
94 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
95 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
96 * |__/
97 *
98 * www.ObjectLab.co.uk
99 */