|
From: <be...@us...> - 2006-11-13 22:41:01
|
Revision: 220
http://svn.sourceforge.net/objectlabkit/?rev=220&view=rev
Author: benoitx
Date: 2006-11-13 14:39:54 -0800 (Mon, 13 Nov 2006)
Log Message:
-----------
Added new handler type ForwardUnlessNegative: a handler that acts like a Forward handler
if the increment is positive otherwise acts like a Backward handler
Modified Paths:
--------------
trunk/common-build/project.xml
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/HolidayHandlerType.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarDateCalculator.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarKitCalculatorsFactory.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateDateCalculator.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateKitCalculatorsFactory.java
trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardDateCalculatorTest.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateKitCalculatorsFactory.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayKitCalculatorsFactory.java
trunk/maven.xml
trunk/src/site/changes.xml
trunk/src/site/navigation.xml
Added Paths:
-----------
trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardUnlessNegativeCalculatorTest.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarForwardUnlessNegativeHandler.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateForwardUnlessNegativeHandler.java
trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkCalendarForwardUnlessNegativeCalculatorTest.java
trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardUnlessNegativeDateCalculatorTest.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateForwardUnlessNegativeHandler.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayForwardUnlessNegativeHandler.java
trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/LocalDateForwardUnlessNegativeDateCalculatorTest.java
trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/YearMonthDayForwardUnlessNegativeDateCalculatorTest.java
trunk/objectlab-statcvs.css
trunk/src/site/statsvn/
trunk/statsvn.bat
Modified: trunk/common-build/project.xml
===================================================================
--- trunk/common-build/project.xml 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/common-build/project.xml 2006-11-13 22:39:54 UTC (rev 220)
@@ -27,7 +27,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd">
<pomVersion>3</pomVersion>
<groupId>net.objectlab.kit.datecalc</groupId>
- <currentVersion>1.0.1</currentVersion>
+ <currentVersion>1.1.0</currentVersion>
<organization>
<name>ObjectLab Financial Ltd</name>
<url>http://www.objectlab.co.uk</url>
@@ -145,6 +145,11 @@
<versions>
<version>
+ <id>1.1.0</id>
+ <name>1.1.0</name>
+ <tag>v1.1.0</tag>
+ </version>
+ <version>
<id>1.0.1</id>
<name>1.0.1</name>
<tag>v1.0.1</tag>
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -65,6 +65,8 @@
private Set<E> nonWorkingDays;
private HolidayHandler<E> holidayHandler;
+
+ private int currentIncrement = 0;
protected AbstractDateCalculator(final String name, final Set<E> nonWorkingDays, final HolidayHandler<E> holidayHandler) {
this.name = name;
@@ -277,6 +279,20 @@
protected abstract DateCalculator<E> createNewCalculator(String calcName, E theStartDate, Set<E> holidays,
HolidayHandler<E> handler);
+
+ /**
+ * @return Returns the currentIncrement.
+ */
+ public int getCurrentIncrement() {
+ return currentIncrement;
+ }
+
+ /**
+ * @param currentIncrement The currentIncrement to set.
+ */
+ public void setCurrentIncrement(int currentIncrement) {
+ this.currentIncrement = currentIncrement;
+ }
}
/*
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -225,6 +225,20 @@
* @return the current DateCalculator
*/
DateCalculator<E> moveByTenor(final Tenor tenor, final int spotLag);
+
+ /**
+ * return the current increment in the calculator, this is used by the
+ * handler.
+ */
+ int getCurrentIncrement();
+
+ /**
+ * This would be used by delegate methods to detect if the increment
+ * if positive or negative (this will allow us to define a Handler
+ * that can act as Forward if positive and Backward if negative).
+ * @param increment
+ */
+ void setCurrentIncrement(final int increment);
}
/*
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/HolidayHandlerType.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/HolidayHandlerType.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/HolidayHandlerType.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -76,6 +76,12 @@
*/
public static final String MODIFIED_PRECEEDING = "modifiedPreceeding";
+ /**
+ * A handler that moves the date forward unless the increment is negative
+ * (eg moveByDays(-2)) in which case it behaves like a Backward handler.
+ */
+ public static final String FORWARD_UNLESS_MOVING_BACK = "forwardUnlessMovingBack";
+
private HolidayHandlerType() {
}
}
Added: trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardUnlessNegativeCalculatorTest.java
===================================================================
--- trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardUnlessNegativeCalculatorTest.java (rev 0)
+++ trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardUnlessNegativeCalculatorTest.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -0,0 +1,394 @@
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ *
+ * $Id: AbstractForwardDateCalculatorTest.java 200 2006-10-10 20:15:58Z benoitx $
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.common;
+
+import java.util.Calendar;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+public abstract class AbstractForwardUnlessNegativeCalculatorTest<E> extends AbstractDateTestCase<E> {
+
+ public void testSimpleForwardWithWeekend() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD);
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ final E startDate = newDate("2006-08-01");
+ cal.setStartDate(startDate);
+ checkDate("Move by 0 days", cal.moveByDays(0), "2006-08-01");
+ checkDate("Move by 1 days", cal.moveByDays(1), "2006-08-02");
+ checkDate("Move by 1 days", cal.moveByDays(-1), "2006-08-01");
+ checkDate("Move by 1 days", cal.moveByDays(1), "2006-08-02");
+ checkDate("Move by 1 more days", cal.moveByDays(1), "2006-08-03");
+ checkDate("Move by 1 more more days", cal.moveByDays(1), "2006-08-04");
+ checkDate("Move by 1 more more more days (across weekend)", cal.moveByDays(1), "2006-08-07");
+ }
+
+ public void testSimpleForwardStartDateWithWeekend() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ cal.setStartDate(newDate("2006-07-31")); // start date Monday
+ checkDate("start date Monday", cal, "2006-07-31");
+
+ cal.setStartDate(newDate("2006-08-01")); // start date Tuesday
+ checkDate("start date Tuesday", cal, "2006-08-01");
+
+ cal.setStartDate(newDate("2006-08-02")); // start date Wednesday
+ checkDate("start date Wednesday", cal, "2006-08-02");
+
+ cal.setStartDate(newDate("2006-08-03")); // start date Thursday
+ checkDate("start date Thursday", cal, "2006-08-03");
+
+ cal.setStartDate(newDate("2006-08-04")); // set on a Friday
+ checkDate("start date friday", cal, "2006-08-04");
+
+ cal.setStartDate(newDate("2006-08-05")); // set on a Saturday
+ checkDate("start date Saturday", cal, "2006-08-07");
+
+ cal.setStartDate(newDate("2006-08-06")); // set on a Sunday
+ checkDate("start date Sunday", cal, "2006-08-07");
+ }
+
+ public void testSimpleForwardStartDateNoWeekend() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(
+ true, Calendar.SUNDAY);
+ cal.setWorkingWeek(getWorkingWeek(ww));
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ cal.setStartDate(newDate("2006-07-31")); // start date Monday
+ checkDate("start date Monday", cal, "2006-07-31");
+
+ cal.setStartDate(newDate("2006-08-01")); // start date Tuesday
+ checkDate("start date Tuesday", cal, "2006-08-01");
+
+ cal.setStartDate(newDate("2006-08-02")); // start date Wednesday
+ checkDate("start date Wednesday", cal, "2006-08-02");
+
+ cal.setStartDate(newDate("2006-08-03")); // start date Thursday
+ checkDate("start date Thursday", cal, "2006-08-03");
+
+ cal.setStartDate(newDate("2006-08-04")); // set on a Friday
+ checkDate("start date friday", cal, "2006-08-04");
+
+ cal.setStartDate(newDate("2006-08-05")); // set on a Saturday
+ checkDate("start date Saturday", cal, "2006-08-05");
+
+ cal.setStartDate(newDate("2006-08-06")); // set on a Sunday
+ checkDate("start date Sunday", cal, "2006-08-06");
+ }
+
+ public void testSimpleForwardStartDateWhackyWeek() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ Calendar.THURSDAY).withWorkingDayFromCalendar(false, Calendar.FRIDAY).withWorkingDayFromCalendar(true,
+ Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
+ cal.setWorkingWeek(getWorkingWeek(ww));
+
+ cal.setStartDate(newDate("2006-07-31")); // start date Monday
+ checkDate("start date Monday", cal, "2006-08-01");
+
+ cal.setStartDate(newDate("2006-08-01")); // start date Tuesday
+ checkDate("start date Tuesday", cal, "2006-08-01");
+
+ cal.setStartDate(newDate("2006-08-02")); // start date Wednesday
+ checkDate("start date Wednesday", cal, "2006-08-03");
+
+ cal.setStartDate(newDate("2006-08-03")); // start date Thursday
+ checkDate("start date Thursday", cal, "2006-08-03");
+
+ cal.setStartDate(newDate("2006-08-04")); // set on a Friday
+ checkDate("start date friday", cal, "2006-08-05");
+
+ cal.setStartDate(newDate("2006-08-05")); // set on a Saturday
+ checkDate("start date Saturday", cal, "2006-08-05");
+
+ cal.setStartDate(newDate("2006-08-06")); // set on a Sunday
+ checkDate("start date Sunday", cal, "2006-08-08");
+ }
+
+ public void testSimpleForwardStartDateIdealWeekend() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ Calendar.THURSDAY).withWorkingDayFromCalendar(true, Calendar.FRIDAY).withWorkingDayFromCalendar(false,
+ Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
+ cal.setWorkingWeek(getWorkingWeek(ww));
+
+ cal.setStartDate(newDate("2006-07-31")); // start date Monday
+ checkDate("start date Monday", cal, "2006-08-01");
+
+ cal.setStartDate(newDate("2006-08-01")); // start date Tuesday
+ checkDate("start date Tuesday", cal, "2006-08-01");
+
+ cal.setStartDate(newDate("2006-08-02")); // start date Wednesday
+ checkDate("start date Wednesday", cal, "2006-08-02");
+
+ cal.setStartDate(newDate("2006-08-03")); // start date Thursday
+ checkDate("start date Thursday", cal, "2006-08-03");
+
+ cal.setStartDate(newDate("2006-08-04")); // set on a Friday
+ checkDate("start date friday", cal, "2006-08-04");
+
+ cal.setStartDate(newDate("2006-08-05")); // set on a Saturday
+ checkDate("start date Saturday", cal, "2006-08-08");
+
+ cal.setStartDate(newDate("2006-08-06")); // set on a Sunday
+ checkDate("start date Sunday", cal, "2006-08-08");
+ }
+
+ public void testSimpleForwardWithHolidays() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ final Set<E> holidays = newHolidaysSet();
+ Assert.assertEquals("Name", "bla", cal.getName());
+ cal.setNonWorkingDays(holidays);
+ Assert.assertEquals("Holidays", holidays, cal.getNonWorkingDays());
+ Assert.assertEquals("Holidays size", 3, cal.getNonWorkingDays().size());
+
+ Assert.assertTrue("contains", holidays.contains(newDate("2006-08-28")));
+ Assert.assertTrue("contains", cal.getNonWorkingDays().contains(newDate("2006-08-28")));
+
+ cal.setStartDate(newDate("2006-08-28"));
+ checkDate("Move given Bank Holiday", cal, "2006-08-29");
+
+ cal.setStartDate(newDate("2006-12-24"));
+ checkDate("Xmas Eve", cal, "2006-12-27");
+
+ cal.setStartDate(newDate("2006-12-21"));
+ checkDate("21/12 + 1", cal.moveByDays(1), "2006-12-22");
+
+ cal.setStartDate(newDate("2006-12-21"));
+ checkDate("21/12 + 1", cal.moveByDays(2), "2006-12-27");
+
+ cal.setStartDate(newDate("2006-12-22"));
+ checkDate("22/12 + 1", cal.moveByDays(1), "2006-12-27");
+
+ cal.setStartDate(newDate("2006-12-23"));
+ checkDate("23/12 + 1", cal.moveByDays(1), "2006-12-28");
+
+ cal.setStartDate(newDate("2006-12-27"));
+ checkDate("27/12 - 1", cal.moveByDays(-1), "2006-12-22");
+ }
+
+ // -----------------------------------------------------------------------
+ //
+ // ObjectLab, world leaders in the design and development of bespoke
+ // applications for the securities financing markets.
+ // www.ObjectLab.co.uk
+ //
+ // -----------------------------------------------------------------------
+
+ public void testMoveByBusinessDays() {
+ final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ final Set<E> holidays = newHolidaysSet();
+ Assert.assertEquals("Name", "bla", cal.getName());
+ cal.setNonWorkingDays(holidays);
+ Assert.assertEquals("Holidays", holidays, cal.getNonWorkingDays());
+ Assert.assertEquals("Holidays size", 3, cal.getNonWorkingDays().size());
+
+ cal.setStartDate(newDate("2006-08-24"));
+ checkDate("Move 1 BD", cal.moveByBusinessDays(1), "2006-08-25");
+
+ cal.setStartDate(newDate("2006-08-24"));
+ checkDate("Add 1 week", cal.moveByDays(7), "2006-08-31");
+ cal.setStartDate(newDate("2006-08-24"));
+ checkDate("Move by 1W with 1 bank holiday", cal.moveByBusinessDays(7), "2006-09-05");
+ }
+
+ public void testMoveByTenorDays() {
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1D, 0, "2006-08-09", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.DAY), 0, "2006-08-10", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(10, TenorCode.DAY), 0, "2006-08-18", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(11, TenorCode.DAY), 0, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(12, TenorCode.DAY), 0, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(13, TenorCode.DAY), 0, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-09-26", new Tenor(4, TenorCode.DAY), 0, "2006-10-02", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorDaysOneDayToSpot() {
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1D, 1, "2006-08-10", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.DAY), 1, "2006-08-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(10, TenorCode.DAY), 1, "2006-08-18", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(11, TenorCode.DAY), 1, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(12, TenorCode.DAY), 1, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(13, TenorCode.DAY), 1, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorDaysTwoDaysToSpot() {
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1D, 2, "2006-08-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.DAY), 2, "2006-08-14", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(10, TenorCode.DAY), 2, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(11, TenorCode.DAY), 2, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(12, TenorCode.DAY), 2, "2006-08-21", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-07", new Tenor(13, TenorCode.DAY), 2, "2006-08-22", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorWeek() {
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1W, 0, "2006-08-15", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.WEEK), 0, "2006-08-22", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(4, TenorCode.WEEK), 0, "2006-09-05", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorWeekOneDayToSpot() {
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1W, 1, "2006-08-16", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.WEEK), 1, "2006-08-23", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(4, TenorCode.WEEK), 1, "2006-09-06", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorWeekTwoDaysToSpot() {
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1W, 2, "2006-08-17", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.WEEK), 2, "2006-08-24", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(4, TenorCode.WEEK), 2, "2006-09-07", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorMonth() {
+ checkMoveByTenor("2006-08-31", StandardTenor.T_1M, 0, "2006-10-02", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.T_2M, 0, "2006-10-31", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-01-31", StandardTenor.T_1M, 0, "2006-02-28", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-01-31", StandardTenor.T_1M, 0, "2008-02-29", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1M, 0, "2006-09-08", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-09", StandardTenor.T_1M, 0, "2006-09-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.MONTH), 0, "2006-10-09", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(5, TenorCode.MONTH), 0, "2007-01-08", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorMonthOneDayToSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.T_1M, 1, "2006-10-02", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.T_2M, 1, "2006-11-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-01-31", StandardTenor.T_1M, 1, "2006-03-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-01-31", StandardTenor.T_1M, 1, "2008-03-03", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1M, 1, "2006-09-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-09", StandardTenor.T_1M, 1, "2006-09-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.MONTH), 1, "2006-10-09", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(5, TenorCode.MONTH), 1, "2007-01-09", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorMonthTwoDaysToSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.T_1M, 2, "2006-10-04", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.T_2M, 2, "2006-11-06", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-01-31", StandardTenor.T_1M, 2, "2006-03-02", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-01-31", StandardTenor.T_1M, 2, "2008-03-04", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+
+ checkMoveByTenor("2006-08-08", StandardTenor.T_1M, 2, "2006-09-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-09", StandardTenor.T_1M, 2, "2006-09-11", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(2, TenorCode.MONTH), 2, "2006-10-10", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-08", new Tenor(5, TenorCode.MONTH), 2, "2007-01-10", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorYear() {
+ checkMoveByTenor("2006-08-31", StandardTenor.T_1Y, 0, "2007-08-31", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.T_2Y, 0, "2008-09-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-02-29", StandardTenor.T_1Y, 0, "2009-03-02", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-02-29", StandardTenor.T_4Y, 0, "2012-02-29", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorYearOneDayToSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.T_1Y, 1, "2007-09-03", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.T_2Y, 1, "2008-09-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-02-29", StandardTenor.T_1Y, 1, "2009-03-03", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-02-29", StandardTenor.T_4Y, 1, "2012-03-05", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorYearTwoDaysToSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.T_1Y, 2, "2007-09-04", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.T_2Y, 2, "2008-09-04", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-02-29", StandardTenor.T_1Y, 2, "2009-03-03", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2008-02-29", StandardTenor.T_4Y, 2, "2012-03-05", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.SPOT, 0, "2006-08-31", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-28", StandardTenor.SPOT, 0, "2006-08-29", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorSpotOneDayToSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.SPOT, 1, "2006-09-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-28", StandardTenor.SPOT, 1, "2006-08-30", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorSpotTwoDaysToSpot() {
+ checkMoveByTenor("2006-08-31", StandardTenor.SPOT, 2, "2006-09-04", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-28", StandardTenor.SPOT, 2, "2006-08-31", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorOvernight() {
+ checkMoveByTenor("2006-08-24", StandardTenor.OVERNIGHT, 0, "2006-08-25", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-25", StandardTenor.OVERNIGHT, 0, "2006-08-29", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.OVERNIGHT, 0, "2006-09-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-28", StandardTenor.OVERNIGHT, 0, "2006-08-30", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorOvernightOneDayToSpot() {
+ checkMoveByTenor("2006-08-24", StandardTenor.OVERNIGHT, 1, "2006-08-25", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-25", StandardTenor.OVERNIGHT, 1, "2006-08-29", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.OVERNIGHT, 1, "2006-09-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-28", StandardTenor.OVERNIGHT, 1, "2006-08-30", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+
+ public void testMoveByTenorOvernightTwoDaysToSpot() {
+ checkMoveByTenor("2006-08-24", StandardTenor.OVERNIGHT, 2, "2006-08-25", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-25", StandardTenor.OVERNIGHT, 2, "2006-08-29", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-31", StandardTenor.OVERNIGHT, 2, "2006-09-01", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ checkMoveByTenor("2006-08-28", StandardTenor.OVERNIGHT, 2, "2006-08-30", HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK);
+ }
+}
+
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarDateCalculator.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarDateCalculator.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarDateCalculator.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -84,13 +84,14 @@
// -----------------------------------------------------------------------
//
- // ObjectLab, world leaders in the design and development of bespoke
- // applications for the securities financing markets.
- // www.ObjectLab.co.uk
+ // ObjectLab, world leaders in the design and development of bespoke
+ // applications for the securities financing markets.
+ // www.ObjectLab.co.uk
//
// -----------------------------------------------------------------------
- public CalendarDateCalculator moveByDays(final int days) {
+ public CalendarDateCalculator moveByDays(final int days) {
+ setCurrentIncrement(days);
getCurrentBusinessDate().add(Calendar.DAY_OF_MONTH, days);
if (getHolidayHandler() != null) {
@@ -102,10 +103,11 @@
@Override
public DateCalculator<Calendar> moveByMonths(final int months) {
- final Calendar date = getCurrentBusinessDate();
- date.add(Calendar.MONTH,months);
+ setCurrentIncrement(months);
+ final Calendar date = getCurrentBusinessDate();
+ date.add(Calendar.MONTH, months);
- setCurrentBusinessDate(date);
+ setCurrentBusinessDate(date);
if (getHolidayHandler() != null) {
setCurrentBusinessDate(getHolidayHandler().moveCurrentDate(this));
Added: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarForwardUnlessNegativeHandler.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarForwardUnlessNegativeHandler.java (rev 0)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarForwardUnlessNegativeHandler.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -0,0 +1,111 @@
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ *
+ * $Id: CalendarForwardHandler.java 203 2006-10-11 12:53:07Z benoitx $
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.jdk;
+
+import java.util.Calendar;
+
+import net.objectlab.kit.datecalc.common.DateCalculator;
+import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.HolidayHandlerType;
+
+/**
+ * A Jdk <code>Calendar</code> implementation of the
+ * {@link net.objectlab.kit.datecalc.common.HolidayHandler}, for the
+ * <strong>Forward</strong> algorithm.
+ *
+ * @author Marcin Jekot
+ * @author $LastChangedBy: benoitx $
+ * @version $Revision: 203 $ $Date: 2006-10-11 13:53:07 +0100 (Wed, 11 Oct 2006) $
+ */
+public class CalendarForwardUnlessNegativeHandler implements HolidayHandler<Calendar> {
+
+ /**
+ * If the current date of the give calculator is a non-working day, it will
+ * be moved according to the algorithm implemented.
+ *
+ * @param calculator
+ * the calculator
+ * @return the date which may have moved.
+ */
+ public Calendar moveCurrentDate(final DateCalculator<Calendar> calculator) {
+ return move(calculator, 1);
+ }
+
+ // -----------------------------------------------------------------------
+ //
+ // ObjectLab, world leaders in the design and development of bespoke
+ // applications for the securities financing markets.
+ // www.ObjectLab.co.uk
+ //
+ // -----------------------------------------------------------------------
+
+ protected Calendar move(final DateCalculator<Calendar> calculator, final int step) {
+ final Calendar cal = (Calendar) calculator.getCurrentBusinessDate().clone();
+
+ while (calculator.isNonWorkingDay(cal)) {
+ if (calculator.getCurrentIncrement() < 0) {
+ cal.add(Calendar.DAY_OF_MONTH, -step);
+ } else {
+ cal.add(Calendar.DAY_OF_MONTH, step);
+ }
+ }
+
+ return cal;
+ }
+
+ /**
+ * Give the type name for this algorithm.
+ *
+ * @return algorithm name.
+ */
+ public String getType() {
+ return HolidayHandlerType.FORWARD;
+ }
+}
+
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarKitCalculatorsFactory.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarKitCalculatorsFactory.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarKitCalculatorsFactory.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -89,6 +89,8 @@
cal.setHolidayHandler(new CalendarModifiedFollowingHandler());
} else if (HolidayHandlerType.MODIFIED_PRECEEDING.equals(holidayHandlerType)) {
cal.setHolidayHandler(new CalendarModifiedPreceedingHandler());
+ } else if (HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK.equals(holidayHandlerType)) {
+ cal.setHolidayHandler(new CalendarForwardUnlessNegativeHandler());
} else {
throw new IllegalArgumentException("Unsupported HolidayHandler: " + holidayHandlerType);
}
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateDateCalculator.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateDateCalculator.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateDateCalculator.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -101,6 +101,8 @@
}
public DateCalculator<Date> moveByDays(final int days) {
+ setCurrentIncrement(days);
+ delegate.setCurrentIncrement(days);
delegate.setCurrentBusinessDate(Utils.getCal(getCurrentBusinessDate()));
setCurrentBusinessDate(delegate.moveByDays(days).getCurrentBusinessDate().getTime());
return this;
@@ -127,6 +129,8 @@
@Override
protected DateCalculator<Date> moveByMonths(final int months) {
+ setCurrentIncrement(months);
+ delegate.setCurrentIncrement(months);
delegate.setCurrentBusinessDate(Utils.getCal(getCurrentBusinessDate()));
setCurrentBusinessDate(delegate.moveByMonths(months).getCurrentBusinessDate().getTime());
return this;
Added: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateForwardUnlessNegativeHandler.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateForwardUnlessNegativeHandler.java (rev 0)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateForwardUnlessNegativeHandler.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -0,0 +1,114 @@
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ *
+ * $Id: DateForwardHandler.java 203 2006-10-11 12:53:07Z benoitx $
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.jdk;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import net.objectlab.kit.datecalc.common.DateCalculator;
+import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.HolidayHandlerType;
+import net.objectlab.kit.datecalc.common.Utils;
+
+/**
+ * A Jdk <code>Date</code> implementation of the
+ * {@link net.objectlab.kit.datecalc.common.HolidayHandler}, for the
+ * <strong>Forward</strong> algorithm.
+ *
+ * @author Marcin Jekot
+ * @author $LastChangedBy: benoitx $
+ * @version $Revision: 203 $ $Date: 2006-10-11 13:53:07 +0100 (Wed, 11 Oct 2006) $
+ *
+ */
+public class DateForwardUnlessNegativeHandler implements HolidayHandler<Date> {
+
+ /**
+ * If the current date of the give calculator is a non-working day, it will
+ * be moved according to the algorithm implemented.
+ *
+ * @param calculator
+ * the calculator
+ * @return the date which may have moved.
+ */
+ public Date moveCurrentDate(final DateCalculator<Date> calculator) {
+ return move(calculator, 1);
+ }
+
+ // -----------------------------------------------------------------------
+ //
+ // ObjectLab, world leaders in the design and development of bespoke
+ // applications for the securities financing markets.
+ // www.ObjectLab.co.uk
+ //
+ // -----------------------------------------------------------------------
+
+ protected Date move(final DateCalculator<Date> calculator, final int step) {
+ final Calendar cal = Utils.getCal(calculator.getCurrentBusinessDate());
+
+ while (calculator.isNonWorkingDay(cal.getTime())) {
+ if (calculator.getCurrentIncrement() < 0) {
+ cal.add(Calendar.DAY_OF_MONTH, -step);
+ } else {
+ cal.add(Calendar.DAY_OF_MONTH, step);
+ }
+ }
+
+ return cal.getTime();
+ }
+
+ /**
+ * Give the type name for this algorithm.
+ *
+ * @return algorithm name.
+ */
+ public String getType() {
+ return HolidayHandlerType.FORWARD;
+ }
+}
+
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateKitCalculatorsFactory.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateKitCalculatorsFactory.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateKitCalculatorsFactory.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -89,6 +89,8 @@
cal.setHolidayHandler(new DateModifiedFollowingHandler());
} else if (HolidayHandlerType.MODIFIED_PRECEEDING.equals(holidayHandlerType)) {
cal.setHolidayHandler(new DateModifiedPreceedingHandler());
+ } else if (HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK.equals(holidayHandlerType)) {
+ cal.setHolidayHandler(new DateForwardUnlessNegativeHandler());
} else {
throw new IllegalArgumentException("Unsupported HolidayHandler: " + holidayHandlerType);
}
Added: trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkCalendarForwardUnlessNegativeCalculatorTest.java
===================================================================
--- trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkCalendarForwardUnlessNegativeCalculatorTest.java (rev 0)
+++ trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkCalendarForwardUnlessNegativeCalculatorTest.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -0,0 +1,70 @@
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ *
+ * $Id: JdkCalendarForwardDateCalculatorTest.java 203 2006-10-11 12:53:07Z benoitx $
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.jdk;
+
+import java.util.Calendar;
+
+import net.objectlab.kit.datecalc.common.AbstractForwardUnlessNegativeCalculatorTest;
+import net.objectlab.kit.datecalc.common.KitCalculatorsFactory;
+import net.objectlab.kit.datecalc.common.Utils;
+
+public class JdkCalendarForwardUnlessNegativeCalculatorTest extends AbstractForwardUnlessNegativeCalculatorTest<Calendar> {
+
+ @Override
+ protected Calendar newDate(final String date) {
+ return Utils.createCalendar(date);
+ }
+
+ @Override
+ protected KitCalculatorsFactory<Calendar> getDateCalculatorFactory() {
+ return CalendarKitCalculatorsFactory.getDefaultInstance();
+ }
+
+}
+
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
Modified: trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardDateCalculatorTest.java
===================================================================
--- trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardDateCalculatorTest.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardDateCalculatorTest.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -33,10 +33,11 @@
package net.objectlab.kit.datecalc.jdk;
import net.objectlab.kit.datecalc.common.AbstractForwardDateCalculatorTest;
+import net.objectlab.kit.datecalc.common.AbstractForwardUnlessNegativeCalculatorTest;
import net.objectlab.kit.datecalc.common.KitCalculatorsFactory;
import net.objectlab.kit.datecalc.common.Utils;
-public class JdkDateForwardDateCalculatorTest extends AbstractForwardDateCalculatorTest {
+public class JdkDateForwardDateCalculatorTest extends AbstractForwardUnlessNegativeCalculatorTest {
@Override
protected Object newDate(final String date) {
Added: trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardUnlessNegativeDateCalculatorTest.java
===================================================================
--- trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardUnlessNegativeDateCalculatorTest.java (rev 0)
+++ trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/JdkDateForwardUnlessNegativeDateCalculatorTest.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -0,0 +1,67 @@
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ *
+ * $Id: JdkDateForwardDateCalculatorTest.java 203 2006-10-11 12:53:07Z benoitx $
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.jdk;
+
+import net.objectlab.kit.datecalc.common.AbstractForwardDateCalculatorTest;
+import net.objectlab.kit.datecalc.common.KitCalculatorsFactory;
+import net.objectlab.kit.datecalc.common.Utils;
+
+public class JdkDateForwardUnlessNegativeDateCalculatorTest extends AbstractForwardDateCalculatorTest {
+
+ @Override
+ protected Object newDate(final String date) {
+ return Utils.createDate(date);
+ }
+
+ @Override
+ protected KitCalculatorsFactory getDateCalculatorFactory() {
+ return DateKitCalculatorsFactory.getDefaultInstance();
+ }
+}
+
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java
===================================================================
--- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -97,6 +97,8 @@
// -----------------------------------------------------------------------
public DateCalculator<LocalDate> moveByDays(final int days) {
+ setCurrentIncrement(days);
+
setCurrentBusinessDate(getCurrentBusinessDate().plusDays(days));
if (getHolidayHandler() != null) {
@@ -108,7 +110,9 @@
@Override
public DateCalculator<LocalDate> moveByMonths(final int months) {
- setCurrentBusinessDate(getCurrentBusinessDate().plusMonths(months));
+ setCurrentIncrement(months);
+
+ setCurrentBusinessDate(getCurrentBusinessDate().plusMonths(months));
if (getHolidayHandler() != null) {
setCurrentBusinessDate(getHolidayHandler().moveCurrentDate(this));
Added: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateForwardUnlessNegativeHandler.java
===================================================================
--- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateForwardUnlessNegativeHandler.java (rev 0)
+++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateForwardUnlessNegativeHandler.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -0,0 +1,109 @@
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ *
+ * $Id: LocalDateForwardHandler.java 203 2006-10-11 12:53:07Z benoitx $
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.joda;
+
+import net.objectlab.kit.datecalc.common.DateCalculator;
+import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.HolidayHandlerType;
+
+import org.joda.time.LocalDate;
+
+/**
+ * A Forward handler will move the date forward if it falls on a non working
+ * day.
+ *
+ * @author Benoit Xhenseval
+ * @author $LastChangedBy: benoitx $
+ * @version $Revision: 203 $ $Date: 2006-10-11 13:53:07 +0100 (Wed, 11 Oct 2006) $
+ *
+ */
+public class LocalDateForwardUnlessNegativeHandler implements HolidayHandler<LocalDate> {
+
+ /**
+ * If the current date of the give calculator is a non-working day, it will
+ * be moved according to the algorithm implemented.
+ *
+ * @param calculator
+ * the calculator
+ * @return the date which may have moved.
+ */
+ public LocalDate moveCurrentDate(final DateCalculator<LocalDate> calculator) {
+ return move(calculator, 1);
+ }
+
+ protected LocalDate move(final DateCalculator<LocalDate> calculator, final int step) {
+ LocalDate date = calculator.getCurrentBusinessDate();
+ if (calculator.getCurrentIncrement()<0) {
+ System.err.println(calculator.getCurrentBusinessDate()+" increment "+calculator.getCurrentIncrement()+ " step "+step);
+ }
+ while (calculator.isNonWorkingDay(date)) {
+ if (calculator.getCurrentIncrement() < 0) {
+ // act as a Backward calendar
+ date = date.minusDays(step);
+ } else {
+ // move forward by a day!
+ date = date.plusDays(step);
+ }
+ if (calculator.getCurrentIncrement()<0) {
+ System.err.println("CAlc "+date);
+ }
+ }
+ return date;
+ }
+
+ /**
+ * Give the type name for this algorithm.
+ *
+ * @return algorithm name.
+ */
+ public String getType() {
+ return HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK;
+ }
+}
+
+/*
+ * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateKitCalculatorsFactory.java
===================================================================
--- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateKitCalculatorsFactory.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateKitCalculatorsFactory.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -92,6 +92,8 @@
cal.setHolidayHandler(new LocalDateModifiedFollowingHandler());
} else if (HolidayHandlerType.MODIFIED_PRECEEDING.equals(holidayHandlerType)) {
cal.setHolidayHandler(new LocalDateModifiedPreceedingHandler());
+ } else if (HolidayHandlerType.FORWARD_UNLESS_MOVING_BACK.equals(holidayHandlerType)) {
+ cal.setHolidayHandler(new LocalDateForwardUnlessNegativeHandler());
} else if (holidayHandlerType != null) {
throw new IllegalArgumentException("Unsupported HolidayHandler: " + holidayHandlerType);
}
Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java
===================================================================
--- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java 2006-11-03 15:59:19 UTC (rev 219)
+++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java 2006-11-13 22:39:54 UTC (rev 220)
@@ -102,6 +102,8 @@
}
public DateCalculator<YearM...
[truncated message content] |