Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- 3157 discussions
Author: hudson
Date: 2010-08-29 17:20:53 +0200 (Sun, 29 Aug 2010)
New Revision: 1915
Url: http://nuiton.org/repositories/revision/nuiton-utils/1915
Log:
[maven-release-plugin] prepare release nuiton-utils-1.4.1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-08-29 14:52:06 UTC (rev 1914)
+++ trunk/pom.xml 2010-08-29 15:20:53 UTC (rev 1915)
@@ -37,7 +37,7 @@
</parent>
<artifactId>nuiton-utils</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.4.1</version>
<dependencies>
@@ -170,9 +170,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/nuiton-utils/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/nuiton-utils/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/nuiton-utils/trunk</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/nuiton-utils/tags/nuiton-utils-1.4.1</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/nuiton-utils/tags/nuiton-utils-1.4.1</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/nuiton-utils/tags/nuiton-utils-1.…</url>
</scm>
<profiles>
1
0
Author: tchemit
Date: 2010-08-29 16:52:06 +0200 (Sun, 29 Aug 2010)
New Revision: 1914
Url: http://nuiton.org/repositories/revision/nuiton-utils/1914
Log:
fix author
Modified:
trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
Modified: trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2010-08-29 14:50:47 UTC (rev 1913)
+++ trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2010-08-29 14:52:06 UTC (rev 1914)
@@ -56,7 +56,7 @@
* properties for the attached bean since the last call to
* {@link #clearModified()} (or {@link #setBean(Object)}.
*
- * @author chemit <chemit(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
* @since 1.4.1
*/
public class BeanMonitor {
1
0
r1913 - in trunk/src: license main/java/org/nuiton/util main/java/org/nuiton/util/beans main/java/org/nuiton/util/converter test/java/org/nuiton/util test/java/org/nuiton/util/beans test/java/org/nuiton/util/converter
by tchemit@users.nuiton.org 29 Aug '10
by tchemit@users.nuiton.org 29 Aug '10
29 Aug '10
Author: tchemit
Date: 2010-08-29 16:50:47 +0200 (Sun, 29 Aug 2010)
New Revision: 1913
Url: http://nuiton.org/repositories/revision/nuiton-utils/1913
Log:
add svn keywords
Modified:
trunk/src/license/THIRD-PARTY.properties
trunk/src/license/project.xml
trunk/src/main/java/org/nuiton/util/DateUtil.java
trunk/src/main/java/org/nuiton/util/TestUtil.java
trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java
trunk/src/main/java/org/nuiton/util/converter/package-info.java
trunk/src/test/java/org/nuiton/util/DateUtilTest.java
trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
trunk/src/test/java/org/nuiton/util/converter/UnregistreableConverter.java
Property changes on: trunk/src/license/THIRD-PARTY.properties
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision HeadURL
+ HeadURL Id Date Revision Author
Property changes on: trunk/src/license/project.xml
___________________________________________________________________
Modified: svn:keywords
- "Author Date Id Revision HeadURL
+ HeadURL Id Date Revision Author
Modified: trunk/src/main/java/org/nuiton/util/DateUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/DateUtil.java 2010-08-29 14:47:34 UTC (rev 1912)
+++ trunk/src/main/java/org/nuiton/util/DateUtil.java 2010-08-29 14:50:47 UTC (rev 1913)
@@ -2,8 +2,8 @@
* #%L
* Nuiton Utils
*
- * $Id: DateUtils.java 1907 2010-08-26 11:09:55Z tchemit $
- * $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/src/main/java/org/nuiton/util/… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2004 - 2010 CodeLutin
* %%
@@ -38,7 +38,7 @@
*
* <b>Note: </b>
* @author fdesbois
- * @version $Id: DateUtils.java 1907 2010-08-26 11:09:55Z tchemit $
+ * @version $Id$
* @since 1.4.1
*/
public class DateUtil {
Property changes on: trunk/src/main/java/org/nuiton/util/DateUtil.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Modified: trunk/src/main/java/org/nuiton/util/TestUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/TestUtil.java 2010-08-29 14:47:34 UTC (rev 1912)
+++ trunk/src/main/java/org/nuiton/util/TestUtil.java 2010-08-29 14:50:47 UTC (rev 1913)
@@ -38,7 +38,7 @@
* Created: 22 juin 2010
*
* @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id:$
+ * @version $Id$
*/
public class TestUtil {
Property changes on: trunk/src/main/java/org/nuiton/util/TestUtil.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Property changes on: trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Property changes on: trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Property changes on: trunk/src/main/java/org/nuiton/util/converter/package-info.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision HeadURL
+ HeadURL Id Date Revision Author
Modified: trunk/src/test/java/org/nuiton/util/DateUtilTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/DateUtilTest.java 2010-08-29 14:47:34 UTC (rev 1912)
+++ trunk/src/test/java/org/nuiton/util/DateUtilTest.java 2010-08-29 14:50:47 UTC (rev 1913)
@@ -2,8 +2,8 @@
* #%L
* Nuiton Utils
*
- * $Id: DateUtilsTest.java 1907 2010-08-26 11:09:55Z tchemit $
- * $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/src/test/java/org/nuiton/util/… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2004 - 2010 CodeLutin
* %%
Property changes on: trunk/src/test/java/org/nuiton/util/DateUtilTest.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Modified: trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java 2010-08-29 14:47:34 UTC (rev 1912)
+++ trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java 2010-08-29 14:50:47 UTC (rev 1913)
@@ -33,7 +33,7 @@
* Tests {@link BeanMonitor}.
*
* @author tchemit <chemit(a)codelutin.com>
- * @serial $Id:$
+ * @serial $Id$
* @since 1.4.1
*/
public class BeanMonitorTest {
Property changes on: trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Property changes on: trunk/src/test/java/org/nuiton/util/converter/UnregistreableConverter.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision HeadURL
+ HeadURL Id Date Revision Author
1
0
r1912 - in trunk/src: main/java/org/nuiton/util/beans test/java/org/nuiton/util/beans
by tchemit@users.nuiton.org 29 Aug '10
by tchemit@users.nuiton.org 29 Aug '10
29 Aug '10
Author: tchemit
Date: 2010-08-29 16:47:34 +0200 (Sun, 29 Aug 2010)
New Revision: 1912
Url: http://nuiton.org/repositories/revision/nuiton-utils/1912
Log:
add headers + clean BeanUtil
Modified:
trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java
trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
Modified: trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2010-08-29 14:39:36 UTC (rev 1911)
+++ trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2010-08-29 14:47:34 UTC (rev 1912)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.util.beans;
import org.apache.commons.logging.Log;
Modified: trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java 2010-08-29 14:39:36 UTC (rev 1911)
+++ trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java 2010-08-29 14:47:34 UTC (rev 1912)
@@ -1,20 +1,34 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.util.beans;
import org.apache.commons.beanutils.MethodUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import static org.nuiton.i18n.I18n._;
-
/**
* Usefull methods around the {@link PropertyChangeListener}.
*
@@ -22,7 +36,10 @@
* @since 1.4.1
*/
public class BeanUtil {
+ public static final String ADD_PROPERTY_CHANGE_LISTENER = "addPropertyChangeListener";
+ public static final String REMOVE_PROPERTY_CHANGE_LISTENER = "removePropertyChangeListener";
+
protected BeanUtil() {
// no instance
}
@@ -45,7 +62,7 @@
public static void addPropertyChangeListener(PropertyChangeListener listener,
Object bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
MethodUtils.invokeExactMethod(bean,
- "addPropertyChangeListener",
+ ADD_PROPERTY_CHANGE_LISTENER,
new Object[]{listener},
new Class[]{PropertyChangeListener.class}
);
@@ -69,7 +86,7 @@
public static void removePropertyChangeListener(PropertyChangeListener listener,
Object bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
MethodUtils.invokeExactMethod(bean,
- "removePropertyChangeListener",
+ REMOVE_PROPERTY_CHANGE_LISTENER,
new Object[]{listener},
new Class[]{PropertyChangeListener.class}
);
Modified: trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java 2010-08-29 14:39:36 UTC (rev 1911)
+++ trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java 2010-08-29 14:47:34 UTC (rev 1912)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.util.beans;
import org.junit.Assert;
1
0
Author: tchemit
Date: 2010-08-29 16:39:36 +0200 (Sun, 29 Aug 2010)
New Revision: 1911
Url: http://nuiton.org/repositories/revision/nuiton-utils/1911
Log:
Evolution #832: Deprecates Log class
Modified:
trunk/src/test/java/org/nuiton/util/LogTest.java
Modified: trunk/src/test/java/org/nuiton/util/LogTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/LogTest.java 2010-08-29 14:38:34 UTC (rev 1910)
+++ trunk/src/test/java/org/nuiton/util/LogTest.java 2010-08-29 14:39:36 UTC (rev 1911)
@@ -38,6 +38,10 @@
import junit.framework.TestCase;
+/**
+ * @deprecated since 1.4.1, will not be replaced.
+ */
+@Deprecated
public class LogTest extends TestCase { // LogTest
protected int callTest = 0;
1
0
r1910 - in trunk/src: main/java/org/nuiton/util test/java/org/nuiton/util
by tchemit@users.nuiton.org 29 Aug '10
by tchemit@users.nuiton.org 29 Aug '10
29 Aug '10
Author: tchemit
Date: 2010-08-29 16:38:34 +0200 (Sun, 29 Aug 2010)
New Revision: 1910
Url: http://nuiton.org/repositories/revision/nuiton-utils/1910
Log:
Evolution #831: Deprecates DateUtils in favour to DateUtil
Modified:
trunk/src/main/java/org/nuiton/util/PeriodDates.java
trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java
Modified: trunk/src/main/java/org/nuiton/util/PeriodDates.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/PeriodDates.java 2010-08-29 14:34:29 UTC (rev 1909)
+++ trunk/src/main/java/org/nuiton/util/PeriodDates.java 2010-08-29 14:38:34 UTC (rev 1910)
@@ -58,7 +58,7 @@
setFromDate(fromDate);
setThruDate(thruDate);
- pattern = DateUtils.DEFAULT_PATTERN;
+ pattern = DateUtil.DEFAULT_PATTERN;
}
public PeriodDates(Calendar fromCalendar, Calendar thruCalendar) throws IllegalArgumentException {
@@ -68,7 +68,7 @@
this.fromCalendar = fromCalendar;
this.thruCalendar = thruCalendar;
- pattern = DateUtils.DEFAULT_PATTERN;
+ pattern = DateUtil.DEFAULT_PATTERN;
}
/**
@@ -95,7 +95,7 @@
Calendar calendarThru = Calendar.getInstance();
// Reset time
- Date minTime = DateUtils.setMinTimeOfDay(new Date());
+ Date minTime = DateUtil.setMinTimeOfDay(new Date());
calendarFrom.setTime(minTime);
calendarThru.setTime(minTime);
@@ -107,7 +107,7 @@
PeriodDates period = new PeriodDates(calendarFrom, calendarThru);
period.initDayOfMonthExtremities();
- period.setPattern(DateUtils.MONTH_PATTERN);
+ period.setPattern(DateUtil.MONTH_PATTERN);
return period;
}
@@ -181,13 +181,13 @@
// Prepare calendars for while condition :
// set first day of month + reset time to 00:00:00.000
- Date tmp = DateUtils.setFirstDayOfMonth(fromCalendar.getTime());
- tmp = DateUtils.setMinTimeOfDay(tmp);
- Calendar current = DateUtils.getDefaultCalendar(tmp);
+ Date tmp = DateUtil.setFirstDayOfMonth(fromCalendar.getTime());
+ tmp = DateUtil.setMinTimeOfDay(tmp);
+ Calendar current = DateUtil.getDefaultCalendar(tmp);
- tmp = DateUtils.setFirstDayOfMonth(thruCalendar.getTime());
- tmp = DateUtils.setMinTimeOfDay(tmp);
- Calendar end = DateUtils.getDefaultCalendar(tmp);
+ tmp = DateUtil.setFirstDayOfMonth(thruCalendar.getTime());
+ tmp = DateUtil.setMinTimeOfDay(tmp);
+ Calendar end = DateUtil.getDefaultCalendar(tmp);
while (!current.equals(end)) {
months.add(current.getTime());
@@ -201,7 +201,7 @@
public List<String> getFormatedMonths() {
List<String> results = new ArrayList<String>();
for (Date date : getMonths()) {
- String str = DateUtils.formatDate(date, pattern);
+ String str = DateUtil.formatDate(date, pattern);
results.add(str);
}
return results;
@@ -224,30 +224,30 @@
}
public boolean beforeEnd(Date date) {
- Calendar calendar = DateUtils.getDefaultCalendar(date);
+ Calendar calendar = DateUtil.getDefaultCalendar(date);
return beforeEnd(calendar);
}
public boolean afterEnd(Date date) {
- Calendar calendar = DateUtils.getDefaultCalendar(date);
+ Calendar calendar = DateUtil.getDefaultCalendar(date);
return afterEnd(calendar);
}
public boolean afterBegin(Date date) {
- Calendar calendar = DateUtils.getDefaultCalendar(date);
+ Calendar calendar = DateUtil.getDefaultCalendar(date);
return afterBegin(calendar);
}
public boolean between(Date date) {
- Calendar calendar = DateUtils.getDefaultCalendar(date);
+ Calendar calendar = DateUtil.getDefaultCalendar(date);
return between(calendar);
}
@Override
public String toString() {
- String fromStr = DateUtils.formatDate(getFromDate(), pattern);
- String thruStr = DateUtils.formatDate(getThruDate(), pattern);
+ String fromStr = DateUtil.formatDate(getFromDate(), pattern);
+ String thruStr = DateUtil.formatDate(getThruDate(), pattern);
return "[ " + getFromDate() + " (pattern: " + fromStr + ") -> " +
getThruDate() + " (pattern: " + thruStr + ") ]";
}
Modified: trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java 2010-08-29 14:34:29 UTC (rev 1909)
+++ trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java 2010-08-29 14:38:34 UTC (rev 1910)
@@ -122,7 +122,7 @@
log.info("getMonths");
// Prepare two calendars with time not equals to 0
- Calendar cal1 = DateUtils.getDefaultCalendar(new Date());
+ Calendar cal1 = DateUtil.getDefaultCalendar(new Date());
cal1.set(Calendar.DAY_OF_MONTH, 3);
cal1.set(Calendar.MONTH, 2);
cal1.set(Calendar.YEAR, 2009);
@@ -132,7 +132,7 @@
log.info("getMonths:: time for calendarFrom : " +
timeFormat.format(cal1.getTime()));
- Calendar cal2 = DateUtils.getDefaultCalendar(new Date());
+ Calendar cal2 = DateUtil.getDefaultCalendar(new Date());
cal2.set(Calendar.DAY_OF_MONTH, 22);
cal2.set(Calendar.MONTH, 6);
cal2.set(Calendar.YEAR, 2009);
@@ -147,7 +147,7 @@
Assert.assertEquals(5, months.size());
for (int i = 0; i < 5; i++) {
Date monthDate = months.get(i);
- int month = DateUtils.getDefaultCalendar(monthDate).get(Calendar.MONTH);
+ int month = DateUtil.getDefaultCalendar(monthDate).get(Calendar.MONTH);
Assert.assertEquals(i + 2, month); // 2, 3, 4, 5, 6
}
}
1
0
r1909 - in trunk/src: main/java/org/nuiton/util test/java/org/nuiton/util
by tchemit@users.nuiton.org 29 Aug '10
by tchemit@users.nuiton.org 29 Aug '10
29 Aug '10
Author: tchemit
Date: 2010-08-29 16:34:29 +0200 (Sun, 29 Aug 2010)
New Revision: 1909
Url: http://nuiton.org/repositories/revision/nuiton-utils/1909
Log:
Evolution #831: Deprecates DateUtils in favour to DateUtil
Added:
trunk/src/main/java/org/nuiton/util/DateUtil.java
trunk/src/test/java/org/nuiton/util/DateUtilTest.java
Modified:
trunk/src/main/java/org/nuiton/util/DateUtils.java
trunk/src/test/java/org/nuiton/util/DateUtilsTest.java
Added: trunk/src/main/java/org/nuiton/util/DateUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/DateUtil.java (rev 0)
+++ trunk/src/main/java/org/nuiton/util/DateUtil.java 2010-08-29 14:34:29 UTC (rev 1909)
@@ -0,0 +1,372 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id: DateUtils.java 1907 2010-08-26 11:09:55Z tchemit $
+ * $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/src/main/java/org/nuiton/util/… $
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.util;
+
+import java.text.DateFormat;
+import java.text.DateFormatSymbols;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Library for manipulating dates.
+ *
+ * <b>Note: </b>
+ * @author fdesbois
+ * @version $Id: DateUtils.java 1907 2010-08-26 11:09:55Z tchemit $
+ * @since 1.4.1
+ */
+public class DateUtil {
+
+ public static final String DEFAULT_PATTERN = "dd/MM/yyyy";
+
+ public static final String MONTH_PATTERN = "MM/yyyy";
+
+ /**
+ * Format a date using the pattern in argument. The pattern is the same using
+ * for DateFormat object.
+ *
+ * @param date the date to format
+ * @param pattern the pattern to use
+ * @return a String corresponding to the date formatted
+ * @see DateFormat
+ */
+ public static String formatDate(Date date, String pattern) {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
+ return simpleDateFormat.format(date);
+ }
+
+ public static String formatDate(Date date, String pattern, Locale locale) {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale);
+ return simpleDateFormat.format(date);
+ }
+
+ /**
+ * Parse a date using the pattern in argument. The pattern is the same using
+ * for DateFormat object.
+ *
+ * @param date the String to parse
+ * @param pattern the pattern to use
+ * @return a Date corresponding to the String argument parsed
+ * @throws ParseException for parsing errors
+ * @see DateFormat
+ */
+ public static Date parseDate(String date, String pattern) throws ParseException {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
+ Date result = simpleDateFormat.parse(date);
+ return result;
+ }
+
+ /**
+ * Create a new date from day, month and year (French version).
+ * The month is the real month of the year and not the one which is stored
+ * in Calendar object.
+ * @param s value of the seconds 1-60
+ * @param m value of the minutes 1-60
+ * @param h value of the hours 1-24
+ * @param dd value of the day 1-31
+ * @param mm value of the month 1-12
+ * @param yy value of the year 0-9999
+ * @return a new date
+ */
+ public static Date createDate(int s, int m, int h, int dd, int mm, int yy) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(Calendar.YEAR, yy);
+ calendar.set(Calendar.MONTH, mm-1);
+ calendar.set(Calendar.DAY_OF_MONTH, dd);
+ calendar.set(Calendar.HOUR_OF_DAY, h);
+ calendar.set(Calendar.MINUTE, m);
+ calendar.set(Calendar.SECOND, s);
+ return calendar.getTime();
+ }
+
+ /**
+ * Create a new date from day, month and year (French version).
+ * The month is the real month of the year and not the one which is stored
+ * in Calendar object. Time is set to 00:00:00.000
+ * @param dd value of the day 1-31
+ * @param mm value of the month 1-12
+ * @param yy value of the year 0-9999
+ * @return a new date
+ */
+ public static Date createDate(int dd, int mm, int yy) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(Calendar.YEAR, yy);
+ calendar.set(Calendar.MONTH, mm-1);
+ calendar.set(Calendar.DAY_OF_MONTH, dd);
+ return setMinTimeOfDay(calendar.getTime());
+ }
+
+ /**
+ * Create a new date after the current date (today) with modification on day, month and year.
+ * You can use negative values on arguments to have a date before today.
+ *
+ * @param ddStep nb days you want to increase from the current date
+ * @param mmStep nb months you want to increase from the current date
+ * @param yyStep nb years you want to increase from the current date
+ * @return a new date from the current date increase by days, months and years.
+ */
+ public static Date createDateAfterToday(int ddStep, int mmStep, int yyStep) {
+ Calendar calendar = getDefaultCalendar(new Date());
+ calendar.add(Calendar.DAY_OF_MONTH, ddStep);
+ calendar.add(Calendar.MONTH,mmStep);
+ calendar.add(Calendar.YEAR, yyStep);
+ return calendar.getTime();
+ }
+
+ /**
+ * Set the last day of month to the date in argument.
+ * The value depends on the month of the date. (30 april, 28 february, ...)
+ *
+ * @param date Date to modify
+ * @return the date with day of month modified
+ */
+ public static Date setLastDayOfMonth(Date date) {
+ Calendar calendar = getDefaultCalendar(date);
+ int maximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+ calendar.set(Calendar.DAY_OF_MONTH, maximum);
+ return calendar.getTime();
+ }
+
+ /**
+ * Set the first day of month to the date in argument.
+ *
+ * @param date Date to modify
+ * @return the date with day of month modified
+ */
+ public static Date setFirstDayOfMonth(Date date) {
+ Calendar calendar = getDefaultCalendar(date);
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ return calendar.getTime();
+ }
+
+ /**
+ * Set the min time of the day : 00:00:00.000.
+ *
+ * @param date to modify
+ * @return Date with the time set to the minimum in the day
+ */
+ public static Date setMinTimeOfDay(Date date) {
+ Calendar calendar = getDefaultCalendar(date);
+ calendar.set(Calendar.AM_PM, Calendar.AM);
+ calendar.set(Calendar.HOUR, 0);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ return calendar.getTime();
+ }
+
+ /**
+ * Set the max time of the day. EUROPE : 23:59:59.999.
+ *
+ * @param date to modify
+ * @return Date with the time set to the maximum in the day
+ */
+ public static Date setMaxTimeOfDay(Date date) {
+ Calendar calendar = getDefaultCalendar(date);
+ calendar.set(Calendar.AM_PM, Calendar.PM);
+ calendar.set(Calendar.HOUR, 11);
+ calendar.set(Calendar.MINUTE, 59);
+ calendar.set(Calendar.SECOND, 59);
+ calendar.set(Calendar.MILLISECOND, 999);
+ return calendar.getTime();
+ }
+
+ /**
+ * Check if the first date in argument is included between the two other
+ * dates. The argument myDate can be equals to beforeDate or afterDate to
+ * validate the includes.
+ *
+ * @param myDate the date to test
+ * @param beforeDate the first date of the period to test
+ * @param afterDate the second date of the period to test
+ * @return true if myDate is included between beforeDate and afterDate
+ */
+ public static boolean between(Date myDate, Date beforeDate, Date afterDate) {
+ if (myDate == null) {
+ return false;
+ }
+ boolean result = true;
+ result &= myDate.after(beforeDate) || myDate.compareTo(beforeDate) == 0;
+ result &= afterDate == null || myDate.before(afterDate) ||
+ myDate.compareTo(afterDate) == 0;
+ return result;
+ }
+
+ /**
+ * Check if the current date is between the two dates in argument.
+ *
+ * @param beforeDate the first date of the period
+ * @param afterDate the second date of the period
+ * @return true if the current date is included between the two dates,
+ * false otherwise
+ * @see #between(Date, Date, Date)
+ */
+ public static boolean currentPeriod(Date beforeDate, Date afterDate) {
+ return between(new Date(), beforeDate, afterDate);
+ }
+
+ /**
+ * Get the month value from a date (between 0 and 11).
+ *
+ * @param date the date to extract month
+ * @return the month value of the date
+ */
+ public static int getMonth(Date date) {
+ Calendar calendar = getDefaultCalendar(date);
+ return calendar.get(Calendar.MONTH);
+ }
+
+ /**
+ * Do the difference between the two dates in argument. The result is a number
+ * of seconds between the two dates.
+ *
+ * @param beginDate first date
+ * @param endDate second date
+ * @return a number of seconds between beginDate and endDate
+ */
+ public static int getDifferenceInSeconds(Date beginDate, Date endDate) {
+ long begin = beginDate.getTime();
+ long end = endDate.getTime();
+ return (int) Math.ceil((end - begin) / 1000);
+ }
+
+ /**
+ * Do the difference between the two dates in argument. The result is a number
+ * of minutes between the two dates.
+ *
+ * @param beginDate first date
+ * @param endDate second date
+ * @return a number of minutes between beginDate and endDate
+ */
+ public static int getDifferenceInMinutes(Date beginDate, Date endDate) {
+ long begin = beginDate.getTime();
+ long end = endDate.getTime();
+ // 60000 = 60 * 1000
+ return (int) Math.ceil((end - begin) / 60000);
+ }
+
+ /**
+ * Do the difference between the two dates in argument. The result is a number
+ * of hours between the two dates.
+ *
+ * @param beginDate first date
+ * @param endDate second date
+ * @return a number of hours between beginDate and endDate
+ */
+ public static int getDifferenceInHours(Date beginDate, Date endDate) {
+ long begin = beginDate.getTime();
+ long end = endDate.getTime();
+ // 3600000 = 60 * 60 * 1000
+ return (int) Math.ceil((end - begin) / 3600000);
+ }
+
+ /**
+ * Do the difference between the two dates in argument. The result is a number
+ * of days between the two dates.
+ * Ex : 28/01/2009 and 08/02/2009 return 11.
+ *
+ * @param beginDate first date
+ * @param endDate second date
+ * @return a number of days between beginDate and endDate
+ */
+ public static int getDifferenceInDays(Date beginDate, Date endDate) {
+ long begin = beginDate.getTime();
+ long end = endDate.getTime();
+ // 86400000 = 24 * 60 * 60 * 1000
+ return (int) Math.ceil((end - begin) / 86400000);
+ }
+
+ /**
+ * Do the difference between the two dates in argument. The result is a number
+ * of months between the two dates.
+ * Ex : 01/01/2009 and 28/02/2009 return 2 months.
+ * Warning, if beginDate is inferior to endDate, the result will be 1 minimum
+ *
+ * @param beginDate first date
+ * @param endDate second date
+ * @return a number of months between beginDate and endDate
+ */
+ public static int getDifferenceInMonths(Date beginDate, Date endDate) {
+ int count = 0;
+ Calendar fromCalendar = getDefaultCalendar(beginDate);
+ Calendar thruCalendar = getDefaultCalendar(endDate);
+
+ while (fromCalendar.before(thruCalendar)) {
+ fromCalendar.add(Calendar.MONTH, 1);
+ count++;
+ }
+ return count;
+ }
+
+ /**
+ * Get libelle of the month corresponding to the number given in argument.
+ *
+ * @param monthNumber between 1-12
+ * @param locale Locale for language support
+ * @return a String corresponding to the libelle of the month
+ */
+ public static String getMonthLibelle(int monthNumber, Locale locale) {
+ return new DateFormatSymbols(locale).getMonths()[monthNumber-1];
+ }
+
+ /**
+ * Get libelle of the month corresponding to the number given in argument.
+ *
+ * @param monthNumber between 1-12
+ * @return a String corresponding to the libelle of the month
+ */
+ public static String getMonthLibelle(int monthNumber) {
+ return getMonthLibelle(monthNumber, Locale.getDefault());
+ }
+
+ /**
+ * Get the date before today
+ *
+ * @param date concerned
+ * @return Date before today
+ */
+ public static Date getYesterday(Date date) {
+ Calendar cal = getDefaultCalendar(date);
+ cal.roll(Calendar.DAY_OF_MONTH, false);
+ return cal.getTime();
+ }
+
+ /**
+ * Get the calendar corresponding to the {@code date}. The default calendar
+ * will be returned (default time zone and locale).
+ *
+ * @param date used to set the calendar time
+ * @return the default calendar with time corresponding to the {@code date}
+ */
+ public static Calendar getDefaultCalendar(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ return calendar;
+ }
+}
Modified: trunk/src/main/java/org/nuiton/util/DateUtils.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/DateUtils.java 2010-08-29 14:21:26 UTC (rev 1908)
+++ trunk/src/main/java/org/nuiton/util/DateUtils.java 2010-08-29 14:34:29 UTC (rev 1909)
@@ -34,12 +34,13 @@
import java.util.Locale;
/**
- * TODO tchemit 2010-08-25 : the name of the class does not fit, it should be called {@code DateUtil}.
* Library for manipulating dates.
*
* @author fdesbois
* @version $Id$
+ * @deprecated since 1.4.1 (use now {@link DateUtil}
*/
+@Deprecated
public class DateUtils {
public static final String DEFAULT_PATTERN = "dd/MM/yyyy";
Added: trunk/src/test/java/org/nuiton/util/DateUtilTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/DateUtilTest.java (rev 0)
+++ trunk/src/test/java/org/nuiton/util/DateUtilTest.java 2010-08-29 14:34:29 UTC (rev 1909)
@@ -0,0 +1,291 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id: DateUtilsTest.java 1907 2010-08-26 11:09:55Z tchemit $
+ * $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/src/test/java/org/nuiton/util/… $
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ *
+ * @author fdesbois
+ * @since 1.4.1
+ */
+public class DateUtilTest {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(DateUtilTest.class);
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of formatDate method, of class DateUtils.
+ */
+ //@Test
+ public void testFormatDate() {
+ log.info("formatDate");
+ }
+
+ /**
+ * Test of parseDate method, of class DateUtils.
+ */
+ //@Test
+ public void testParseDate() {
+ log.info("parseDate");
+ }
+
+ /**
+ * Test of createDate method, of class DateUtils.
+ */
+ @Test
+ public void testCreateDate() {
+ log.info("createDate");
+
+ Date newdate = DateUtil.createDate(3, 3, 2009);
+ Calendar calendar = DateUtil.getDefaultCalendar(newdate);
+
+ Assert.assertEquals(3, calendar.get(Calendar.DAY_OF_MONTH));
+ Assert.assertEquals(2, calendar.get(Calendar.MONTH));
+ Assert.assertEquals(2009, calendar.get(Calendar.YEAR));
+
+ Assert.assertEquals(0, calendar.get(Calendar.HOUR));
+ Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
+ Assert.assertEquals(0, calendar.get(Calendar.SECOND));
+ Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
+ }
+
+ /**
+ * Test of createDateAfterToday method, of class DateUtil.
+ */
+ //@Test
+ public void testCreateDateAfterToday() {
+ log.info("createDateAfterToday");
+ }
+
+ /**
+ * Test of setLastDayOfMonth method, of class DateUtil.
+ */
+ //@Test
+ public void testSetLastDayOfMonth() {
+ log.info("setLastDayOfMonth");
+ }
+
+ /**
+ * Test of setFirstDayOfMonth method, of class DateUtil.
+ */
+ //@Test
+ public void testSetFirstDayOfMonth() {
+ log.info("setFirstDayOfMonth");
+ }
+
+ /**
+ * Test of between method, of class DateUtil.
+ */
+ @Test
+ public void testBetween() {
+ log.info("between");
+
+ Date middle = DateUtil.createDate(3, 3, 2009);
+
+ // middle = begin, and end = null
+ Date begin = DateUtil.createDate(3, 3, 2009);
+ Date end = null;
+
+ boolean result = DateUtil.between(middle, begin, end);
+ Assert.assertTrue(result);
+
+ // middle between the period : march 2009
+ PeriodDates period = new PeriodDates(begin, begin);
+ period.initDayOfMonthExtremities();
+
+ log.info("period : " + period);
+
+ result = DateUtil.between(middle, period.getFromDate(), period.getThruDate());
+ Assert.assertTrue(result);
+
+ // middle = period begin
+ middle = DateUtil.setFirstDayOfMonth(middle);
+ result = DateUtil.between(middle, period.getFromDate(), period.getThruDate());
+ Assert.assertTrue(result);
+
+ // test with different implementation of Date
+ Timestamp middle2 = new Timestamp(middle.getTime());
+ result = DateUtil.between(middle2, period.getFromDate(), period.getThruDate());
+ Assert.assertTrue(result);
+
+ // middle before begin
+ middle = DateUtil.createDate(2, 2, 2009);
+ result = DateUtil.between(middle, period.getFromDate(), period.getThruDate());
+ Assert.assertFalse(result);
+ }
+
+ /**
+ * Test of currentPeriod method, of class DateUtil.
+ */
+ //@Test
+ public void testCurrentPeriod() {
+ log.info("currentPeriod");
+ }
+
+ /**
+ * Test of getMonth method, of class DateUtil.
+ */
+ //@Test
+ public void testGetMonth() {
+ log.info("getMonth");
+ }
+
+ @Test
+ public void testGetDifferenceInSeconds() {
+ log.info("getDifferenceInSecondes");
+
+ Date beginDate = DateUtil.createDate(30, 10, 0, 3, 2, 2009);
+ Date endDate = DateUtil.createDate(0, 11, 0, 3, 2, 2009);
+
+ int result = DateUtil.getDifferenceInSeconds(beginDate, endDate);
+ Assert.assertEquals(30, result);
+
+ beginDate = DateUtil.createDate(9, 28, 0, 28, 1, 2009);
+ endDate = DateUtil.createDate(50, 30, 0, 28, 1, 2009);
+
+ result = DateUtil.getDifferenceInSeconds(beginDate, endDate);
+ Assert.assertEquals(161, result);
+ }
+
+ @Test
+ public void testGetDifferenceInMinutes() {
+ log.info("getDifferenceInMinutes");
+
+ Date beginDate = DateUtil.createDate(30, 10, 0, 3, 2, 2009);
+ Date endDate = DateUtil.createDate(0, 12, 0, 3, 2, 2009);
+
+ int result = DateUtil.getDifferenceInMinutes(beginDate, endDate);
+ Assert.assertEquals(1, result);
+
+ beginDate = DateUtil.createDate(9, 28, 0, 28, 1, 2009);
+ endDate = DateUtil.createDate(50, 30, 0, 28, 1, 2009);
+
+ result = DateUtil.getDifferenceInMinutes(beginDate, endDate);
+ Assert.assertEquals(2, result);
+ }
+
+ @Test
+ public void testGetDifferenceInHours() {
+ log.info("getDifferenceInHours");
+
+ Date beginDate = DateUtil.createDate(30, 10, 0, 3, 2, 2009);
+ Date endDate = DateUtil.createDate(0, 11, 0, 4, 2, 2009);
+
+ int result = DateUtil.getDifferenceInHours(beginDate, endDate);
+ Assert.assertEquals(24, result);
+
+ beginDate = DateUtil.createDate(9, 28, 0, 28, 1, 2009);
+ endDate = DateUtil.createDate(50, 30, 8, 28, 1, 2009);
+
+ result = DateUtil.getDifferenceInHours(beginDate, endDate);
+ Assert.assertEquals(8, result);
+ }
+
+ @Test
+ public void testGetDifferenceInDays() {
+ log.info("getDifferenceInDays");
+
+ Date beginDate = DateUtil.createDate(3, 2, 2009);
+ Date endDate = DateUtil.createDate(8, 2, 2009);
+
+ int result = DateUtil.getDifferenceInDays(beginDate, endDate);
+ Assert.assertEquals(5, result);
+
+ beginDate = DateUtil.createDate(28, 1, 2009);
+ endDate = DateUtil.createDate(8, 2, 2009);
+
+ result = DateUtil.getDifferenceInDays(beginDate, endDate);
+ Assert.assertEquals(11, result);
+ }
+
+ @Test
+ public void testGetDifferenceInMonths() {
+ log.info("getDifferenceInMonths");
+
+ Date beginDate = DateUtil.createDate(3, 2, 2009);
+ Date endDate = DateUtil.createDate(8, 8, 2010);
+
+ int result = DateUtil.getDifferenceInMonths(beginDate, endDate);
+ log.info("result1 : " + result);
+ Assert.assertEquals(19, result);
+
+ beginDate = DateUtil.createDate(1, 1, 2009);
+ endDate = DateUtil.createDate(28, 2, 2009);
+
+ result = DateUtil.getDifferenceInMonths(beginDate, endDate);
+ log.info("result2 : " + result);
+ Assert.assertEquals(2, result);
+
+ beginDate = DateUtil.createDate(31, 1, 2009);
+ endDate = DateUtil.createDate(1, 2, 2009);
+
+ result = DateUtil.getDifferenceInMonths(beginDate, endDate);
+ log.info("result3 : " + result);
+ Assert.assertEquals(1, result);
+ }
+
+ @Test
+ public void testGetMonthLibelle() {
+ log.info("getMonthLibelle");
+
+ Locale.setDefault(Locale.FRENCH);
+ String janvier = DateUtil.getMonthLibelle(1);
+ Assert.assertEquals("janvier", janvier);
+
+ String juli = DateUtil.getMonthLibelle(7, Locale.GERMAN);
+ Assert.assertEquals("Juli", juli);
+ }
+
+}
Modified: trunk/src/test/java/org/nuiton/util/DateUtilsTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/DateUtilsTest.java 2010-08-29 14:21:26 UTC (rev 1908)
+++ trunk/src/test/java/org/nuiton/util/DateUtilsTest.java 2010-08-29 14:34:29 UTC (rev 1909)
@@ -42,7 +42,9 @@
/**
*
* @author fdesbois
+ * @deprecated since 1.4.1, use now {@link DateUtilTest}
*/
+@Deprecated
public class DateUtilsTest {
/** Logger */
1
0
Author: tchemit
Date: 2010-08-29 16:21:26 +0200 (Sun, 29 Aug 2010)
New Revision: 1908
Url: http://nuiton.org/repositories/revision/nuiton-utils/1908
Log:
Utilisation de mavenpom4redmine 2.2.4
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-08-26 11:09:55 UTC (rev 1907)
+++ trunk/pom.xml 2010-08-29 14:21:26 UTC (rev 1908)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.2.3</version>
+ <version>2.2.4</version>
</parent>
<artifactId>nuiton-utils</artifactId>
1
0
r1907 - in trunk/src: main/java/org/nuiton/util main/resources/i18n test/java/org/nuiton/util
by tchemit@users.nuiton.org 26 Aug '10
by tchemit@users.nuiton.org 26 Aug '10
26 Aug '10
Author: tchemit
Date: 2010-08-26 13:09:55 +0200 (Thu, 26 Aug 2010)
New Revision: 1907
Url: http://nuiton.org/repositories/revision/nuiton-utils/1907
Log:
i18n
add some TODO and FIXME on none sane codes
improve code (reformat, javadoc, others...)
Modified:
trunk/src/main/java/org/nuiton/util/DateUtils.java
trunk/src/main/java/org/nuiton/util/DigestGenerator.java
trunk/src/main/java/org/nuiton/util/Log.java
trunk/src/main/java/org/nuiton/util/MD5InputStream.java
trunk/src/main/java/org/nuiton/util/ObjectUtil.java
trunk/src/main/java/org/nuiton/util/PeriodDates.java
trunk/src/main/java/org/nuiton/util/ReflectUtil.java
trunk/src/main/java/org/nuiton/util/Resource.java
trunk/src/main/java/org/nuiton/util/ResourceResolver.java
trunk/src/main/java/org/nuiton/util/ReverseFileReader.java
trunk/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java
trunk/src/main/java/org/nuiton/util/StringUtil.java
trunk/src/main/java/org/nuiton/util/TestUtil.java
trunk/src/main/java/org/nuiton/util/Version.java
trunk/src/main/java/org/nuiton/util/VersionUtil.java
trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties
trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties
trunk/src/test/java/org/nuiton/util/DateUtilsTest.java
trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java
Modified: trunk/src/main/java/org/nuiton/util/DateUtils.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/DateUtils.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/DateUtils.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -34,13 +34,12 @@
import java.util.Locale;
/**
+ * TODO tchemit 2010-08-25 : the name of the class does not fit, it should be called {@code DateUtil}.
* Library for manipulating dates.
*
* @author fdesbois
- * @version $Revision$
- *
- * Last update: $Date$
- * by : */
+ * @version $Id$
+ */
public class DateUtils {
public static final String DEFAULT_PATTERN = "dd/MM/yyyy";
Modified: trunk/src/main/java/org/nuiton/util/DigestGenerator.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/DigestGenerator.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/DigestGenerator.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -54,8 +54,12 @@
/**
* Helper class to provide the functionality of the digest value generation. This is an implementation of the DHASH
* algorithm on .
+ *
+ * TODO tchemit 2010-08-25 : This class is a nightmare ? we talk about digest mixed with dom nodes ?
+ * TODO tchemit 2010-08-25 : Should have more to explain the purpose (javadoc, author, since...) or (rename | split) this class.
*/
public class DigestGenerator {
+ public static final String UNICODE_BIG_UNMARKED = "UnicodeBigUnmarked";
/**
* This method is an overloaded method for the digest generation for Document
@@ -133,7 +137,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(1);
- dos.write(getExpandedName(element).getBytes("UnicodeBigUnmarked"));
+ dos.write(getExpandedName(element).getBytes(UNICODE_BIG_UNMARKED));
dos.write((byte) 0);
dos.write((byte) 0);
Collection attrs = getAttributesWithoutNS(element);
@@ -179,10 +183,10 @@
md.update((byte) 0);
md.update((byte) 0);
md.update((byte) 7);
- md.update(pi.getTarget().getBytes("UnicodeBigUnmarked"));
+ md.update(pi.getTarget().getBytes(UNICODE_BIG_UNMARKED));
md.update((byte) 0);
md.update((byte) 0);
- md.update(pi.getNodeValue().getBytes("UnicodeBigUnmarked"));
+ md.update(pi.getNodeValue().getBytes(UNICODE_BIG_UNMARKED));
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new Exception(e);
@@ -212,10 +216,10 @@
md.update((byte) 0);
md.update((byte) 2);
md.update(getExpandedName(attribute).getBytes(
- "UnicodeBigUnmarked"));
+ UNICODE_BIG_UNMARKED));
md.update((byte) 0);
md.update((byte) 0);
- md.update(attribute.getValue().getBytes("UnicodeBigUnmarked"));
+ md.update(attribute.getValue().getBytes(UNICODE_BIG_UNMARKED));
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new Exception(e);
@@ -242,7 +246,7 @@
md.update((byte) 0);
md.update((byte) 0);
md.update((byte) 3);
- md.update(text.getTextContent().getBytes("UnicodeBigUnmarked"));
+ md.update(text.getTextContent().getBytes(UNICODE_BIG_UNMARKED));
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new Exception(e);
Modified: trunk/src/main/java/org/nuiton/util/Log.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/Log.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/Log.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -68,7 +68,9 @@
* Log.logUserInfo("SAVE", "Sauvegarde réussie");
* Log.logTask("SAVE", "Sauvegarde terminée", 0, 0);
* </pre>
+ * @deprecated since 1.4.1, there should be some others libraries much better than that...
*/
+@Deprecated
public class Log { // Log
static private Log LOG_INSTANCE = new Log();
Modified: trunk/src/main/java/org/nuiton/util/MD5InputStream.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/MD5InputStream.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/MD5InputStream.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -35,6 +35,8 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import static org.nuiton.i18n.I18n._;
+
/**
* MD5InputStream, a subclass of FilterInputStream implementing MD5
* functionality on a stream.
@@ -46,13 +48,13 @@
/** Class logger. */
private static Log log = LogFactory.getLog(MD5InputStream.class);
- protected static MessageDigest getMD5Digest() {
+ protected static MessageDigest getMD5Digest() throws IllegalStateException {
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
return digest;
} catch (NoSuchAlgorithmException e) {
if (log.isErrorEnabled()) {
- log.error("Could not find algorithm MD5...", e);
+ log.error(_("nuitonutil.erro.could.not.find.MD5"), e);
}
throw new IllegalStateException(e);
}
Modified: trunk/src/main/java/org/nuiton/util/ObjectUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ObjectUtil.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/ObjectUtil.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -306,7 +306,7 @@
Constructor<T>[] constructors = (Constructor<T>[])clazz.getConstructors();
for (Constructor<T> c : constructors) {
if (paramNumber < 0 ||
- (c.isVarArgs() && c.getParameterTypes().length <= paramNumber - 1) ||
+ c.isVarArgs() && c.getParameterTypes().length <= paramNumber - 1 ||
c.getParameterTypes().length == paramNumber) {
result.add(c);
}
Modified: trunk/src/main/java/org/nuiton/util/PeriodDates.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/PeriodDates.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/PeriodDates.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -29,23 +29,18 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
+ * TODO tchemit 2010-08-25 JAVADOC + I18N
* PeriodDates.java
*
* Created on 2009-08-13
*
* @author fdesbois
- * @version $Revision$
- *
- * Last update: $Date$
- * by : */
+ * @version $Id$
+ */
public class PeriodDates {
- private static final Log log = LogFactory.getLog(PeriodDates.class);
-
private String pattern;
private Calendar fromCalendar;
Modified: trunk/src/main/java/org/nuiton/util/ReflectUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ReflectUtil.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/ReflectUtil.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -59,7 +59,9 @@
*/
public static boolean isConstantField(Field field) {
int modifiers = field.getModifiers();
- return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
+ return Modifier.isPublic(modifiers) &&
+ Modifier.isStatic(modifiers) &&
+ Modifier.isFinal(modifiers);
}
/**
@@ -75,13 +77,15 @@
* @throws RuntimeException si problème lors de la récupération
*/
@SuppressWarnings({"unchecked"})
- public static <T> List<T> getConstants(Class<?> klass, Class<T> searchingClass) {
+ public static <T> List<T> getConstants(Class<?> klass,
+ Class<T> searchingClass) {
List<T> result = new ArrayList<T>();
for (Field field : klass.getDeclaredFields()) {
if (!field.isAccessible()) {
field.setAccessible(true);
}
- if (searchingClass.isAssignableFrom(field.getType()) && isConstantField(field)) {
+ if (searchingClass.isAssignableFrom(field.getType()) &&
+ isConstantField(field)) {
try {
result.add((T) field.get(null));
} catch (IllegalAccessException e) {
Modified: trunk/src/main/java/org/nuiton/util/Resource.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/Resource.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/Resource.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -46,6 +46,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.String;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@@ -181,10 +182,10 @@
* @param filename le nom du fichier à rechercher
* @return l'objet Properties de configuration
* @throws IOException si une erreur est survenue
- * @deprecated since 1.1.2, use {@link org.nuiton.util.ApplicationConfig} class instead
- * to {@link org.nuiton.util.ApplicationConfig#setConfigFileName(java.lang.String) }
+ * @deprecated since 1.1.2, use {@link ApplicationConfig} class instead
+ * to {@link ApplicationConfig#setConfigFileName(String) }
* and search properties file from more folders with
- * {@link org.nuiton.util.ApplicationConfig#parse(java.lang.String[]) } method
+ * {@link ApplicationConfig#parse(String[]) } method
*/
@Deprecated
static public Properties getConfigProperties(String filename)
@@ -204,10 +205,10 @@
* @param parent les proprietes parent a surcharger
* @return l'objet Properties de configuration
* @throws IOException si une erreur est survenue
- * @deprecated since 1.1.2, use {@link org.nuiton.util.ApplicationConfig} class instead
- * to {@link org.nuiton.util.ApplicationConfig#setConfigFileName(java.lang.String) }
+ * @deprecated since 1.1.2, use {@link ApplicationConfig} class instead
+ * to {@link ApplicationConfig#setConfigFileName(String) }
* and search properties file from more folders with
- * {@link org.nuiton.util.ApplicationConfig#parse(java.lang.String[]) } method
+ * {@link ApplicationConfig#parse(String[]) } method
*/
@Deprecated
static public Properties getConfigProperties(String filename,
@@ -264,14 +265,15 @@
}
/**
- * Recupere la liste des urls d'un {@link java.net.URLClassLoader}.
+ * Recupere la liste des urls d'un {@link URLClassLoader}.
* <p/>
* Note : Un cas particulier est positionné pour JBoss qui utilise la method getAllURLs.
*
* @param classLoader le class loader a scanner
* @return les urls du classloade.
- * @deprecated should use now {@link org.nuiton.util.ClassLoaderUtil#getURLs(java.net.URLClassLoader)}
+ * @deprecated should use now {@link ClassLoaderUtil#getURLs(URLClassLoader)}
*/
+ @Deprecated
static public URL[] getURLs(URLClassLoader classLoader) {
return ClassLoaderUtil.getURLs(classLoader);
}
@@ -357,7 +359,7 @@
if (log.isDebugEnabled()) {
log.debug("jar to search " + file);
}
- urlList.addAll(Resource.getURLsFromJar(file, pattern));
+ urlList.addAll(getURLsFromJar(file, pattern));
continue;
}
if (file.isDirectory()) {
@@ -367,7 +369,7 @@
}
// on traite le cas ou il peut y avoir des repertoire dans ce
// repertoire
- urlList.addAll(Resource.getURLsFromDirectory(file, pattern));
+ urlList.addAll(getURLsFromDirectory(file, pattern));
continue;
}
@@ -376,7 +378,7 @@
if (log.isDebugEnabled()) {
log.debug("zip to search " + file);
}
- urlList.addAll(Resource.getURLsFromZip(file, pattern));
+ urlList.addAll(getURLsFromZip(file, pattern));
}
}
@@ -465,7 +467,7 @@
if (pattern == null || name.matches(pattern)) {
// on recupere le fichier correspondant au pattern dans le
// classloader
- URL url = Resource.getURL(name);
+ URL url = getURL(name);
// on ajoute le fichier correspondant au pattern dans la
// liste
if (log.isTraceEnabled()) {
@@ -506,7 +508,7 @@
if (pattern == null || name.matches(pattern)) {
// on recupere le fichier correspondant au pattern dans le
// classloader
- URL url = Resource.getURL(name);
+ URL url = getURL(name);
// on ajoute le fichier correspondant au pattern dans la
// liste
if (log.isTraceEnabled()) {
@@ -556,7 +558,7 @@
// cas de recursivite : repertoire dans un repertoire
if (file.exists() && file.isDirectory()) {
- urlList.addAll(Resource.getURLsFromDirectory(file,
+ urlList.addAll(getURLsFromDirectory(file,
pattern));
// si le fichier du repertoire n'est pas un repertoire
// on verifie s'il correspond au pattern
@@ -669,7 +671,7 @@
* @param url the url to seek
* @param directory the directory to find
* @return <code>true</code> if directory was found, <code>false</code> otherwise.
- * @throws java.io.IOException if any io pb
+ * @throws IOException if any io pb
*/
public static boolean containsDirectDirectory(URL url, String directory) throws IOException {
String fileName = url.getFile();
Modified: trunk/src/main/java/org/nuiton/util/ResourceResolver.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ResourceResolver.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/ResourceResolver.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -22,28 +22,27 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
-
+
package org.nuiton.util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashSet;
import java.util.List;
-
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.stream.StreamSource;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* ResourceResolver is a URIResolver for XSL transformation. <br/>
* Its purpose is to catch the XSL document(...) function call and return a
@@ -52,57 +51,52 @@
* The main goal of ResourceResolver is to retrieve datasources locally, if the
* wanted resource is not present in project resource then null will be
* returned.<br/>
- * <p>
+ * <p/>
* The resolve function search for the file part of href parameter: <br/>
* href: http://argouml.org/profiles/uml14/default-uml14.xmi <br/>
* file part: default-uml14.xmi. <br/>
* The resource is searched this way: <br/>
* eg: <code>[file part extension]/[file part]</code> <br/>
* eg: <code>xmi/default-uml14.xmi</code>
- * <p>
+ * <p/>
* You should assign this ResourceResolver on
* {@link Transformer} but not on
* {@link TransformerFactory}. <br/>
- *
+ *
* @author chorlet
* @version $Revision$
- *
- * Last update : $Date$
- * By : */
+ * <p/>
+ * Last update : $Date$
+ * By :
+ */
public class ResourceResolver implements URIResolver {
/** log. */
private static final Log log = LogFactory.getLog(ResourceResolver.class);
- /**
- * Shared Cache to not search in full classpath at each request.
- */
+
+ /** Shared Cache to not search in full classpath at each request. */
protected static final SortedMap<String, Source> sourceCache =
new TreeMap<String, Source>();
- /**
- * Shared Cache of not local resources
- */
+
+ /** Shared Cache of not local resources */
protected static final Set<String> unresolvedCache = new HashSet<String>();
- /**
- * le pattern de detection d'une uri
- */
+
+ /** le pattern de detection d'une uri */
public static final Pattern HREF_PATTERN =
Pattern.compile("([a-zA-Z]+)\\:\\/\\/(.+)");
- /**
- * Pour vider le cache partage.
- */
+ /** Pour vider le cache partage. */
public static synchronized void clearCache() {
sourceCache.clear();
unresolvedCache.clear();
}
+
protected String base;
- /**
- * le niveau de verbosite
- */
+
+ /** le niveau de verbosite */
protected boolean verbose = log.isDebugEnabled();
- /**
- * le classe loader utilise pour recuperer les resources
- */
+
+ /** le classe loader utilise pour recuperer les resources */
protected ClassLoader cl = getClass().getClassLoader();
public ResourceResolver() {
@@ -121,7 +115,7 @@
/**
* Resolve href on local resource.
- *
+ *
* @return null if local resource not found
*/
@Override
@@ -158,7 +152,7 @@
// relative path :
// example 3 : xxx/zzz/ttt.uml
- Source source = null;
+ Source source;
// if URI
Matcher matcher = HREF_PATTERN.matcher(href);
@@ -213,7 +207,7 @@
protected Source findHrefSource(String path) {
long t0 = System.nanoTime();
- String filename = null;
+ String filename;
int beginIndex = path.lastIndexOf('/');
if (beginIndex > -1) {
filename = path.substring(beginIndex + 1);
@@ -223,7 +217,7 @@
if (filename == null || filename.isEmpty()) {
return null;
}
- String resource = null;
+ String resource;
resource = ".*/" + filename;
@@ -283,7 +277,7 @@
// if (filename == null || filename.isEmpty()) {
// return null;
// }
- String resource = null;
+ String resource;
if (base != null) {
resource = base + "/" + filename;
} else {
Modified: trunk/src/main/java/org/nuiton/util/ReverseFileReader.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/ReverseFileReader.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/ReverseFileReader.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -34,12 +34,11 @@
* Reverse file reader.
*
* @author chatellier
- * @version $Revision$
+ * @version $ID: $
*
* TODO add an interface on it.
*
- * Last update : $Date$
- * By : */
+ */
public class ReverseFileReader implements Closeable {
protected String filename;
protected RandomAccessFile randomfile;
@@ -122,9 +121,6 @@
return finalLine;
}
- /*
- * @see java.io.Closeable#close()
- */
@Override
public void close() throws IOException {
if (randomfile != null) {
@@ -132,9 +128,6 @@
}
}
- /*
- * @see java.lang.Object#finalize()
- */
@Override
protected void finalize() throws Throwable {
close();
Modified: trunk/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -50,7 +50,7 @@
public static final int TT_KEYWORD = -101;
public static final int TT_VARIABLE = -102;
protected HashSet<String> keywords = new HashSet<String>();
- protected boolean lowerCaseKeyword = false;
+ protected boolean lowerCaseKeyword;
protected int quoteCharVariable = -1;
public StreamKeywordTokenizer(Reader in){
Modified: trunk/src/main/java/org/nuiton/util/StringUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/StringUtil.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/StringUtil.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -38,7 +38,6 @@
import java.awt.Color;
import java.lang.reflect.Field;
-import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.ParseException;
@@ -98,9 +97,9 @@
result += "O";
} else if ("ÙÛÜ".indexOf(c) != -1) {
result += "U";
- } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
- || ('0' <= c && c <= '9') || ('.' == c) || ('-' == c)
- || ('_' == c)) {
+ } else if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z'
+ || '0' <= c && c <= '9' || '.' == c || '-' == c
+ || '_' == c) {
result += c;
} else {
// on ne l'ajoute pas a result donc on supprime le caractere
@@ -178,7 +177,7 @@
if (o == null) {
continue;
}
- String str = null;
+ String str;
// Use ToString contract from argument
if (ts != null) {
str = ts.toString(o);
@@ -503,7 +502,9 @@
"d"};
/**
- * @param value
+ * Converts an time delay into a human readable format.
+ *
+ * @param value the delay to convert
* @return the memory representation of the given value
* @see #convert(long, double[], String[])
*/
@@ -512,8 +513,10 @@
}
/**
- * @param value
- * @param value2
+ * Converts an time period into a human readable format.
+ *
+ * @param value the begin time
+ * @param value2 the end time
* @return the time representation of the given value
* @see #convert(long, double[], String[])
*/
@@ -527,7 +530,9 @@
"To"};
/**
- * @param value
+ * Converts an memory measure into a human readable format.
+ *
+ * @param value the memory measure to convert
* @return the memory representation of the given value
* @see #convert(long, double[], String[])
*/
@@ -540,9 +545,9 @@
* (the {@link Locale#getDefault()}) in the method
* {@link MessageFormat#MessageFormat(String)}.
*
- * @param value
- * @param factors
- * @param unites
+ * @param value value to convert
+ * @param factors facotrs used form conversion
+ * @param unites libelle of unites to use
* @return the converted representation of the given value
*/
static public String convert(long value, double[] factors, String[] unites) {
@@ -652,9 +657,9 @@
*
* @param toEncode string concerned
* @return md5 corresponding
- * @throws NoSuchAlgorithmException if could not found algorithm MD5
+ * @throws IllegalStateException if could not found algorithm MD5
*/
- public static String encodeMD5(String toEncode) throws NoSuchAlgorithmException {
+ public static String encodeMD5(String toEncode) {
byte[] uniqueKey = toEncode.getBytes();
byte[] hash;
Modified: trunk/src/main/java/org/nuiton/util/TestUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/TestUtil.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/TestUtil.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -31,12 +31,14 @@
import java.io.IOException;
/**
+ * TODO tchemit 2010-08-25 : Why a Test thing is here ? Move it to the test and expose nuiton-utils with a test classifier.
+ *
* This class contains useful methods for Tests.
*
* Created: 22 juin 2010
*
* @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
+ * @version $Id:$
*/
public class TestUtil {
Modified: trunk/src/main/java/org/nuiton/util/Version.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/Version.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/Version.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -77,7 +77,7 @@
*/
protected final String classifier;
/**
- * optional classifier number (if no classifier should ne null)
+ * optional classifier number (if no classifier should be null)
*/
protected final Integer classifierNumber;
/**
@@ -217,18 +217,6 @@
return version;
}
-// On prefere ne pas confier de logique a l'objet, utiliser les methodes de VersionUtil
-// /**
-// * Incremente le numero de version dans une nouvelle version.
-// *
-// * Utilise par defaut, la methode {@link VersionUtil#inc(org.nuiton.util.Version)}.
-// *
-// * @return la version incrementee
-// */
-// public Version inc() {
-// Version result = VersionUtil.inc(this);
-// return result;
-// }
/**
* Convertit la representation textuelle de la version en identifiant java valide :
* - en java : "." interdit
Modified: trunk/src/main/java/org/nuiton/util/VersionUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/VersionUtil.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/java/org/nuiton/util/VersionUtil.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -25,15 +25,20 @@
package org.nuiton.util;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
import java.util.regex.Pattern;
/**
* Class of usefull methods on {@link Version} objects.
- *
+ * <p/>
* There is some factory methods : <code>valueOf(XXX)</code> to obtain a new
* version.
- *
+ * <p/>
* Some methods to transform a version (since version are immutable, we can not
* modify Version's property) :
* <pre>
@@ -50,17 +55,18 @@
/**
* Pattern pour detecter une version.
- *
+ * <p/>
* Le pattern possède toujours 3 groupes de captures.
- *
+ * <p/>
* - Le groupe 1 est le nombre de la version
* - Le groupe 2 est le classifier (peut-etre null)
* - Le groupe 3 est le numéro de classifier (peut-etre null)
- *
+ * <p/>
* Dans le cas d'une version simple (sans classifier), le groupe 2 et 3 sont null.
*/
public static final Pattern VERSION_PATTERN =
Pattern.compile("^(\\d+(?:\\.(?:\\d+))*)(?:-(\\w+?)-(\\d+?)){0,1}$");
+
/**
* Shared instance of default version comparator.
*
@@ -68,9 +74,8 @@
*/
public static final VersionComparator DEFAULT_VERSION_COMPARATOR =
new VersionComparator();
- /**
- * The snapshot suffix.
- */
+
+ /** The snapshot suffix. */
public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
/**
@@ -87,9 +92,10 @@
/**
* Recuperation d'une instance de version.
*
- * @param classifier le classifier (peut-etre null)
- * @param classifierNumber la version du classifier (doit etre null si le classifier est null)
- * @param numbers les nombres de la version
+ * @param classifier le classifier (peut-etre null)
+ * @param classifierNumber la version du classifier (doit etre null si le
+ * classifier est null)
+ * @param numbers les nombres de la version
* @return l'instance de la version requise
*/
public static Version valueOf(String classifier,
@@ -113,12 +119,14 @@
* Construction d'une nouvelle version avec un classifier a partir d'une
* version donnee.
*
- * @param version la version de base (sans classifier)
- * @param classifier le classifier a ajouter
+ * @param version la version de base (sans classifier)
+ * @param classifier le classifier a ajouter
* @param classifierNumber la version du classifier a ajouter
* @return l'instance de la version requise
- * @throws NullPointerException si le classifier ou le classifierNumber est null.
- * @throws IllegalArgumentException si la version donnee contient deja un classifier.
+ * @throws NullPointerException si le classifier ou le
+ * classifierNumber est null.
+ * @throws IllegalArgumentException si la version donnee contient deja un
+ * classifier.
*/
public static Version addClassifier(Version version,
String classifier,
@@ -163,7 +171,7 @@
/**
* Incremente le numero de version donnee, seul le dernier constituant est
* incremente: 1.2.3.4 -> 1.2.3.5; null -> 1; 0 -> 1.
- *
+ * <p/>
* Si la version a un classifier, alors c'est la version du classifier qui
* change : 1.1-alpha-12 -> 1.1-alpha-13
*
@@ -191,7 +199,6 @@
* Remove the suffix <code>-SNAPSHOT</code> stamp from a version (if any).
*
* @param version the string representation of the version
- *
* @return the string representation of the given version
* without the <code>-SNAPSHOT</code> suffix (if any).
* @throws NullPointerException if version is null
@@ -210,10 +217,10 @@
/**
* Filter versions.
- *
- * @param versions versions to filter
- * @param min min version to accept
- * @param max max version to accept
+ *
+ * @param versions versions to filter
+ * @param min min version to accept
+ * @param max max version to accept
* @param includeMin flag to include min version
* @param includeMax flag to include max version
* @return versions between min and max
@@ -228,7 +235,6 @@
int t;
if (min != null) {
t = v.compareTo(min);
-// if (v.compareTo(min) <= 0) {
if (t < 0 || t == 0 && !includeMin) {
// version trop ancienne
continue;
@@ -236,7 +242,6 @@
}
if (max != null) {
t = v.compareTo(max);
-// if (v.compareTo(max) > 0) {
if (t > 0 || t == 0 && !includeMax) {
// version trop recente
continue;
@@ -250,21 +255,22 @@
/**
* L'implantation d'un comparateur de versions permettant de controler
* l'ordre du numero de version, classifier et numero de classifer.
- *
+ * <p/>
* Toute implementation de ce contrat devrait suivre cet algorithme :
- *
+ * <p/>
* 1) Si versions égales, on quitte.
- *
+ * <p/>
* 2) On teste l'ordre des nombres {@link #compareNumbers(Version, Version)}
- *
+ * <p/>
* Si différent, alors versions différentes, on quitte
- *
- * 3) On teste l'ordre des classifiers {@link #compareClassifier(Version, Version)}
- *
+ * <p/>
+ * 3) On teste l'ordre des classifiers
+ * {@link #compareClassifier(Version, Version)}
+ * <p/>
* Si différent, alors versions différentes, on quitte
- *
- * 4) On teste l'ordre des versions de classifiers {@link #compareClassifierNumber(Version, Version)}.
- *
+ * <p/>
+ * 4) On teste l'ordre des versions de classifiers
+ * {@link #compareClassifierNumber(Version, Version)}.
*/
public static class VersionComparator implements Comparator<Version> {
@@ -399,8 +405,9 @@
/**
* Trier un ensemble de versions données en entrees
+ * <p/>
+ * On affiche le resultat dans la console
*
- * On affiche le resultat dans la console
* @param args les versions
*/
public static void main(String... args) {
@@ -409,10 +416,9 @@
List<Version> snapshots = new ArrayList<Version>();
for (String a : args) {
- //System.err.println("convert value : " + a);
- if (a.endsWith("-SNAPSHOT")) {
+ if (a.endsWith(SNAPSHOT_SUFFIX)) {
snapshots.add(valueOf(
- a.substring(0, a.length() - "-SNAPSHOT".length())));
+ a.substring(0, a.length() - VersionUtil.SNAPSHOT_SUFFIX.length())));
continue;
}
Version v = valueOf(a);
@@ -429,18 +435,18 @@
if (list.contains(snap)) {
// on ajoute juste avant
int index = asString.indexOf(v);
- asString.add(index, v + "-SNAPSHOT");
+ asString.add(index, v + SNAPSHOT_SUFFIX);
} else {
// ajout dans la liste initiale
list.add(snap);
Collections.sort(list);
int index = list.indexOf(snap);
if (index == 0) {
- asString.add(0, v + "-SNAPSHOT");
+ asString.add(0, v + SNAPSHOT_SUFFIX);
} else {
Version v2 = list.get(index - 1);
index = asString.indexOf(v2.toString());
- asString.add(index + 1, v + "-SNAPSHOT");
+ asString.add(index + 1, v + SNAPSHOT_SUFFIX);
}
list.remove(snap);
}
Modified: trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/resources/i18n/nuiton-utils-en_GB.properties 2010-08-26 11:09:55 UTC (rev 1907)
@@ -2,10 +2,13 @@
nuitonutil.debug.objectutil.create=Try to create %s with %s
nuitonutil.debug.objectutil.instantiate=Can't instantiate %s with params %s
nuitonutil.debug.objectutil.invoke=Invoke %s with %s
+nuitonutil.erro.could.not.find.MD5=Could not find MD5 algorithm
nuitonutil.error.add.url.in.classloader=Can't add url in classloader %1$s for reason %2$s
nuitonutil.error.applicationconfig.save=Can't save config in file %s
nuitonutil.error.convert.file.to.url=Can't convert %s for reason %s
nuitonutil.error.convertor.noValue=No value specified for converter %s
+nuitonutil.error.could.not.addPCL=Could not add the PropertychangeListener %1$s on object %2$s for following reason \: %3$s
+nuitonutil.error.could.not.removePCL=Could remove the PropertychangeListener %1$s from object %2$s for following reason \: %3$s
nuitonutil.error.get.url.from.zip=Error while reading %s \: %s
nuitonutil.error.no.convertor=no convertor found for type %2$s and objet '%1$s'
nuitonutil.error.not.an.enum=The type %1$s ins not an Enum type
Modified: trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/main/resources/i18n/nuiton-utils-fr_FR.properties 2010-08-26 11:09:55 UTC (rev 1907)
@@ -2,10 +2,13 @@
nuitonutil.debug.objectutil.create=Essaye de cr\u00E9er %s avec %s
nuitonutil.debug.objectutil.instantiate=Ne peut pas instancier %s avec les param\u00EAtres %s
nuitonutil.debug.objectutil.invoke=Invocation de %s avec %s
+nuitonutil.erro.could.not.find.MD5=L'algorithme MD5 n'a pas \u00E9t\u00E9 trouv\u00E9\!
nuitonutil.error.add.url.in.classloader=Impossible d'ajouter une url dans le classloader %s pour la raison \: %s
nuitonutil.error.applicationconfig.save=Impossible de sauvegarder le fichier de configuration dans %s
nuitonutil.error.convert.file.to.url=Le fichier '%1$s' n'a pas pu \u00EAtre converti en URL pour la raison suivante \: %2$S
nuitonutil.error.convertor.noValue=Aucune valeur \u00E0 convertir pour le convertisseur %s
+nuitonutil.error.could.not.addPCL=N'a pas pu ajout\u00E9 le PropertychangeListener %1$s sur l'objet %2$s pour la raison suivante \: %3$s
+nuitonutil.error.could.not.removePCL=N'a pas pu enlev\u00E9 le PropertychangeListener %1$s sur l'objet %2$s pour la raison suivante \: %3$s
nuitonutil.error.get.url.from.zip=Erreur lors de la lecture du fichier compress\u00E9 %1$s \: %2$s
nuitonutil.error.no.convertor=Aucun convertisseur trouv\u00E9 pour le type %2$s et l''objet '%1$s'
nuitonutil.error.not.an.enum=Le type %1$s n'est pas une enumeration java
Modified: trunk/src/test/java/org/nuiton/util/DateUtilsTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/DateUtilsTest.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/test/java/org/nuiton/util/DateUtilsTest.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -25,24 +25,28 @@
package org.nuiton.util;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import org.junit.Assert;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
/**
*
* @author fdesbois
*/
public class DateUtilsTest {
- public DateUtilsTest() {
- }
+ /** Logger */
+ private static final Log log = LogFactory.getLog(DateUtilsTest.class);
@BeforeClass
public static void setUpClass() throws Exception {
@@ -65,7 +69,7 @@
*/
//@Test
public void testFormatDate() {
- System.out.println("formatDate");
+ log.info("formatDate");
}
/**
@@ -73,7 +77,7 @@
*/
//@Test
public void testParseDate() {
- System.out.println("parseDate");
+ log.info("parseDate");
}
/**
@@ -81,7 +85,7 @@
*/
@Test
public void testCreateDate() {
- System.out.println("createDate");
+ log.info("createDate");
Date newdate = DateUtils.createDate(3, 3, 2009);
Calendar calendar = DateUtils.getDefaultCalendar(newdate);
@@ -101,7 +105,7 @@
*/
//@Test
public void testCreateDateAfterToday() {
- System.out.println("createDateAfterToday");
+ log.info("createDateAfterToday");
}
/**
@@ -109,7 +113,7 @@
*/
//@Test
public void testSetLastDayOfMonth() {
- System.out.println("setLastDayOfMonth");
+ log.info("setLastDayOfMonth");
}
/**
@@ -117,7 +121,7 @@
*/
//@Test
public void testSetFirstDayOfMonth() {
- System.out.println("setFirstDayOfMonth");
+ log.info("setFirstDayOfMonth");
}
/**
@@ -125,7 +129,7 @@
*/
@Test
public void testBetween() {
- System.out.println("between");
+ log.info("between");
Date middle = DateUtils.createDate(3, 3, 2009);
@@ -140,7 +144,7 @@
PeriodDates period = new PeriodDates(begin, begin);
period.initDayOfMonthExtremities();
- System.out.println("period : " + period);
+ log.info("period : " + period);
result = DateUtils.between(middle, period.getFromDate(), period.getThruDate());
Assert.assertTrue(result);
@@ -151,7 +155,7 @@
Assert.assertTrue(result);
// test with different implementation of Date
- java.sql.Timestamp middle2 = new java.sql.Timestamp(middle.getTime());
+ Timestamp middle2 = new Timestamp(middle.getTime());
result = DateUtils.between(middle2, period.getFromDate(), period.getThruDate());
Assert.assertTrue(result);
@@ -166,7 +170,7 @@
*/
//@Test
public void testCurrentPeriod() {
- System.out.println("currentPeriod");
+ log.info("currentPeriod");
}
/**
@@ -174,15 +178,15 @@
*/
//@Test
public void testGetMonth() {
- System.out.println("getMonth");
+ log.info("getMonth");
}
@Test
public void testGetDifferenceInSeconds() {
- System.out.println("getDifferenceInSecondes");
+ log.info("getDifferenceInSecondes");
Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009);
- Date endDate = DateUtils.createDate(00, 11, 0, 3, 2, 2009);
+ Date endDate = DateUtils.createDate(0, 11, 0, 3, 2, 2009);
int result = DateUtils.getDifferenceInSeconds(beginDate, endDate);
Assert.assertEquals(30, result);
@@ -196,10 +200,10 @@
@Test
public void testGetDifferenceInMinutes() {
- System.out.println("getDifferenceInMinutes");
+ log.info("getDifferenceInMinutes");
Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009);
- Date endDate = DateUtils.createDate(00, 12, 0, 3, 2, 2009);
+ Date endDate = DateUtils.createDate(0, 12, 0, 3, 2, 2009);
int result = DateUtils.getDifferenceInMinutes(beginDate, endDate);
Assert.assertEquals(1, result);
@@ -213,10 +217,10 @@
@Test
public void testGetDifferenceInHours() {
- System.out.println("getDifferenceInHours");
+ log.info("getDifferenceInHours");
Date beginDate = DateUtils.createDate(30, 10, 0, 3, 2, 2009);
- Date endDate = DateUtils.createDate(00, 11, 0, 4, 2, 2009);
+ Date endDate = DateUtils.createDate(0, 11, 0, 4, 2, 2009);
int result = DateUtils.getDifferenceInHours(beginDate, endDate);
Assert.assertEquals(24, result);
@@ -230,7 +234,7 @@
@Test
public void testGetDifferenceInDays() {
- System.out.println("getDifferenceInDays");
+ log.info("getDifferenceInDays");
Date beginDate = DateUtils.createDate(3, 2, 2009);
Date endDate = DateUtils.createDate(8, 2, 2009);
@@ -247,33 +251,33 @@
@Test
public void testGetDifferenceInMonths() {
- System.out.println("getDifferenceInMonths");
+ log.info("getDifferenceInMonths");
Date beginDate = DateUtils.createDate(3, 2, 2009);
Date endDate = DateUtils.createDate(8, 8, 2010);
int result = DateUtils.getDifferenceInMonths(beginDate, endDate);
- System.out.println("result1 : " + result);
+ log.info("result1 : " + result);
Assert.assertEquals(19, result);
beginDate = DateUtils.createDate(1, 1, 2009);
endDate = DateUtils.createDate(28, 2, 2009);
result = DateUtils.getDifferenceInMonths(beginDate, endDate);
- System.out.println("result2 : " + result);
+ log.info("result2 : " + result);
Assert.assertEquals(2, result);
beginDate = DateUtils.createDate(31, 1, 2009);
endDate = DateUtils.createDate(1, 2, 2009);
result = DateUtils.getDifferenceInMonths(beginDate, endDate);
- System.out.println("result3 : " + result);
+ log.info("result3 : " + result);
Assert.assertEquals(1, result);
}
@Test
public void testGetMonthLibelle() {
- System.out.println("getMonthLibelle");
+ log.info("getMonthLibelle");
Locale.setDefault(Locale.FRENCH);
String janvier = DateUtils.getMonthLibelle(1);
Modified: trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java 2010-08-26 11:08:53 UTC (rev 1906)
+++ trunk/src/test/java/org/nuiton/util/PeriodDatesTest.java 2010-08-26 11:09:55 UTC (rev 1907)
@@ -25,10 +25,8 @@
package org.nuiton.util;
-import java.text.DateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -36,15 +34,18 @@
import org.junit.BeforeClass;
import org.junit.Test;
-/**
- *
- * @author fdesbois
- */
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/** @author fdesbois */
public class PeriodDatesTest {
- public PeriodDatesTest() {
- }
+ /** Logger */
+ private static final Log log = LogFactory.getLog(PeriodDatesTest.class);
+
@BeforeClass
public static void setUpClass() throws Exception {
}
@@ -61,84 +62,64 @@
public void tearDown() {
}
- /**
- * Test of createMonthsPeriodFromToday method, of class PeriodDates.
- */
+ /** Test of createMonthsPeriodFromToday method, of class PeriodDates. */
//@Test
public void testCreateMonthsPeriodFromToday() {
- System.out.println("createMonthsPeriodFromToday");
+ log.info("createMonthsPeriodFromToday");
}
- /**
- * Test of getPattern method, of class PeriodDates.
- */
+ /** Test of getPattern method, of class PeriodDates. */
//@Test
public void testGetPattern() {
- System.out.println("getPattern");
+ log.info("getPattern");
}
- /**
- * Test of setPattern method, of class PeriodDates.
- */
+ /** Test of setPattern method, of class PeriodDates. */
//@Test
public void testSetPattern() {
- System.out.println("setPattern");
+ log.info("setPattern");
}
- /**
- * Test of initDayOfMonthExtremities method, of class PeriodDates.
- */
+ /** Test of initDayOfMonthExtremities method, of class PeriodDates. */
//@Test
public void testInitDayOfMonthExtremities() {
- System.out.println("initDayOfMonthExtremities");
+ log.info("initDayOfMonthExtremities");
}
- /**
- * Test of setFromDate method, of class PeriodDates.
- */
+ /** Test of setFromDate method, of class PeriodDates. */
//@Test
public void testSetFromDate() {
- System.out.println("setFromDate");
+ log.info("setFromDate");
}
- /**
- * Test of getFromDate method, of class PeriodDates.
- */
+ /** Test of getFromDate method, of class PeriodDates. */
//@Test
public void testGetFromDate() {
- System.out.println("getFromDate");
+ log.info("getFromDate");
}
- /**
- * Test of getFromMonth method, of class PeriodDates.
- */
+ /** Test of getFromMonth method, of class PeriodDates. */
//@Test
public void testGetFromMonth() {
- System.out.println("getFromMonth");
+ log.info("getFromMonth");
}
- /**
- * Test of setThruDate method, of class PeriodDates.
- */
+ /** Test of setThruDate method, of class PeriodDates. */
//@Test
public void testSetThruDate() {
- System.out.println("setThruDate");
+ log.info("setThruDate");
}
- /**
- * Test of getThruDate method, of class PeriodDates.
- */
+ /** Test of getThruDate method, of class PeriodDates. */
//@Test
public void testGetThruDate() {
- System.out.println("getThruDate");
+ log.info("getThruDate");
}
- /**
- * Test of getMonths method, of class PeriodDates.
- */
+ /** Test of getMonths method, of class PeriodDates. */
@Test
public void testGetMonths() {
- System.out.println("getMonths");
+ log.info("getMonths");
// Prepare two calendars with time not equals to 0
Calendar cal1 = DateUtils.getDefaultCalendar(new Date());
@@ -148,8 +129,8 @@
cal1.set(Calendar.HOUR, 8);
DateFormat timeFormat = DateFormat.getTimeInstance();
- System.out.println("getMonths:: time for calendarFrom : " +
- timeFormat.format(cal1.getTime()));
+ log.info("getMonths:: time for calendarFrom : " +
+ timeFormat.format(cal1.getTime()));
Calendar cal2 = DateUtils.getDefaultCalendar(new Date());
cal2.set(Calendar.DAY_OF_MONTH, 22);
@@ -157,8 +138,8 @@
cal2.set(Calendar.YEAR, 2009);
cal2.set(Calendar.HOUR, 4);
- System.out.println("getMonths:: time for calendarThru : " +
- timeFormat.format(cal2.getTime()));
+ log.info("getMonths:: time for calendarThru : " +
+ timeFormat.format(cal2.getTime()));
PeriodDates period = new PeriodDates(cal1, cal2);
@@ -167,88 +148,68 @@
for (int i = 0; i < 5; i++) {
Date monthDate = months.get(i);
int month = DateUtils.getDefaultCalendar(monthDate).get(Calendar.MONTH);
- Assert.assertEquals(i+2, month); // 2, 3, 4, 5, 6
+ Assert.assertEquals(i + 2, month); // 2, 3, 4, 5, 6
}
}
- /**
- * Test of getFormatedMonths method, of class PeriodDates.
- */
+ /** Test of getFormatedMonths method, of class PeriodDates. */
//@Test
public void testGetFormatedMonths() {
- System.out.println("getFormatedMonths");
+ log.info("getFormatedMonths");
}
- /**
- * Test of beforeEnd method, of class PeriodDates.
- */
+ /** Test of beforeEnd method, of class PeriodDates. */
//@Test
public void testBeforeEnd_Calendar() {
- System.out.println("beforeEnd");
+ log.info("beforeEnd");
}
- /**
- * Test of afterEnd method, of class PeriodDates.
- */
+ /** Test of afterEnd method, of class PeriodDates. */
//@Test
public void testAfterEnd_Calendar() {
- System.out.println("afterEnd");
+ log.info("afterEnd");
}
- /**
- * Test of afterBegin method, of class PeriodDates.
- */
+ /** Test of afterBegin method, of class PeriodDates. */
//@Test
public void testAfterBegin_Calendar() {
- System.out.println("afterBegin");
+ log.info("afterBegin");
}
- /**
- * Test of between method, of class PeriodDates.
- */
+ /** Test of between method, of class PeriodDates. */
//@Test
public void testBetween_Calendar() {
- System.out.println("between");
+ log.info("between");
}
- /**
- * Test of beforeEnd method, of class PeriodDates.
- */
+ /** Test of beforeEnd method, of class PeriodDates. */
//@Test
public void testBeforeEnd_Date() {
- System.out.println("beforeEnd");
+ log.info("beforeEnd");
}
- /**
- * Test of afterEnd method, of class PeriodDates.
- */
+ /** Test of afterEnd method, of class PeriodDates. */
//@Test
public void testAfterEnd_Date() {
- System.out.println("afterEnd");
+ log.info("afterEnd");
}
- /**
- * Test of afterBegin method, of class PeriodDates.
- */
+ /** Test of afterBegin method, of class PeriodDates. */
//@Test
public void testAfterBegin_Date() {
- System.out.println("afterBegin");
+ log.info("afterBegin");
}
- /**
- * Test of between method, of class PeriodDates.
- */
+ /** Test of between method, of class PeriodDates. */
//@Test
public void testBetween_Date() {
- System.out.println("between");
+ log.info("between");
}
- /**
- * Test of toString method, of class PeriodDates.
- */
+ /** Test of toString method, of class PeriodDates. */
//@Test
public void testToString() {
- System.out.println("toString");
+ log.info("toString");
}
}
1
0
r1906 - in trunk/src: main/java/org/nuiton/util/beans test/java/org/nuiton/util/beans
by tchemit@users.nuiton.org 26 Aug '10
by tchemit@users.nuiton.org 26 Aug '10
26 Aug '10
Author: tchemit
Date: 2010-08-26 13:08:53 +0200 (Thu, 26 Aug 2010)
New Revision: 1906
Url: http://nuiton.org/repositories/revision/nuiton-utils/1906
Log:
Evolution #820: Introduce BeanMonitor api
Added:
trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java
trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
Modified:
trunk/src/test/java/org/nuiton/util/beans/BeanA.java
trunk/src/test/java/org/nuiton/util/beans/BeanB.java
Added: trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java (rev 0)
+++ trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2010-08-26 11:08:53 UTC (rev 1906)
@@ -0,0 +1,201 @@
+package org.nuiton.util.beans;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * A monitor of beans.
+ * <p/>
+ * You indicates which properties to monitor (via the constructor).
+ * <p/>
+ * Then attach a bean to monitor via the method {@link #setBean(Object)}.
+ * <p/>
+ * The method {@link #clearModified()} reset the states about modified
+ * properties.
+ * <p/>
+ * The method {@link #wasModified()} tells if there was any modification on
+ * monitored properties for the attached bean since the last call to
+ * {@link #clearModified()} (or {@link #setBean(Object)}.
+ * <p/>
+ * the method {@link #getModifiedProperties()} gives you the names of monitored
+ * properties for the attached bean since the last call to
+ * {@link #clearModified()} (or {@link #setBean(Object)}.
+ *
+ * @author chemit <chemit(a)codelutin.com>
+ * @since 1.4.1
+ */
+public class BeanMonitor {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(BeanMonitor.class);
+
+ /** Names of properties to watch on attached bean. */
+ protected final List<String> propertyNames;
+
+ /** Names of monitored and modified properties for the attached bean. */
+ protected final Set<String> modifiedProperties;
+
+ /** To store the original values when watched properties are changing. */
+ protected final Map<String, Object> originalValues;
+
+ /**
+ * The {@link PropertyChangeListener} which listen modification on bean
+ * only on monitored properties.
+ */
+ protected final PropertyChangeListener listener;
+
+ /** The bean to monitor. */
+ protected Object bean;
+
+ /**
+ * Constructor of monitor with property names to monitor.
+ *
+ * @param propertyNames the names of properties to monitor
+ */
+ public BeanMonitor(String... propertyNames) {
+ this.propertyNames = Arrays.asList(propertyNames);
+ modifiedProperties = new LinkedHashSet<String>();
+ originalValues = new TreeMap<String, Object>();
+ listener = new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ String propertyName = evt.getPropertyName();
+ if (!BeanMonitor.this.propertyNames.contains(propertyName)) {
+ return;
+ }
+
+ // the property is monitored
+
+ Object newValue = evt.getNewValue();
+ Object oldValue = evt.getOldValue();
+
+ if (modifiedProperties.contains(propertyName)) {
+
+ // property already modified
+ // check if value did not come back to original
+ Object originalValue = originalValues.get(propertyName);
+
+ if (originalValue == null && newValue == null ||
+ originalValue != null && originalValue.equals(newValue)) {
+
+ // coming back to original value
+ // the property is no more modified
+ modifiedProperties.remove(propertyName);
+ originalValues.remove(propertyName);
+ return;
+ }
+
+ // can safely return since original is already known
+ // and property is already known to be modified
+ return;
+ }
+
+ // the property was not modified before
+ // just mark it and keep the original value
+ modifiedProperties.add(propertyName);
+ originalValues.put(propertyName, oldValue);
+ }
+ };
+ }
+
+ /**
+ * Obtains the monitored {@link #bean}.
+ *
+ * @return the attached bean, or {@code null} if none attached.
+ */
+ public Object getBean() {
+ return bean;
+ }
+
+ /**
+ * Tells if any of the monitored properties were modified on the attached
+ * bean since last call to {@link #clearModified()} or
+ * {@link #setBean(Object)}.
+ *
+ * @return {@code true} if there were a modified monitored property on
+ * the attached bean, {@code false} otherwise.
+ */
+ public boolean wasModified() {
+ return !modifiedProperties.isEmpty();
+ }
+
+ /**
+ * Obtains the names of monitored properties which has been touched for the
+ * attached bean since last call to {@link #clearModified()} or
+ * {@link #setBean(Object)}.
+ *
+ * @return the array of property names to monitor.
+ */
+ public String[] getModifiedProperties() {
+ return modifiedProperties.toArray(new String[modifiedProperties.size()]);
+ }
+
+ /**
+ * Obtains the original values for all modified properties.
+ *
+ * @return the dictionnary of original values for modified properties
+ */
+ public Map<String, Object> getOriginalValues() {
+
+ // always expose a copy of map
+ Map<String, Object> map = new TreeMap<String, Object>(originalValues);
+ return map;
+ }
+
+ /**
+ * Sets the {@code bean} to monitor.
+ * <p/>
+ * As a side effect, it will attach the {@link #listener} to new bean
+ * (if not null) and remove it from the previous bean attached (if not null).
+ * <p/>
+ * As a second side effect, it will always clean the modified states,
+ * using the method {@link #clearModified()}.
+ *
+ * @param bean the new bean to monitor
+ */
+ public void setBean(Object bean) {
+ Object oldBean = this.bean;
+ this.bean = bean;
+
+ // while removing a bean must clean modified states
+ clearModified();
+
+ if (oldBean != null) {
+
+ // dettach listener from old bean
+ try {
+ BeanUtil.removePropertyChangeListener(listener, oldBean);
+ } catch (Exception eee) {
+ log.error(_("nuitonutil.error.could.not.removePCL",
+ listener, oldBean, eee.getMessage()));
+ }
+ }
+ if (bean != null) {
+
+ // attach listener to new bean
+ try {
+ BeanUtil.addPropertyChangeListener(listener, bean);
+ } catch (Exception eee) {
+ log.error(_("nuitonutil.error.could.not.addPCL",
+ listener, bean, eee.getMessage()));
+ }
+ }
+ }
+
+ /** To clear the modified states. */
+ public void clearModified() {
+ modifiedProperties.clear();
+ originalValues.clear();
+ }
+}
Added: trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java (rev 0)
+++ trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java 2010-08-26 11:08:53 UTC (rev 1906)
@@ -0,0 +1,77 @@
+package org.nuiton.util.beans;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Usefull methods around the {@link PropertyChangeListener}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.1
+ */
+public class BeanUtil {
+
+ protected BeanUtil() {
+ // no instance
+ }
+
+ /**
+ * Add the given {@code listener} to the given {@code bean} using the
+ * normalized method named {@code addPropertyChangeListener}.
+ *
+ * @param listener the listener to add
+ * @param bean the bean on which the listener is added
+ * @throws InvocationTargetException if could not invoke the method
+ * {@code addPropertyChangeListener}
+ * @throws NoSuchMethodException if method
+ * {@code addPropertyChangeListener}
+ * does not exist on given bean
+ * @throws IllegalAccessException if an illegal access occurs when
+ * invoking the method
+ * {@code addPropertyChangeListener}
+ */
+ public static void addPropertyChangeListener(PropertyChangeListener listener,
+ Object bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+ MethodUtils.invokeExactMethod(bean,
+ "addPropertyChangeListener",
+ new Object[]{listener},
+ new Class[]{PropertyChangeListener.class}
+ );
+ }
+
+ /**
+ * Remove the given {@code listener} from the given {@code bean} using the
+ * normalized method named {@code removePropertyChangeListener}.
+ *
+ * @param listener the listener to remove
+ * @param bean the bean on which the listener is removed
+ * @throws InvocationTargetException if could not invoke the method
+ * {@code removePropertyChangeListener}
+ * @throws NoSuchMethodException if method
+ * {@code removePropertyChangeListener}
+ * does not exist on given bean
+ * @throws IllegalAccessException if an illegal access occurs when
+ * invoking the method
+ * {@code removePropertyChangeListener}
+ */
+ public static void removePropertyChangeListener(PropertyChangeListener listener,
+ Object bean) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+ MethodUtils.invokeExactMethod(bean,
+ "removePropertyChangeListener",
+ new Object[]{listener},
+ new Class[]{PropertyChangeListener.class}
+ );
+ }
+}
Modified: trunk/src/test/java/org/nuiton/util/beans/BeanA.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/beans/BeanA.java 2010-08-11 14:46:50 UTC (rev 1905)
+++ trunk/src/test/java/org/nuiton/util/beans/BeanA.java 2010-08-26 11:08:53 UTC (rev 1906)
@@ -25,26 +25,37 @@
package org.nuiton.util.beans;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
public class BeanA {
public static final String PROPERTY_A = "a";
+
public static final String PROPERTY_B = "b";
+
public static final String PROPERTY_C = "c";
+
public static final String PROPERTY_D = "d";
+
public static final String PROPERTY_E = "e";
+
public static final String PROPERTY_F = "f";
- String a, b, c, d;
+ protected String a, b, c, d;
+ protected int e, f;
- int e, f;
+ protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public String getA() {
return a;
}
public void setA(String a) {
+ Object oldValue = this.a;
this.a = a;
+ firePropertyChange(PROPERTY_A, oldValue, a);
}
public String getB() {
@@ -52,7 +63,9 @@
}
public void setB(String b) {
+ Object oldValue = this.b;
this.b = b;
+ firePropertyChange(PROPERTY_B, oldValue, b);
}
public String getC() {
@@ -60,7 +73,9 @@
}
public void setC(String c) {
+ Object oldValue = this.c;
this.c = c;
+ firePropertyChange(PROPERTY_C, oldValue, c);
}
public String getD() {
@@ -68,7 +83,9 @@
}
public void setD(String d) {
+ Object oldValue = this.d;
this.d = d;
+ firePropertyChange(PROPERTY_D, oldValue, d);
}
public int getE() {
@@ -76,7 +93,9 @@
}
public void setE(int e) {
+ Object oldValue = this.e;
this.e = e;
+ firePropertyChange(PROPERTY_E, oldValue, e);
}
public int getF() {
@@ -84,6 +103,31 @@
}
public void setF(int f) {
+ Object oldValue = this.f;
this.f = f;
+ firePropertyChange(PROPERTY_F, oldValue, f);
}
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue,
+ Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
}
Modified: trunk/src/test/java/org/nuiton/util/beans/BeanB.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/beans/BeanB.java 2010-08-11 14:46:50 UTC (rev 1905)
+++ trunk/src/test/java/org/nuiton/util/beans/BeanB.java 2010-08-26 11:08:53 UTC (rev 1906)
@@ -28,21 +28,29 @@
public class BeanB extends BeanA {
public static final String PROPERTY_A2 = "a2";
+
public static final String PROPERTY_B2 = "b2";
+
public static final String PROPERTY_C2 = "c2";
+
public static final String PROPERTY_D2 = "d2";
- public static final String PROPERTY_E2 = "e2";
+
+ public static final String PROPERTY_E2 = "e2";
+
public static final String PROPERTY_F2 = "f2";
+
String a2, b2, c2, d2;
- int e2,f2;
+ int e2, f2;
public String getA2() {
return a2;
}
public void setA2(String a2) {
+ Object oldValue = this.a2;
this.a2 = a2;
+ firePropertyChange(PROPERTY_A2, oldValue, a2);
}
public String getB2() {
@@ -50,7 +58,9 @@
}
public void setB2(String b2) {
+ Object oldValue = this.b2;
this.b2 = b2;
+ firePropertyChange(PROPERTY_B2, oldValue, b2);
}
public String getC2() {
@@ -58,7 +68,9 @@
}
public void setC2(String c2) {
+ Object oldValue = this.c2;
this.c2 = c2;
+ firePropertyChange(PROPERTY_C2, oldValue, c2);
}
public String getD2() {
@@ -66,7 +78,9 @@
}
public void setD2(String d2) {
+ Object oldValue = this.d2;
this.d2 = d2;
+ firePropertyChange(PROPERTY_D2, oldValue, d2);
}
public int getE2() {
@@ -74,7 +88,9 @@
}
public void setE2(int e2) {
+ Object oldValue = this.e2;
this.e2 = e2;
+ firePropertyChange(PROPERTY_E2, oldValue, e2);
}
public int getF2() {
@@ -82,6 +98,8 @@
}
public void setF2(int f2) {
+ Object oldValue = this.f2;
this.f2 = f2;
+ firePropertyChange(PROPERTY_F2, oldValue, f2);
}
}
Added: trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java (rev 0)
+++ trunk/src/test/java/org/nuiton/util/beans/BeanMonitorTest.java 2010-08-26 11:08:53 UTC (rev 1906)
@@ -0,0 +1,106 @@
+package org.nuiton.util.beans;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+/**
+ * Tests {@link BeanMonitor}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @serial $Id:$
+ * @since 1.4.1
+ */
+public class BeanMonitorTest {
+
+ @Test
+ public void testMonitor() throws Exception {
+
+ BeanMonitor monitor = new BeanMonitor(BeanA.PROPERTY_A,
+ BeanA.PROPERTY_B,
+ BeanA.PROPERTY_E
+ );
+
+ BeanA bean = new BeanA();
+ monitor.setBean(bean);
+
+ // nothing is monitored
+ assertMonitor(monitor);
+
+ // property A was modified
+ bean.setA("A");
+ assertMonitor(monitor, BeanA.PROPERTY_A, null);
+
+ // clean monitor
+ monitor.clearModified();
+ assertMonitor(monitor);
+
+ // property A was not modified
+ bean.setA("A");
+ assertMonitor(monitor);
+
+ // property C is not monitored
+ bean.setC("C");
+ assertMonitor(monitor);
+
+ // property A was modified
+ bean.setA("AA");
+ assertMonitor(monitor, BeanA.PROPERTY_A, "A");
+
+ // property A and B were modified
+ bean.setB("B");
+ assertMonitor(monitor,
+ BeanA.PROPERTY_A, "A",
+ BeanA.PROPERTY_B, null);
+
+ // property B is no more modified (came back to original value)
+ bean.setB(null);
+ assertMonitor(monitor, BeanA.PROPERTY_A, "A");
+
+ // property A and E were modified
+ bean.setE(1);
+ assertMonitor(monitor, BeanA.PROPERTY_A, "A", BeanA.PROPERTY_E, 0);
+
+ // property A is no more modified (came back to original value)
+ bean.setA("A");
+ assertMonitor(monitor, BeanA.PROPERTY_E, 0);
+
+ // property E is no more modified (came back to original value)
+ bean.setE(0);
+ assertMonitor(monitor);
+
+ // property B was modified
+ bean.setB("B");
+ assertMonitor(monitor, BeanA.PROPERTY_B, null);
+
+ // nothing is monitored (bean changed)
+ monitor.setBean(bean);
+ assertMonitor(monitor);
+
+ }
+
+ protected void assertMonitor(BeanMonitor monitor,
+ Object... propertyNamesAndOriginalValues) {
+
+ if (propertyNamesAndOriginalValues.length % 2 != 0) {
+ throw new IllegalArgumentException(
+ "propertiesAndValues should be couple of (propertyName, originalValue)");
+ }
+ String[] modifiedFields = monitor.getModifiedProperties();
+ Map<String, Object> originalValues = monitor.getOriginalValues();
+
+ if (propertyNamesAndOriginalValues.length == 0) {
+ Assert.assertFalse(monitor.wasModified());
+ Assert.assertEquals(0, modifiedFields.length);
+ } else {
+ Assert.assertTrue(monitor.wasModified());
+ for (int i = 0; i < propertyNamesAndOriginalValues.length; i += 2) {
+ String propertyName = (String) propertyNamesAndOriginalValues[i];
+ Object value = propertyNamesAndOriginalValues[i + 1];
+ Assert.assertEquals(propertyName, modifiedFields[i / 2]);
+ Assert.assertEquals(value, originalValues.get(propertyName));
+ }
+ }
+ }
+}
1
0