Author: dlanglais Date: 2010-01-28 00:23:49 +0100 (Thu, 28 Jan 2010) New Revision: 26 Added: trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureTest.java Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Cell.java trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellImpl.java trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Column.java trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnImpl.java trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Structure.java trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureImpl.java Log: Passage ?\195?\160 l'anglais de certain commentaire javadoc. Cr?\195?\169ation de test sur la classe StructureImpl. Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Cell.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Cell.java 2010-01-27 21:59:17 UTC (rev 25) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Cell.java 2010-01-27 23:23:49 UTC (rev 26) @@ -1,21 +1,29 @@ package org.nuiton.mapstoragemanager.plugins.bighashmap; /** - * Interface listant les opérations nécéssaires sur une cellule. + * Interface to present the method an a Cell. * @author Dorian Langlais * - * @param <T> type d'objet contenu dans les cellules. + * @param <T> Class of the object stored in the cells. */ public interface Cell < T > { /** - * Récupère le contenu le plus récent de la cellule. - * @return retourne l'objet le plus récent stocké dans la cellule. + * Get the most recent object put in the cell. + * @return The most recent object stored in the cell. */ T get(); + /** - * Ajout de contenu dans la cellule. - * @param t objet de type < T > à stocker dans la cellule. + * Put a new object in the cell. + * @param t Objet to store in the cell. */ void put(T t); + + /** + * Get an object from its "version". + * @param t the version wanted (it can be timestamp, number..). + * @return The object corresponding to the "version". + */ + T get(Long t); } Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellImpl.java 2010-01-27 21:59:17 UTC (rev 25) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellImpl.java 2010-01-27 23:23:49 UTC (rev 26) @@ -5,31 +5,31 @@ import java.util.NoSuchElementException; /** - * Classe Cell. - * Une cellule (selon la spec bigtable de google) est une Map entre un - * timestamp et un contenu. - * @param <T> Une cellule est paramétrée selon son type de contenu. + * Class Cell. + * A cell contain different version of a content. + * So a cell store objects and its version. + * @param <T> The type of the stored objects. * @author dorian Langlais, amaury Fages, gilles Crieloue, florent Gilet. * @licence GPL. */ public class CellImpl < T /**extends Serializable*/ > implements Cell < T > { /** - * Cellule. - * hashMap ayant pour clé le timestamp et pour valeur un objet de type T. + * cell. + * hashMap with key as timestamp and value, as object of T class. */ private Map < Long, T > cell; /** - * Constructeur par défaut. + * Default constructor. */ public CellImpl() { this.cell = new HashMap < Long, T > (); } - + /** - * Constructeur avec un objet. - * @param t objet à mettre dans la cellule à construire. + * Constructor with object. + * @param t The object to store. */ public CellImpl(T t) { this.cell = new HashMap < Long, T > (); @@ -44,10 +44,7 @@ } /** - * get(Long timestamp). - * fonction d'accès au contenu d'une cellule en fonction de son timestamp. - * @param timestamp Timestamps d'une cellule. - * @return retourne le contenu de la cellule. + * {@inheritDoc} */ public final T get(final Long timestamp) { return cell.get(timestamp); Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Column.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Column.java 2010-01-27 21:59:17 UTC (rev 25) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Column.java 2010-01-27 23:23:49 UTC (rev 26) @@ -1,23 +1,38 @@ package org.nuiton.mapstoragemanager.plugins.bighashmap; /** - * Interface représentant les méthodes nécéssaires sur une colonne. + * Interface to present the method to implement for en Column. * @author Dorian Langlais * - * @param <T> type d'objet contenu dans la colonne. + * @param <T> Class of the object stored in the columns. */ public interface Column < T > { /** - * Récupère le contenu de la cellule ayant pour clé key. - * @param key clé de la ligne. - * @return objet stocké dans la celulle ayant pour clé key. + * Get the object which has key <b>key</key>. + * @param key the key. + * @return the object stored at the line identified by <b>key</b> */ T get(String key); + /** - * Ajoute l'objet t à la ligne de clé key. - * @param key clé de la ligne. - * @param t objet à stocker. + * Get the object which has key <b>key</key> and version <b>version</b>. + * @param key + * @param version the version wanted (it can be timestamp, number..). + * @return The object corresponding to the "version". */ + T get(String key, Long version); + + /** + * Put object <b>t</b> with the key <b>key</b>. + * @param key the key + * @param t object to store + */ void put(String key, T t); + + /** + * Delete an object by its key. + * @param key the key + */ + void delete(String key); } Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnImpl.java 2010-01-27 21:59:17 UTC (rev 25) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnImpl.java 2010-01-27 23:23:49 UTC (rev 26) @@ -13,14 +13,13 @@ public class ColumnImpl < T /**extends Serializable*/ > implements Column < T > { /** - * Colonne. - * hashMap ayant pour clé la "clé" de la "ligne" de la table et pour - * valeur le contenu de la cellule. + * column. + * hashMap with key the key of the line, and value a column. */ private Map < String, CellImpl < T > > column; /** - * Constructeur par défaut. + * Default constructor. */ public ColumnImpl() { column = new HashMap < String, CellImpl < T > > (); @@ -28,11 +27,7 @@ /** - * get(Long timestamp). - * fonction d'accès au contenu d'une cellule en fonction de son timestamp. - * @param key clé de la ligne. - * @param timestamp désiré. - * @return retourne le contenu de la cellule. + * {@inheritDoc} */ public final T get(final String key, final Long timestamp) { return this.column.get(key).get(timestamp); @@ -58,4 +53,11 @@ this.column.put(key, new CellImpl < T > (content)); } } + + /** + * {@inheritDoc} + */ + public final void delete(final String key) { + this.column.remove(key); + } } Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Structure.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Structure.java 2010-01-27 21:59:17 UTC (rev 25) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/Structure.java 2010-01-27 23:23:49 UTC (rev 26) @@ -3,33 +3,33 @@ import java.util.Set; /** - * Interface listant les méthodes nécéssaires sur une structure. - * Une Structure est une description d'une Table. + * Interface to present the method on a structure. + * A structure is a description of a table. * @author Dorian Langlais * */ public interface Structure { /** - * Méthode permettant l'ajout d'une colonne à une structure de table. - * @param columnName nom de la colonne. - * @param columnClass type d'objet contenu dans la colonne. + * Add a new column in the structure. + * @param columnName the column name + * @param columnClass the column class */ void addColumn(String columnName, Class < ? > columnClass); /** - * Méthode permettant de récupérer le nom des colonnes. - * @return retourne le nom de colonnes. + * Get the columns' names. + * @return return a set containing the name of the columns. */ Set < String > getColumnsNames(); /** - * Méthode permettant de récupérer le type d'objet d'une colonne. - * @param columnName nom de la colonne. - * @return retourne le type d'objet de la colonne columnName. + * Get the class of object of the column <b>columnName</b>. + * @param columnName the column name + * @return return the column class */ Class < ? > getColumnClass(String columnName); /** - * Méthode permettant la suppression d'une colonne à la structure. - * @param columnName nom de la colonne à supprimer. + * Remove a column of the structure by its name. + * @param columnName the column name */ void removeColumn(String columnName); } Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureImpl.java 2010-01-27 21:59:17 UTC (rev 25) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureImpl.java 2010-01-27 23:23:49 UTC (rev 26) @@ -5,25 +5,24 @@ import java.util.Set; /** - * Classe Structure. - * Représente le mapping d'une ligne, les types des colonnes + * Class Structure. + * Represente the mapping between a row and the column of a table. * @author Dorian Langlais * */ public class StructureImpl implements Structure { /** - * Structure de la table. - * Contient le nom de la colonne comme clé, - * et le type de la colonne pour valeur. + * structure. + * hashMap with key the column name, and value the column class. */ - private Map < String, Class < ? /**extends Serializable*/ > > struct; + private Map < String, Class < ? /**extends Serializable*/ > > structure; /** - * Constructeur par défaut. + * Default constructor. */ public StructureImpl() { - this.struct = + this.structure = new HashMap < String, Class < ? /**extends Serializable*/ > > (); } @@ -32,14 +31,14 @@ */ public final void addColumn(final String columnName, final Class < ? /**extends Serializable*/ > columnClass) { - this.struct.put(columnName, columnClass); + this.structure.put(columnName, columnClass); } /** * {@inheritDoc} */ public final void removeColumn(final String columnName) { - this.struct.remove(columnName); + this.structure.remove(columnName); } /** @@ -47,13 +46,13 @@ */ public final Class < ? /**extends Serializable*/ > getColumnClass( final String columnName) { - return this.struct.get(columnName); + return this.structure.get(columnName); } /** * {@inheritDoc} */ public final Set < String > getColumnsNames() { - return this.struct.keySet(); + return this.structure.keySet(); } } Added: trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureTest.java =================================================================== --- trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/StructureTest.java 2010-01-27 23:23:49 UTC (rev 26) @@ -0,0 +1,65 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmap; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import junit.framework.TestCase; + +public class StructureTest extends TestCase { + + public void testGetColumnsNamesVoid() { + Structure s = new StructureImpl(); + Set < String > columnNames = s.getColumnsNames(); + assertEquals(0, columnNames.size()); + } + + /** + * we add a column with name and class. + * We use reflexivity to verify that the map of the structure is like we + * want. + */ + public void testAddColumn() { + + Map < String, Class < ? > > structureExpected = + new HashMap<String, Class<?>>(); + + try { + Structure s = new StructureImpl(); + + Field fStructure = s.getClass().getDeclaredField("structure"); + fStructure.setAccessible(true); + Map < String, Class < ? > > structureActual = + (Map < String, Class < ? > >) fStructure.get(s); + + s.addColumn("Test", String.class); + structureExpected.put("Test", String.class); + + assertEquals(structureExpected, structureActual); + + + s.addColumn("Test2", Object.class); + structureExpected.put("Test2", Object.class); + + assertEquals(structureExpected, structureActual); + + + s.addColumn("Test3", Map.class); + structureExpected.put("Test3", Map.class); + + assertEquals(structureExpected, structureActual); + + } catch (IllegalArgumentException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (NoSuchFieldException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(StructureTest.class.getName()).log(Level.SEVERE, null, ex); + } + } +}