001/*
002 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
003 *
004 * Based in London, we are world leaders in the design and development
005 * of bespoke applications for the securities financing markets.
006 *
007 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
008 *           ___  _     _           _   _          _
009 *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
010 *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
011 *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
012 *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
013 *                   |__/
014 *
015 *                     www.ObjectLab.co.uk
016 *
017 * $Id$
018 *
019 * Copyright 2006 the original author or authors.
020 *
021 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
022 * use this file except in compliance with the License. You may obtain a copy of
023 * the License at
024 *
025 * http://www.apache.org/licenses/LICENSE-2.0
026 *
027 * Unless required by applicable law or agreed to in writing, software
028 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
029 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
030 * License for the specific language governing permissions and limitations under
031 * the License.
032 */
033package net.objectlab.kit.datecalc.common;
034
035import java.io.Serializable;
036import java.util.Set;
037
038import net.objectlab.kit.datecalc.common.ccy.CurrencyCalculatorConfig;
039
040/**
041 * Factory will create new instances of calculators, these are lightweight, each
042 * thread should use the factory as a given calculator should NOT be shared
043 * across thread (unless you know what you're doing) as the startDate, current
044 * date and working week would be shared. Once created, the set of holidays will
045 * NOT change even if a new set is registered; one needs to get a new
046 * DateCalculator to get the new set.
047 *
048 * @author Benoit Xhenseval
049 *
050 * @param <E>
051 *            a representation of a date, typically JDK: Date, Calendar;
052 *            Joda:LocalDate, YearMonthDay
053 *
054 */
055public interface KitCalculatorsFactory<E extends Serializable> {
056
057    /**
058     * Create a new CurrencyDateCalculatorBuilder specialised for 2 currencies, including WorkingWeek, calendars registered and CurrencyCalculatorConfig.
059     *
060     * NOTE that USD currency holiday must also be registered.
061     *
062     * @param ccy1
063     *            first currency, will pickup the holiday set for this ccy.
064     * @param ccy2
065     *            second currency, will pick up the holiday set for this ccy.
066     * @param spotLag
067     *            the number of days between tradeDate and spotDate.
068     * @return a new CurrencyDateCalculatorBuilder
069     * @exception IllegalArgumentException
070     *                if the type is not null or a valid value.
071     * @since 1.4.0
072     */
073    CurrencyDateCalculatorBuilder<E> getDefaultCurrencyDateCalculatorBuilder(String ccy1, String ccy2, SpotLag spotLag);
074
075    CurrencyDateCalculator<E> buildCurrencyDateCalculator(CurrencyDateCalculatorBuilder<E> builder);
076
077    /**
078     * Create a new IMMUTABLE CurrencyDateCalculator specialised for 2 currencies, including WorkingWeek, calendars
079     * registered and CurrencyCalculatorConfig.
080     *
081     * NOTE that USD currency holiday must also be registered.
082     *
083     * @param ccy1
084     *            first currency, will pickup the holiday set for this ccy.
085     * @param ccy2
086     *            second currency, will pick up the holiday set for this ccy.
087     * @param spotLag
088     *            the number of days between tradeDate and spotDate.
089     * @return a new CurrencyDateCalculator
090     * @exception IllegalArgumentException
091     *                if the type is not null or a valid value.
092     * @since 1.4.0
093     */
094    CurrencyDateCalculator<E> getDefaultCurrencyDateCalculator(String ccy1, String ccy2, SpotLag spotLag);
095
096    /**
097     * Use this method register a specific currency config, if not provided then the DefaultCurrencyCalculatorConfig will be given.
098     * @param config that specifies the set of currencies subject to USD T+1.
099     */
100    void setCurrencyCalculatorConfig(CurrencyCalculatorConfig config);
101
102    CurrencyCalculatorConfig getCurrencyCalculatorConfig();
103
104    /**
105     * Create a new DateCalculator for a given name and type of handling.
106     *
107     * @param name
108     *            calendar name (holidays set interested in). If there is set of
109     *            holidays with that name, it will return a DateCalculator with
110     *            an empty holiday set (will work on Weekend only).
111     * @param holidayHandlerType
112     *            typically one of the value of HolidayHandlerType or null.
113     * @return a new DateCalculator
114     * @exception IllegalArgumentException
115     *                if the type is not null or a valid value.
116     */
117    DateCalculator<E> getDateCalculator(String name, String holidayHandlerType);
118
119    /**
120     * Use this method to register a holidays calendar.
121     *
122     * @param calendarName
123     *            the calendar name to register these holidays under.
124     * @param holidaysCalendar
125     *            the holiday calendar (non-working days with boundaries).
126     */
127    KitCalculatorsFactory<E> registerHolidays(String calendarName, HolidayCalendar<E> holidaysCalendar);
128
129    /**
130     * @return true if the holiday calendar name is registered.
131     */
132    boolean isHolidayCalendarRegistered(String calendarName);
133
134    /**
135     * @return an immutable Holiday Calendar name that is registered.
136     */
137    HolidayCalendar<E> getHolidayCalendar(String calendarName);
138
139    /**
140     * @return an immutable set of registered calendar names
141     */
142    Set<String> getRegisteredHolidayCalendarNames();
143
144    /**
145     * Unregister a given holiday calendar
146     * @param calendarName
147     *          the calendar name to unregister.
148     */
149    KitCalculatorsFactory<E> unregisterHolidayCalendar(String calendarName);
150
151    /**
152     * unregister all holiday calendars;
153     */
154    KitCalculatorsFactory<E> unregisterAllHolidayCalendars();
155
156    // -----------------------------------------------------------------------
157    //
158    // ObjectLab, world leaders in the design and development of bespoke
159    // applications for the securities financing markets.
160    // www.ObjectLab.co.uk
161    //
162    // -----------------------------------------------------------------------
163
164    /**
165     * Create a new PeriodCountCalculator.
166     *
167     * @return a PeriodCountCalculator
168     */
169    PeriodCountCalculator<E> getPeriodCountCalculator();
170
171    /**
172     * Create a new IMMDateCalculator.
173     *
174     * @return an IMMDateCalculator
175     */
176    IMMDateCalculator<E> getIMMDateCalculator();
177
178    /**
179     * Create a new holiday handler of given type
180     * @param holidayHandlerType
181     * @return a new handler
182     * @throws IllegalArgumentException if the holidayHandlerType is unsupported
183     * @since 1.4.0
184     */
185    HolidayHandler<E> getHolidayHandler(String holidayHandlerType);
186
187}
188
189/*
190 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
191 *
192 * Based in London, we are world leaders in the design and development
193 * of bespoke applications for the securities financing markets.
194 *
195 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
196 *           ___  _     _           _   _          _
197 *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
198 *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
199 *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
200 *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
201 *                   |__/
202 *
203 *                     www.ObjectLab.co.uk
204 */