r1790 - in trunk/src: main/java/org/nuiton/util test/java/org/nuiton test/java/org/nuiton/util
Author: tchemit Date: 2010-03-07 18:28:51 +0100 (Sun, 07 Mar 2010) New Revision: 1790 Log: - Evolution #350: Remove deprecated api VersionNumber - Evolution #351: Remove deprecated api SimplePaginationEnum - Evolution #347: Move all i18n api to project i18n Removed: trunk/src/main/java/org/nuiton/util/SimplePaginationEnum.java trunk/src/main/java/org/nuiton/util/VersionNumber.java trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java trunk/src/main/java/org/nuiton/util/VersionNumberUtil.java trunk/src/test/java/org/nuiton/log/ trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java Deleted: trunk/src/main/java/org/nuiton/util/SimplePaginationEnum.java =================================================================== --- trunk/src/main/java/org/nuiton/util/SimplePaginationEnum.java 2010-03-07 17:24:19 UTC (rev 1789) +++ trunk/src/main/java/org/nuiton/util/SimplePaginationEnum.java 2010-03-07 17:28:51 UTC (rev 1790) @@ -1,50 +0,0 @@ -/* -* *##% Nuiton utilities library - * Copyright (C) 2004 - 2009 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>. ##%* */ -package org.nuiton.util; - -/** - * Une enumration pour definir les tailles de liste - * - * @author chemit - * - * @deprecated since 1.1.0, too static! (only used in simexplorer) - */ -@Deprecated -public enum SimplePaginationEnum { - _5, - _10, - _20, - _50, - _100; - - int intValue; - - SimplePaginationEnum() { - intValue = Integer.valueOf(toString()); - } - - @Override - public String toString() { - return super.toString().substring(1); - } - - public int intValue() { - return intValue; - } - -} Deleted: trunk/src/main/java/org/nuiton/util/VersionNumber.java =================================================================== --- trunk/src/main/java/org/nuiton/util/VersionNumber.java 2010-03-07 17:24:19 UTC (rev 1789) +++ trunk/src/main/java/org/nuiton/util/VersionNumber.java 2010-03-07 17:28:51 UTC (rev 1790) @@ -1,87 +0,0 @@ -/* -* *##% Nuiton utilities library - * Copyright (C) 2004 - 2009 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>. ##%* */ -package org.nuiton.util; - -import java.util.Arrays; - -/** - * A class to represent an application version - * - * @author chemit - * @deprecated since 1.6.0, use the {@link Version} class instead) - */ -@Deprecated -public class VersionNumber implements Comparable<VersionNumber> { - protected int[] numbers; - - public VersionNumber() { - this.numbers = new int[]{0}; - } - - public VersionNumber(int... numbers) { - this.numbers = numbers; - } - - public int[] getNumbers() { - return numbers; - } - - public int getNumber(int level) { - if (level<0 || level>=numbers.length) { - throw new IllegalArgumentException("not a valid level "+level+ " for the VersionNumber "+this); - } - return numbers[level]; - } - - public int getNbComponents() { - return numbers.length; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (int number : numbers) { - sb.append('.').append(number); - } - return sb.toString().substring(1); - } - - public int compareTo(VersionNumber o) { - String str = toString(); - String ostr = o.toString(); - if (str.equals(ostr)) { - return 0; - } - return VersionNumberUtil.greaterThan(str, ostr) ? 1 : -1; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof VersionNumber)) return false; - - VersionNumber that = (VersionNumber) o; - return Arrays.equals(numbers, that.numbers); - - } - - @Override - public int hashCode() { - return Arrays.hashCode(numbers); - } -} Deleted: trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java 2010-03-07 17:24:19 UTC (rev 1789) +++ trunk/src/main/java/org/nuiton/util/VersionNumberConverter.java 2010-03-07 17:28:51 UTC (rev 1790) @@ -1,85 +0,0 @@ -/* -* *##% Nuiton utilities library - * Copyright (C) 2004 - 2009 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>. ##%* */ -package org.nuiton.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n._; - -/** - * classe pour convertir une chaine en un objet VersionNumber. - * - * @author chemit - * @see VersionNumber - * @deprecated since 1.6.0, use the {@link VersionConverter} class instead) - */ -@Deprecated -public class VersionNumberConverter implements Converter { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static org.apache.commons.logging.Log log = getLog(VersionNumberConverter.class); - - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException(_("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = valueOf((String) value); - return result; - } - } - throw new ConversionException(_("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - public VersionNumberConverter() { - if (log.isDebugEnabled()) { - log.debug(this); - } - } - - protected VersionNumber valueOf(String value) { - try { - VersionNumber result; - String[] str = value.split("\\."); - if (str.length == 0) { - return new VersionNumber(); - } - int[] numbers = new int[str.length]; - for (int i = 0; i < str.length; i++) { - String number = str[i]; - numbers[i] = Integer.valueOf(number); - } - result = new VersionNumber(numbers); - return result; - } catch (IllegalArgumentException e) { - throw new ConversionException(_("nuitonutil.error.url.convertor", value, this, e.getMessage())); - } - } - - protected boolean isEnabled(Class aClass) { - return aClass == VersionNumber.class; - } - -} Deleted: trunk/src/main/java/org/nuiton/util/VersionNumberUtil.java =================================================================== --- trunk/src/main/java/org/nuiton/util/VersionNumberUtil.java 2010-03-07 17:24:19 UTC (rev 1789) +++ trunk/src/main/java/org/nuiton/util/VersionNumberUtil.java 2010-03-07 17:28:51 UTC (rev 1790) @@ -1,107 +0,0 @@ -/* *##% Nuiton utilities library - * Copyright (C) 2004 - 2009 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>. ##%* */ - -/* * - * NumberVersionUtil.java - * - * Created: 4 déc. 2003 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - -package org.nuiton.util; - -/** - * - * @author chemit - * @deprecated since 1.6.0, use {@link VersionUtil} instead. - * @see Version - * @see VersionUtil - */ -@Deprecated -public class VersionNumberUtil { // VersionNumberUtil - - protected static String normalize(String version) { - if (version == null) { - version = "0"; - } - return version; - } - - public static boolean greaterThan(String v1, String v2) { - String[] v1s = normalize(v1).split("\\."); - String[] v2s = normalize(v2).split("\\."); - int minlen = Math.min(v1s.length, v2s.length); - for (int i = 0; i < minlen; i++) { - if (!v1s[i].equals(v2s[i])) - return Integer.parseInt(v1s[i]) > Integer.parseInt(v2s[i]); - } - // si on est ici c que tout les nombres sont v1[i] = v2[i] - return v1s.length > v2s.length; - } - - /** - * Regarde l'egalité entre 2 numeros de version - * 1.2.0 et 1.2 ne sont pas egaux - */ - public static boolean equals(String v1, String v2) { - return normalize(v1).equals(normalize(v2)); - } - - public static boolean smallerThan(String v1, String v2) { - String[] v1s = normalize(v1).split("\\."); - String[] v2s = normalize(v2).split("\\."); - int minlen = Math.min(v1s.length, v2s.length); - for (int i = 0; i < minlen; i++) { - if (!v1s[i].equals(v2s[i])) - return Integer.parseInt(v1s[i]) < Integer.parseInt(v2s[i]); - } - // si on est ici c que tout les nombres sont v1[i] = v2[i] - return v1s.length < v2s.length; - } - - /** - * Incremente le numero de version, seul le dernier constituant est - * incremente: 1.2.3.4 -> 1.2.3.5; null -> 1; 0 -> 1 - */ - public static String inc(String v) { - if (v == null) { - return "1"; - } else { - v = v.trim(); - } - - String result = null; - int i = v.lastIndexOf('.'); - if (i == -1) { - int n = Integer.parseInt(v) + 1; - result = "" + n; - } else { - String num = v.substring(i + 1); - int n = Integer.parseInt(num) + 1; - result = v.substring(0, i + 1) + n; - } - return result; - } - -} // VersionNumberUtil - Deleted: trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java =================================================================== --- trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java 2010-03-07 17:24:19 UTC (rev 1789) +++ trunk/src/test/java/org/nuiton/util/VersionNumberUtilTest.java 2010-03-07 17:28:51 UTC (rev 1790) @@ -1,92 +0,0 @@ -/* *##% Nuiton utilities library - * Copyright (C) 2004 - 2009 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>. ##%* */ - -/* * - * VersionNumberUtilTest.java - * - * Created: 13 juil. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -package org.nuiton.util; - -import junit.framework.TestCase; - -/** - * - * @author chemit - * @deprecated since 1.6.0, the {@link VersionNumberUtil} is deprecated) - */ -@Deprecated -public class VersionNumberUtilTest extends TestCase { // VersionNumberUtilTest - - public void testSmaller() { - assertTrue(VersionNumberUtil.smallerThan("1", "2")); - assertFalse(VersionNumberUtil.smallerThan("3", "1")); - - assertFalse(VersionNumberUtil.smallerThan("1.2.3", "1.2.3")); - assertTrue(VersionNumberUtil.smallerThan("1.2.3", "1.2.3.1")); - assertTrue(VersionNumberUtil.smallerThan("1.2.3", "1.3.3.1")); - assertFalse(VersionNumberUtil.smallerThan("1.3.3", "1.2.3.1")); - - assertFalse(VersionNumberUtil.smallerThan("1.2.3", "1.2.3")); - assertFalse(VersionNumberUtil.smallerThan("1.2.3.1", "1.2.3")); - assertFalse(VersionNumberUtil.smallerThan("1.2.3.1", "1.2.3")); - assertTrue(VersionNumberUtil.smallerThan("1.2.3.1", "1.3.3")); - } - - public void testEquals() { - assertTrue(VersionNumberUtil.equals("10", "10")); - assertFalse(VersionNumberUtil.equals("3", "1")); - - assertTrue(VersionNumberUtil.equals("1.2.3", "1.2.3")); - assertFalse(VersionNumberUtil.equals("1.2.3", "1.2.3.0")); - assertFalse(VersionNumberUtil.equals("1.2.3.0", "1.2.3")); - assertFalse(VersionNumberUtil.equals("1.2.3", "1.2.3.1")); - assertFalse(VersionNumberUtil.equals("1.2.3", "1.3.3.1")); - assertFalse(VersionNumberUtil.equals("1.3.3", "1.2.3.1")); - } - - public void testGreater() { - assertFalse(VersionNumberUtil.greaterThan("1", "2")); - assertTrue(VersionNumberUtil.greaterThan("3", "1")); - - assertFalse(VersionNumberUtil.greaterThan("1.2.3", "1.2.3")); - assertFalse(VersionNumberUtil.greaterThan("1.2.3", "1.2.3.1")); - assertFalse(VersionNumberUtil.greaterThan("1.2.3", "1.3.3.1")); - assertTrue(VersionNumberUtil.greaterThan("1.3.3", "1.2.3.1")); - - assertFalse(VersionNumberUtil.greaterThan("1.2.3", "1.2.3")); - assertTrue(VersionNumberUtil.greaterThan("1.2.3.1", "1.2.3")); - assertTrue(VersionNumberUtil.greaterThan("1.3.3.1", "1.2.3")); - assertFalse(VersionNumberUtil.greaterThan("1.2.3.1", "1.3.3")); - } - - public void testInc() { - assertTrue(VersionNumberUtil.equals("1", VersionNumberUtil.inc(null))); - assertTrue(VersionNumberUtil.equals("4", VersionNumberUtil.inc("3"))); - assertTrue(VersionNumberUtil.equals("10", VersionNumberUtil.inc("9"))); - assertTrue(VersionNumberUtil.equals("1.2.4", VersionNumberUtil.inc("1.2.3"))); - assertTrue(VersionNumberUtil.equals("1.2.10", VersionNumberUtil.inc("1.2.9"))); - } -} // VersionNumberUtilTest -
participants (1)
-
tchemit@users.nuiton.org