Author: glandais Date: 2008-03-20 14:34:04 +0000 (Thu, 20 Mar 2008) New Revision: 1419 Added: trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java Removed: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java Log: Moving to test Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-03-20 14:28:16 UTC (rev 1418) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-03-20 14:34:04 UTC (rev 1419) @@ -1,162 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais, Tony Chemit -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* 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 Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.storage; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Random; - -import fr.cemagref.simexplorer.is.entities.metadata.Version; - -/** - * A Version generator. - * - * @author chemit - */ -public class VersionGenerator { - - /** la taille maximum d'une version generée. */ - static final int MAX_SIZE = 5; - - /** la valeur maximum d'un numero de version a generer. */ - static final int MAX_VERSION_NUMBER = 10; - - /** - * le nombre maximum de versions generees dans la methode - * {@link #generateVersions()}. - */ - static final int MAX_NB_VERSIONS = 20; - - /** instance statique partagee. */ - protected static VersionGenerator instance; - - /** - * Gets the single instance of VersionGenerator. - * - * @return single instance of VersionGenerator - */ - public static VersionGenerator getInstance() { - if (instance == null) { - instance = new VersionGenerator(); - } - return instance; - } - - /** The r. */ - protected Random r; - - /** - * Generate version. - * - * @return the version - */ - public Version generateVersion() { - StringBuilder sb = new StringBuilder(); - for (int i = 0, size = generateNotNullAbsInt(MAX_SIZE); i < size; i++) { - sb.append('.').append(generateAbsInt(MAX_VERSION_NUMBER)); - } - return Version.valueOf(sb.substring(1)); - } - - /** - * Generate versions. - * - * @return the version[] - */ - public Version[] generateVersions() { - int nb = generateNotNullAbsInt(MAX_NB_VERSIONS); - return generateVersions(nb); - } - - /** - * Generate versions. - * - * @param mandatory - * the mandatory - * - * @return the version[] - */ - public Version[] generateVersions(Version mandatory) { - int nb = generateNotNullAbsInt(MAX_NB_VERSIONS); - Version[] versions = generateVersions(nb); - List<Version> list = new ArrayList<Version>(Arrays.asList(versions)); - if (!list.contains(mandatory)) { - list.add(mandatory); - Collections.sort(list); - } - return list.toArray(new Version[list.size()]); - } - - /** - * Generate versions. - * - * @param nb - * the nb - * - * @return the version[] - */ - public Version[] generateVersions(int nb) { - Version[] result = new Version[nb]; - result[0] = generateVersion(); - // System.out.println("nb versions :" + nb); - // System.out.println("version 0 :" + result[0]); - for (int i = 1; i < nb; i++) { - result[i] = result[i - 1].incVersion(generateAbsInt(MAX_SIZE)); - // System.out.println("version " + i + " :" + result[i]); - } - return result; - } - - /** - * Generate abs int. - * - * @param max - * the max - * - * @return the int - */ - protected int generateAbsInt(int max) { - return Math.abs(r.nextInt()) % max; - } - - /** - * Generate not null abs int. - * - * @param max - * the max - * - * @return the int - */ - protected int generateNotNullAbsInt(int max) { - int nb = 0; - while (nb == 0) { - nb = generateAbsInt(max); - } - return nb; - } - - /** - * Instantiates a new version generator. - */ - protected VersionGenerator() { - this.r = new Random(); - } - -} \ No newline at end of file Copied: trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java (from rev 1418, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-03-20 14:34:04 UTC (rev 1419) @@ -0,0 +1,162 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais, Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* 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 Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.storage; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +import fr.cemagref.simexplorer.is.entities.metadata.Version; + +/** + * A Version generator. + * + * @author chemit + */ +public class VersionGenerator { + + /** la taille maximum d'une version generée. */ + static final int MAX_SIZE = 5; + + /** la valeur maximum d'un numero de version a generer. */ + static final int MAX_VERSION_NUMBER = 10; + + /** + * le nombre maximum de versions generees dans la methode + * {@link #generateVersions()}. + */ + static final int MAX_NB_VERSIONS = 20; + + /** instance statique partagee. */ + protected static VersionGenerator instance; + + /** + * Gets the single instance of VersionGenerator. + * + * @return single instance of VersionGenerator + */ + public static VersionGenerator getInstance() { + if (instance == null) { + instance = new VersionGenerator(); + } + return instance; + } + + /** The r. */ + protected Random r; + + /** + * Generate version. + * + * @return the version + */ + public Version generateVersion() { + StringBuilder sb = new StringBuilder(); + for (int i = 0, size = generateNotNullAbsInt(MAX_SIZE); i < size; i++) { + sb.append('.').append(generateAbsInt(MAX_VERSION_NUMBER)); + } + return Version.valueOf(sb.substring(1)); + } + + /** + * Generate versions. + * + * @return the version[] + */ + public Version[] generateVersions() { + int nb = generateNotNullAbsInt(MAX_NB_VERSIONS); + return generateVersions(nb); + } + + /** + * Generate versions. + * + * @param mandatory + * the mandatory + * + * @return the version[] + */ + public Version[] generateVersions(Version mandatory) { + int nb = generateNotNullAbsInt(MAX_NB_VERSIONS); + Version[] versions = generateVersions(nb); + List<Version> list = new ArrayList<Version>(Arrays.asList(versions)); + if (!list.contains(mandatory)) { + list.add(mandatory); + Collections.sort(list); + } + return list.toArray(new Version[list.size()]); + } + + /** + * Generate versions. + * + * @param nb + * the nb + * + * @return the version[] + */ + public Version[] generateVersions(int nb) { + Version[] result = new Version[nb]; + result[0] = generateVersion(); + // System.out.println("nb versions :" + nb); + // System.out.println("version 0 :" + result[0]); + for (int i = 1; i < nb; i++) { + result[i] = result[i - 1].incVersion(generateAbsInt(MAX_SIZE)); + // System.out.println("version " + i + " :" + result[i]); + } + return result; + } + + /** + * Generate abs int. + * + * @param max + * the max + * + * @return the int + */ + protected int generateAbsInt(int max) { + return Math.abs(r.nextInt()) % max; + } + + /** + * Generate not null abs int. + * + * @param max + * the max + * + * @return the int + */ + protected int generateNotNullAbsInt(int max) { + int nb = 0; + while (nb == 0) { + nb = generateAbsInt(max); + } + return nb; + } + + /** + * Instantiates a new version generator. + */ + protected VersionGenerator() { + this.r = new Random(); + } + +} \ No newline at end of file