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@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"); } }