|
From: <ma...@us...> - 2006-08-26 09:30:13
|
Revision: 61 Author: marchy Date: 2006-08-26 02:28:55 -0700 (Sat, 26 Aug 2006) ViewCVS: http://svn.sourceforge.net/objectlabkit/?rev=61&view=rev Log Message: ----------- Made DateCalculatorFactory and PeriodCountCalculator generic. Modified Paths: -------------- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultPeriodCountCalculator.java trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculatorTest.java trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultDateCalculatorFactory.java trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculatorTest.java Added Paths: ----------- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculatorFactory.java trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/PeriodCountCalculator.java Removed Paths: ------------- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateCalculatorFactory.java trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculator.java trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DateCalculatorFactory.java trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculator.java Copied: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculatorFactory.java (from rev 57, trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateCalculatorFactory.java) =================================================================== --- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculatorFactory.java (rev 0) +++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculatorFactory.java 2006-08-26 09:28:55 UTC (rev 61) @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * 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.Set; + +/** + * Factory will create new instances of DateCalculator, these are lightweight, + * each thread should use the factory as a given DateCalculator should NOT be + * shared across thread (unless you know what you're doing) as the startDate, + * current date and working week would be shared. Once created, the set of + * holidays will NOT change even if a new set is registered; one needs to get a + * new DateCalculator to get the new set. + * + * @author Benoit Xhenseval + * @author $LastEditedBy$ + * @version $Revision$ $Date$ + */ +public interface DateCalculatorFactory<E> { + + /** + * Create a new DateCalculator for a given name and type of handling. + * + * @param name + * calendar name (holidays set interested in). If there is set of + * holidays with that name, it will return a DateCalculator with + * an empty holiday set (will work on Weekend only). + * @param type + * typically one of the value of HolidayHandlerType + * @return a new DateCalculator + */ + DateCalculator<E> getDateCalculator(final String name, + final String holidayHandlerType); + + /** + * Use this method to register a set of holidays for a given calendar. + * + * @param name + * the calendar name to register these holidays under. + * @param holidays + * the set of holidays (non-working days). + */ + void registerHolidays(final String name, Set<E> holidays); + + /** + * @return a PeriodCountCalculator + */ + PeriodCountCalculator<E> getPeriodCountCalculator(); +} Copied: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/PeriodCountCalculator.java (from rev 57, trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculator.java) =================================================================== --- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/PeriodCountCalculator.java (rev 0) +++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/PeriodCountCalculator.java 2006-08-26 09:28:55 UTC (rev 61) @@ -0,0 +1,35 @@ +/* + * $Id$ + * + * 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; + +/** + * TODO add javadoc + * + * @author Benoit Xhenseval + * @author $LastChangedBy$ + * @version $Revision$ $Date$ + * + * @param <E> + */ +public interface PeriodCountCalculator<E> { + int dayDiff(final E start, final E end, PeriodCountBasis basis); + + double monthDiff(final E start, final E end, PeriodCountBasis basis); + + double yearDiff(final E start, final E end, PeriodCountBasis basis); +} Deleted: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateCalculatorFactory.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateCalculatorFactory.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DateCalculatorFactory.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,62 +0,0 @@ -/* - * 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.Date; -import java.util.Set; - -import net.objectlab.kit.datecalc.common.DateCalculator; - -/** - * Factory will create new instances of DateCalculator, these are lightweight, - * each thread should use the factory as a given DateCalculator should NOT be - * shared across thread (unless you know what you're doing) as the startDate, - * current date and working week would be shared. Once created, the set of - * holidays will NOT change even if a new set is registered; one needs to get a - * new DateCalculator to get the new set. - * - * @author Benoit Xhenseval - */ -public interface DateCalculatorFactory { - - /** - * Create a new DateCalculator for a given name and type of handling. - * - * @param name - * calendar name (holidays set interested in). If there is set of - * holidays with that name, it will return a DateCalculator with - * an empty holiday set (will work on Weekend only). - * @param type - * typically one of the value of HolidayHandlerType - * @return a new DateCalculator - */ - DateCalculator getDateCalculator(final String name, final String holidayHandlerType); - - /** - * Use this method to register a set of holidays for a given calendar. - * - * @param name - * the calendar name to register these holidays under. - * @param holidays - * the set of holidays (non-working days). - */ - void registerHolidays(final String name, Set<Date> holidays); - - /** - * @return a PeriodCountCalculator - */ - PeriodCountCalculator getPeriodCountCalculator(); -} Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,4 +1,6 @@ /* + * $Id$ + * * Copyright 2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -21,9 +23,19 @@ import java.util.concurrent.ConcurrentMap; import net.objectlab.kit.datecalc.common.DateCalculator; +import net.objectlab.kit.datecalc.common.DateCalculatorFactory; import net.objectlab.kit.datecalc.common.HolidayHandlerType; +import net.objectlab.kit.datecalc.common.PeriodCountCalculator; -public class DefaultDateCalculatorFactory implements DateCalculatorFactory { +/** + * TODO add javadoc + * + * @author Benoit Xhenseval + * @author $LastChangedBy$ + * @version $Revision$ $Date$ + * + */ +public class DefaultDateCalculatorFactory implements DateCalculatorFactory<Date> { private static final DateCalculatorFactory DEFAULT = new DefaultDateCalculatorFactory(); private final ConcurrentMap<String, Set<Date>> holidays = new ConcurrentHashMap<String, Set<Date>>(); @@ -43,7 +55,7 @@ * typically one of the value of HolidayHandlerType * @return a new DateCalculator */ - public DateCalculator getDateCalculator(final String name, final String holidayHandlerType) { + public DateCalculator<Date> getDateCalculator(final String name, final String holidayHandlerType) { final BaseDateCalculator cal = new BaseDateCalculator(); cal.setName(name); if (holidays.containsKey(name)) { @@ -85,9 +97,9 @@ this.holidays.put(name, holidays); } - private static final PeriodCountCalculator PCC = new DefaultPeriodCountCalculator(); + private static final PeriodCountCalculator<Date> PCC = new DefaultPeriodCountCalculator(); - public PeriodCountCalculator getPeriodCountCalculator() { + public PeriodCountCalculator<Date> getPeriodCountCalculator() { return PCC; } } Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultPeriodCountCalculator.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultPeriodCountCalculator.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultPeriodCountCalculator.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,3 +1,20 @@ +/* + * $Id$ + * + * 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.Date; @@ -3,6 +20,15 @@ import net.objectlab.kit.datecalc.common.PeriodCountBasis; +import net.objectlab.kit.datecalc.common.PeriodCountCalculator; -public class DefaultPeriodCountCalculator implements PeriodCountCalculator { +/** + * TODO javadoc + * + * @author Benoit Xhenseval + * @author $LastChangedBy$ + * @version $Revision$ $Date$ + * + */ +public class DefaultPeriodCountCalculator implements PeriodCountCalculator<Date> { public int dayDiff(final Date start, final Date end, final PeriodCountBasis basis) { Deleted: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculator.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculator.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculator.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,13 +0,0 @@ -package net.objectlab.kit.datecalc.jdk; - -import java.util.Date; - -import net.objectlab.kit.datecalc.common.PeriodCountBasis; - -public interface PeriodCountCalculator { - int dayDiff(final Date start, final Date end, PeriodCountBasis basis); - - double monthDiff(final Date start, final Date end, PeriodCountBasis basis); - - double yearDiff(final Date start, final Date end, PeriodCountBasis basis); -} Modified: trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculatorTest.java =================================================================== --- trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculatorTest.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-jdk/src/test/java/net/objectlab/kit/datecalc/jdk/PeriodCountCalculatorTest.java 2006-08-26 09:28:55 UTC (rev 61) @@ -20,6 +20,7 @@ import junit.framework.Assert; import net.objectlab.kit.datecalc.common.PeriodCountBasis; +import net.objectlab.kit.datecalc.common.PeriodCountCalculator; public class PeriodCountCalculatorTest extends AbstractDateCalculatorTest { Deleted: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DateCalculatorFactory.java =================================================================== --- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DateCalculatorFactory.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DateCalculatorFactory.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,63 +0,0 @@ -/* - * 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 java.util.Set; - -import net.objectlab.kit.datecalc.common.DateCalculator; - -import org.joda.time.LocalDate; - -/** - * Factory will create new instances of DateCalculator, these are lightweight, - * each thread should use the factory as a given DateCalculator should NOT be - * shared across thread (unless you know what you're doing) as the startDate, - * current date and working week would be shared. Once created, the set of - * holidays will NOT change even if a new set is registered; one needs to get a - * new DateCalculator to get the new set. - * - * @author Benoit Xhenseval - */ -public interface DateCalculatorFactory { - - /** - * Create a new DateCalculator for a given name and type of handling. - * - * @param name - * calendar name (holidays set interested in). If there is set of - * holidays with that name, it will return a DateCalculator with - * an empty holiday set (will work on Weekend only). - * @param type - * typically one of the value of HolidayHandlerType - * @return a new DateCalculator - */ - DateCalculator<LocalDate> getDateCalculator(final String name, final String holidayHandlerType); - - /** - * Use this method to register a set of holidays for a given calendar. - * - * @param name - * the calendar name to register these holidays under. - * @param holidays - * the set of holidays (non-working days). - */ - void registerHolidays(final String name, Set<LocalDate> holidays); - - /** - * @return a PeriodCountCalculator - */ - PeriodCountCalculator getPeriodCountCalculator(); -} Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultDateCalculatorFactory.java =================================================================== --- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultDateCalculatorFactory.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultDateCalculatorFactory.java 2006-08-26 09:28:55 UTC (rev 61) @@ -21,11 +21,13 @@ import java.util.concurrent.ConcurrentMap; import net.objectlab.kit.datecalc.common.DateCalculator; +import net.objectlab.kit.datecalc.common.DateCalculatorFactory; import net.objectlab.kit.datecalc.common.HolidayHandlerType; +import net.objectlab.kit.datecalc.common.PeriodCountCalculator; import org.joda.time.LocalDate; -public class DefaultDateCalculatorFactory implements DateCalculatorFactory { +public class DefaultDateCalculatorFactory implements DateCalculatorFactory<LocalDate> { private static final DateCalculatorFactory DEFAULT = new DefaultDateCalculatorFactory(); private final ConcurrentMap<String, Set<LocalDate>> holidays = new ConcurrentHashMap<String, Set<LocalDate>>(); @@ -79,9 +81,9 @@ this.holidays.put(name, new HashSet<LocalDate>(holidayDates)); } - private static final PeriodCountCalculator PCC = new DefaultPeriodCountCalculator(); + private static final PeriodCountCalculator<LocalDate> PCC = new DefaultPeriodCountCalculator(); - public PeriodCountCalculator getPeriodCountCalculator() { + public PeriodCountCalculator<LocalDate> getPeriodCountCalculator() { return PCC; } } Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java =================================================================== --- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,12 +1,13 @@ package net.objectlab.kit.datecalc.joda; import net.objectlab.kit.datecalc.common.PeriodCountBasis; +import net.objectlab.kit.datecalc.common.PeriodCountCalculator; import org.joda.time.LocalDate; import org.joda.time.Period; import org.joda.time.PeriodType; -public class DefaultPeriodCountCalculator implements PeriodCountCalculator { +public class DefaultPeriodCountCalculator implements PeriodCountCalculator<LocalDate> { private static final int YEAR_360 = 360; private static final int MONTHS_IN_YEAR = 12; Deleted: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculator.java =================================================================== --- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculator.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculator.java 2006-08-26 09:28:55 UTC (rev 61) @@ -1,13 +0,0 @@ -package net.objectlab.kit.datecalc.joda; - -import net.objectlab.kit.datecalc.common.PeriodCountBasis; - -import org.joda.time.LocalDate; - -public interface PeriodCountCalculator { - int dayDiff(final LocalDate start, final LocalDate end, PeriodCountBasis basis); - - double monthDiff(final LocalDate start, final LocalDate end, PeriodCountBasis basis); - - double yearDiff(final LocalDate start, final LocalDate end, PeriodCountBasis basis); -} Modified: trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculatorTest.java =================================================================== --- trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculatorTest.java 2006-08-26 09:08:30 UTC (rev 60) +++ trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/PeriodCountCalculatorTest.java 2006-08-26 09:28:55 UTC (rev 61) @@ -20,6 +20,7 @@ import junit.framework.Assert; import junit.framework.TestCase; import net.objectlab.kit.datecalc.common.PeriodCountBasis; +import net.objectlab.kit.datecalc.common.PeriodCountCalculator; import org.joda.time.LocalDate; @@ -316,7 +317,7 @@ }; public void testConv30EvIsma() { - final PeriodCountCalculator cal = DefaultDateCalculatorFactory.getDefaultInstance().getPeriodCountCalculator(); + final PeriodCountCalculator<LocalDate> cal = DefaultDateCalculatorFactory.getDefaultInstance().getPeriodCountCalculator(); Assert.assertNotNull(cal); for (final String[] test : CONV_360E_ISMA) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |