Author: echatellier Date: 2009-07-17 18:18:45 +0200 (Fri, 17 Jul 2009) New Revision: 168 Modified: trunk/changelog.txt trunk/src/main/java/org/nuiton/math/matrix/AbstractMatrixND.java trunk/src/main/java/org/nuiton/math/matrix/BasicMatrix.java trunk/src/main/java/org/nuiton/math/matrix/BasicMatrixIterator.java trunk/src/main/java/org/nuiton/math/matrix/FloatVector.java trunk/src/main/java/org/nuiton/math/matrix/MapFunction.java trunk/src/main/java/org/nuiton/math/matrix/MatrixEncoder.java trunk/src/main/java/org/nuiton/math/matrix/MatrixException.java trunk/src/main/java/org/nuiton/math/matrix/MatrixFactory.java trunk/src/main/java/org/nuiton/math/matrix/MatrixHelper.java trunk/src/main/java/org/nuiton/math/matrix/MatrixIterator.java trunk/src/main/java/org/nuiton/math/matrix/MatrixIteratorImpl.java trunk/src/main/java/org/nuiton/math/matrix/MatrixND.java trunk/src/main/java/org/nuiton/math/matrix/MatrixNDImpl.java trunk/src/main/java/org/nuiton/math/matrix/MatrixStringEncoder.java trunk/src/main/java/org/nuiton/math/matrix/SemanticList.java trunk/src/main/java/org/nuiton/math/matrix/SubMatrix.java trunk/src/main/java/org/nuiton/math/matrix/Vector.java trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixEditor.java trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.java trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelListener.java trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java trunk/src/test/java/org/nuiton/math/matrix/MatrixNDTest.java trunk/src/test/java/org/nuiton/math/matrix/MatrixStringEncoderTest.java Log: Change some methods names, add comments. Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/changelog.txt 2009-07-17 16:18:45 UTC (rev 168) @@ -1,3 +1,8 @@ +ver-2.0 chatellier + * rename some methods (make originals deprecated) + * add generics + * improve javadoc + ver-1.3 chatellier 2009xxxx * Move test to junit 4 * Update copyright Modified: trunk/src/main/java/org/nuiton/math/matrix/AbstractMatrixND.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/AbstractMatrixND.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/AbstractMatrixND.java 2009-07-17 16:18:45 UTC (rev 168) @@ -68,7 +68,7 @@ protected int[] dim = null; - protected List[] semantics = null; + protected List<?>[] semantics = null; protected double defaultValue = 0; @@ -96,13 +96,13 @@ public AbstractMatrixND(MatrixFactory factory, int[] dim) { this(factory); init(dim); - for (int i = 0; i < getNbDim(); i++) { + for (int i = 0; i < getDimCount(); i++) { // par defaut les listes des semantiques contiennent des nulls semantics[i] = Collections.nCopies(dim[i], null); } } - public AbstractMatrixND(MatrixFactory factory, List[] semantics) { + public AbstractMatrixND(MatrixFactory factory, List<?>[] semantics) { this(factory); int[] dim = new int[semantics.length]; for (int i = 0; i < dim.length; i++) { @@ -113,8 +113,8 @@ } } init(dim); - for (int i = 0; i < getNbDim(); i++) { - setSemantics(i, semantics[i]); + for (int i = 0; i < getDimCount(); i++) { + setSemantic(i, semantics[i]); } } @@ -132,13 +132,14 @@ } } - public AbstractMatrixND(MatrixFactory factory, String name, List[] semantics) { + public AbstractMatrixND(MatrixFactory factory, String name, + List<?>[] semantics) { this(factory, semantics); setName(name); } public AbstractMatrixND(MatrixFactory factory, String name, - List[] semantics, String[] dimNames) { + List<?>[] semantics, String[] dimNames) { this(factory, name, semantics); for (int i = 0; dimNames != null && i < dimNames.length; i++) { setDimensionName(i, dimNames[i]); @@ -146,9 +147,7 @@ } /* - * (non-Javadoc) - * - * @see org.codelutin.math.matrix.MatrixND#copy() + * @see org.nuiton.math.matrix.MatrixND#copy() */ public MatrixND copy() { MatrixND result = getFactory().create(this); @@ -156,8 +155,6 @@ } /* - * (non-Javadoc) - * * @see java.lang.Object#clone() */ @Override @@ -175,19 +172,39 @@ } @Override - public List[] getSemantics() { + public List<?>[] getSemantics() { return semantics; } + /** + * {@inheritDoc} + * + * @deprecated Use #getSemantics(dim) + */ @Override - public List getSemantics(int dim) { + public List<?> getSemantics(int dim) { + return getSemantic(dim); + } + + @Override + public List<?> getSemantic(int dim) { return semantics[dim]; } + /** + * {@inheritDoc} + * + * @deprecated Use #setSemantic(dim, List<E>) + */ @Override - public void setSemantics(int dim, List sem) { + public <E> void setSemantics(int dim, List<E> sem) { + setSemantic(dim, sem); + } + + @Override + public <E> void setSemantic(int dim, List<E> sem) { if (!(sem instanceof SemanticList)) { - sem = new SemanticList(sem); + sem = new SemanticList<E>(sem); } // else SemanticList is immutable and can be used in many matrix in // same time this permit to used same indexOf optimization @@ -252,7 +269,7 @@ // implantation on s'appuie. Mais dans les sous classes, si on a deja // un tableau il ne faut pas le recréer, on peut le passer directement int nbelem = 1; - for (int i = 0; i < getNbDim(); i++) { + for (int i = 0; i < getDimCount(); i++) { nbelem *= getDim(i); } double[] data = new double[nbelem]; @@ -263,8 +280,18 @@ return MatrixHelper.maxOccurence(data); } + /** + * {@inheritDoc} + * + * @deprecated use #getDimCount() instead + */ @Override public int getNbDim() { + return getDimCount(); + } + + @Override + public int getDimCount() { return dim.length; } @@ -316,7 +343,7 @@ @Override public double getValue(Object x, Object y, Object z, Object t) { return getValue(dimHelper.get(x, y, z, t)); - }; + } @Override public double getValue(int x) { @@ -402,7 +429,7 @@ result = result && equalsValues(mat); // les sémantiques doivent-être identique - for (int i = 0; result && i < getNbDim(); i++) { + for (int i = 0; result && i < getDimCount(); i++) { String dimName1 = getDimensionName(i); String dimName2 = mat.getDimensionName(i); result = ObjectUtils.equals(dimName1, dimName2); @@ -413,8 +440,8 @@ // System.out.println("dimName1("+dimName1+")==dimName2("+dimName2+ // ")="+result); - List sem1 = getSemantics(i); - List sem2 = mat.getSemantics(i); + List<?> sem1 = getSemantic(i); + List<?> sem2 = mat.getSemantic(i); result = result && ObjectUtils.equals(sem1, sem2); if (log.isTraceEnabled()) { log.trace("sem1(" + sem1 + ")==sem2(" + sem2 + ")=" + result); @@ -434,7 +461,7 @@ * pas les semantiques * * @param mat - * @return + * @return equality on values */ @Override public boolean equalsValues(MatrixND mat) { @@ -472,18 +499,18 @@ } @Override - public List toList() { - List result = new ArrayList(); + public List<Object> toList() { + List<Object> result = new ArrayList<Object>(); // [3,2,5,4] for (MatrixIterator i = iterator(); i.next();) { int[] coord = i.getCoordinates(); double value = i.getValue(); - List tmp = result; + List<Object> tmp = result; for (int dim = 0; dim < coord.length - 1; dim++) { while (tmp.size() <= coord[dim]) { - tmp.add(new ArrayList()); + tmp.add(new ArrayList<Object>()); } - tmp = (List) tmp.get(coord[dim]); + tmp = (List<Object>) tmp.get(coord[dim]); } while (tmp.size() <= coord[coord.length - 1]) { tmp.add(NumberUtils.DOUBLE_ZERO); @@ -496,14 +523,14 @@ } @Override - public void fromList(List list) { + public void fromList(List<Object> list) { // on suppose que les listes sont bien formé, c-a-d qu'elles sont // toutes de la meme dimension pour une dimension donnée. ArrayIntList dim = new ArrayIntList(); - List tmp = list; + List<Object> tmp = list; while (tmp.get(tmp.size() - 1) instanceof List) { dim.add(tmp.size()); - tmp = (List) tmp.get(tmp.size() - 1); + tmp = (List<Object>) tmp.get(tmp.size() - 1); } dim.add(tmp.size()); MatrixND mat = getFactory().create(dim.toArray()); @@ -512,7 +539,7 @@ int[] coord = i.getCoordinates(); tmp = list; for (int d = 0; d < coord.length - 1; d++) { - tmp = (List) tmp.get(coord[d]); + tmp = (List<Object>) tmp.get(coord[d]); } Double value = (Double) tmp.get(coord[coord.length - 1]); @@ -522,7 +549,7 @@ } public boolean isValidCoordinates(int[] dim) { - boolean result = getNbDim() == dim.length; + boolean result = getDimCount() == dim.length; for (int i = 0; result && i < dim.length; i++) { result = 0 <= dim[i] && dim[i] < getDim(i); } @@ -530,9 +557,9 @@ } public boolean isValidCoordinates(Object[] semantics) { - boolean result = getNbDim() == semantics.length; + boolean result = getDimCount() == semantics.length; for (int i = 0; result && i < semantics.length; i++) { - result = getSemantics(i).contains(semantics[i]); + result = getSemantic(i).contains(semantics[i]); } return result; } @@ -568,8 +595,8 @@ // le nombre d'element qu'il y aura dans la dim pour le resultat int nbDim = getDim(dim) / step; - List[] semantics = new List[getNbDim()]; - System.arraycopy(getSemantics(), 0, semantics, 0, getNbDim()); + List<Object>[] semantics = new List[getDimCount()]; + System.arraycopy(getSemantics(), 0, semantics, 0, getDimCount()); semantics[dim] = semantics[dim].subList(0, nbDim); // creation du resultat @@ -589,8 +616,9 @@ @Override public MatrixND sumOverDim(int dim, int start, int nb) { // copie de l'ancienne semantique - List[] semantics = new List[getNbDim()]; - System.arraycopy(getSemantics(), 0, semantics, 0, getNbDim()); + List<Object>[] semantics = new List[getDimCount()]; + + System.arraycopy(getSemantics(), 0, semantics, 0, getDimCount()); semantics[dim] = new ArrayList<Object>(semantics[dim]); // creation d'un liste qui agrege les elements sommés @@ -610,7 +638,7 @@ MatrixND sub3 = this.getSubMatrix(dim, start + nb, getDim(dim) - (start + nb)); - int[] origin = new int[getNbDim()]; + int[] origin = new int[getDimCount()]; result.paste(origin, sub1); origin[dim] = start; result.paste(origin, sub2); @@ -632,7 +660,7 @@ */ @Override public MatrixND paste(MatrixND mat) { - return paste(new int[getNbDim()], mat); + return paste(new int[getDimCount()], mat); } /** @@ -681,7 +709,7 @@ @Override public MatrixND getSubMatrix(int dim, int start, int nb) { if (dim < 0) { - dim = getNbDim() + dim; + dim = getDimCount() + dim; } if (start < 0) { start = getDim(dim) + start; @@ -704,7 +732,7 @@ * * @param dim * @param elem - * @return + * @return new matrix */ public MatrixND getSubMatrixOnSemantic(int dim, Object... elem) { MatrixND result = getSubMatrix(dim, elem); @@ -760,32 +788,33 @@ @Override public MatrixND transpose() { - if (getNbDim() > 2) { + MatrixND result = null; + + if (getDimCount() > 2) { throw new MatrixException( "La transpose ne peut-être fait que sur une matrice ayant 2 dimensions ou moins"); } - if (getNbDim() == 1) { - MatrixND result = getFactory() + if (getDimCount() == 1) { + result = getFactory() .create( getName(), new List[] { Collections.nCopies(1, null), - getSemantics(0) }, + getSemantic(0) }, new String[] { "Dimension 0", getDimensionName(0) }); for (int x = 0; x < getDim(0); x++) { result.setValue(0, x, getValue(x)); } - return result; } else { - MatrixND result = getFactory().create(getName(), - new List[] { getSemantics(1), getSemantics(0) }, + result = getFactory().create(getName(), + new List[] { getSemantic(1), getSemantic(0) }, new String[] { getDimensionName(1), getDimensionName(0) }); for (int x = 0; x < getDim(0); x++) { for (int y = 0; y < getDim(1); y++) { result.setValue(y, x, getValue(x, y)); } } - return result; } + return result; } @Override @@ -801,21 +830,21 @@ // l'element i du tableau qui correcpond à la dimensions i de la // nouvelle matrice contient la dimension equivalente dans // la matrice actuelle - int[] correspondance = new int[getNbDim()]; + int[] correspondance = new int[getDimCount()]; // les nouvelles semantiques - List sem = new ArrayList(); + List<Object> sem = new ArrayList<Object>(); // les nouveaux noms de dimensions - List dimName = new ArrayList(); + List<Object> dimName = new ArrayList<Object>(); // il faut au moins une dimension pour la matrice int minNbDim = 1; - for (int j = getNbDim() - 1; j >= 0; j--) { + for (int j = getDimCount() - 1; j >= 0; j--) { // si la dimension à plus d'un élément ou qu'il n'est pas dans dims // on garde la dimension if (getDim(j) > 1 || Arrays.binarySearch(dims, j) < 0 || j < minNbDim) { // on ne conserve que les dimensions supérieure à 1 correspondance[sem.size()] = j; - sem.add(getSemantics(j)); + sem.add(getSemantic(j)); dimName.add(getDimensionName(j)); minNbDim--; } @@ -831,18 +860,18 @@ // l'element i du tableau qui correcpond à la dimensions i de la // nouvelle matrice contient la dimension equivalente dans // la matrice actuelle - int[] correspondance = new int[getNbDim()]; + int[] correspondance = new int[getDimCount()]; // les nouvelles semantiques - List sem = new ArrayList(); + List<Object> sem = new ArrayList<Object>(); // les nouveaux noms de dimensions - List dimName = new ArrayList(); - for (int j = getNbDim() - 1; j >= 0; j--) { + List<Object> dimName = new ArrayList<Object>(); + for (int j = getDimCount() - 1; j >= 0; j--) { // si la dimension à plus d'un élément ou si on a pas assez de // dimension pour avoir le minimum demandé on prend la dimension if (getDim(j) > 1 || j < minNbDim) { // on ne conserve que les dimensions supérieure à 1 correspondance[sem.size()] = j; - sem.add(getSemantics(j)); + sem.add(getSemantic(j)); dimName.add(getDimensionName(j)); // on vient de prendre une dimension il nous en faut une de // moins @@ -863,15 +892,16 @@ * returned matrix * @return new matrix */ - protected MatrixND reduce(List dimName, List sem, int[] correspondance) { + protected MatrixND reduce(List<Object> dimName, List<Object> sem, + int[] correspondance) { // on converti les listes en tableau en inversant l'ordre car on // a fait un parcours en sens inverse int nbDim = sem.size(); - List[] newSemantics = new List[nbDim]; + List<?>[] newSemantics = new List<?>[nbDim]; String[] newDimNames = new String[nbDim]; int[] tmpcorrespondance = new int[nbDim]; for (int i = 0; i < nbDim; i++) { - newSemantics[i] = (List) sem.get(nbDim - 1 - i); + newSemantics[i] = (List<?>) sem.get(nbDim - 1 - i); newDimNames[i] = (String) dimName.get(nbDim - 1 - i); tmpcorrespondance[i] = correspondance[nbDim - 1 - i]; } @@ -881,7 +911,7 @@ newDimNames); // on reprend les valeurs - int[] newCoordinates = new int[result.getNbDim()]; + int[] newCoordinates = new int[result.getDimCount()]; for (MatrixIterator mi = iterator(); mi.next();) { int[] oldCoordinates = mi.getCoordinates(); for (int i = 0; i < newCoordinates.length; i++) { @@ -894,7 +924,7 @@ @Override public MatrixND mult(MatrixND m) throws MatrixException { - if (this.getNbDim() > 2 || m.getNbDim() > 2) { + if (this.getDimCount() > 2 || m.getDimCount() > 2) { throw new MatrixException( "La multiplication de matrice n'est pas applicable aux matrices de plus de 2 dimensions"); } @@ -965,7 +995,7 @@ */ @Override public boolean isSupportedCSV() { - return getNbDim() <= 2; + return getDimCount() <= 2; } /** @@ -1090,7 +1120,7 @@ @Override public void exportCSV(Writer writer, boolean withSemantics) throws IOException { - int dimsCount = getNbDim(); + int dimsCount = getDimCount(); int rowsCount = dimsCount == 1 ? 1 : getDim(0); int columnsCount = dimsCount == 1 ? getDim(0) : getDim(1); int[] coordinates; @@ -1102,7 +1132,7 @@ /* Création de l'entete */ if (withSemantics) { /* Recuperation de la liste sur la bonne dimenssion */ - List listSemantics = getSemantics(dimsCount - 1); + List<?> listSemantics = getSemantic(dimsCount - 1); /* Ajout d'un décalage de l'entete pour la dimenssion 2 */ writer.append(dimsCount == 2 ? " " + CSV_SEPARATOR : ""); for (Object semantic : listSemantics) { @@ -1114,7 +1144,7 @@ for (int rowNb = 0; rowNb < rowsCount; rowNb++) { /* Ajout de la semantic devant la ligne pour la dimenssion 2 */ if (withSemantics && dimsCount == 2) { - Object semantic = getSemantics(0).get(rowNb); + Object semantic = getSemantic(0).get(rowNb); writer.append("\"" + semantic + "\"" + CSV_SEPARATOR); } Modified: trunk/src/main/java/org/nuiton/math/matrix/BasicMatrix.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/BasicMatrix.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/BasicMatrix.java 2009-07-17 16:18:45 UTC (rev 168) @@ -42,7 +42,7 @@ protected int[] dimensions = null; /** La matrice en représentation linéaire */ protected Vector data = null; - + /** * tableau de facteur permettant de convertir les coordonnées dans la * matrice en un indice dans la représentation linéaire de la matrice @@ -50,7 +50,10 @@ protected int[] linearFactor = null; /** - * Crée une nouvelle matrice ayant les dimensions demandées + * Crée une nouvelle matrice ayant les dimensions demandées. + * + * @param factory factory + * @param dimensions dimensions */ public BasicMatrix(MatrixFactory factory, int[] dimensions) { this.factory = factory; @@ -206,8 +209,8 @@ for (int i = 0; i < dim.length; i++) { if (dim[i] <= 0) { throw new IllegalArgumentException(I18n._( - "lutinmatrix.invalid.size", Integer.valueOf(i), - Integer.valueOf(dim[i]))); + "lutinmatrix.invalid.size", Integer.valueOf(i), Integer + .valueOf(dim[i]))); } } } @@ -313,12 +316,12 @@ @Override public boolean next() { + boolean result = false; if (hasNext()) { pos++; return true; - } else { - return false; } + return result; } @Override Modified: trunk/src/main/java/org/nuiton/math/matrix/BasicMatrixIterator.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/BasicMatrixIterator.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/BasicMatrixIterator.java 2009-07-17 16:18:45 UTC (rev 168) @@ -39,21 +39,29 @@ /** * Passe à l'élément suivant. + * + * @return vrai s'il y a un suivant, faux sinon */ public boolean next(); /** * Retourne les coordonnés de l'élément. + * + * @return current element coordinates */ public int[] getCoordinates(); /** * Retourne la valeur courant pointé par l'iterator. + * + * @return current element value */ public double getValue(); /** * Modifie la valeur courant pointé par l'iterator. + * + * @param value new value to set to current element */ public void setValue(double value); Modified: trunk/src/main/java/org/nuiton/math/matrix/FloatVector.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/FloatVector.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/FloatVector.java 2009-07-17 16:18:45 UTC (rev 168) @@ -259,7 +259,7 @@ public void add(Vector v) { FloatVector fbv = (FloatVector) v; for (int i = 0; i < data.size(); i++) { - data.set(i, (float) (data.get(i) + fbv.data.get(i))); + data.set(i, data.get(i) + fbv.data.get(i)); } } @@ -267,7 +267,7 @@ public void minus(Vector v) { FloatVector fbv = (FloatVector) v; for (int i = 0; i < data.size(); i++) { - data.set(i, (float) (data.get(i) - fbv.data.get(i))); + data.set(i, data.get(i) - fbv.data.get(i)); } } Modified: trunk/src/main/java/org/nuiton/math/matrix/MapFunction.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MapFunction.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MapFunction.java 2009-07-17 16:18:45 UTC (rev 168) @@ -42,4 +42,3 @@ public double apply(double value); } // MapFunction - Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixEncoder.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixEncoder.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixEncoder.java 2009-07-17 16:18:45 UTC (rev 168) @@ -48,14 +48,17 @@ * représentation chaine les objets Un objet deviendra donc une chaine de * caractere lors de la lecture de la matrice à partir du XML si cette * méthode n'est pas surchargée. Le seul objet convenablement supporté sont - * les représentation objet des types primitifs + * les représentation objet des types primitifs. + * + * @throws IOException + * @return semntics as xml */ protected String getSemanticsAsXml(Object o) throws IOException { - if (o == null) { - // on ne fait rien car la valeur par defaut lorsqu'on relit - // la matrice est null - return null; - } else { + String xml = null; + + // on ne fait rien car la valeur par defaut lorsqu'on relit + // la matrice est null + if (o != null) { // par defaut si on ne sait pas comment mettre en XML un objet // on dit qu'il est de type String et on appelle la methode // toString sur l'objet @@ -64,9 +67,10 @@ if (o instanceof Number || o instanceof Boolean) { type = o.getClass().getName(); } - return "<object type=\"" + type + "\">" + o.toString() + xml = "<object type=\"" + type + "\">" + o.toString() + "</object>"; } + return xml; } public void writeMatrice(MatrixND mat) throws IOException { @@ -80,7 +84,7 @@ out.write("\" type=\"" + mat.getClass().getName() + "\">\n"); // ecriture des noms des dimensions - for (int i = 0; i < mat.getNbDim(); i++) { + for (int i = 0; i < mat.getDimCount(); i++) { String dimName = mat.getDimensionName(i); // si le nom est non null et non vide on l'ecrit, // sinon c la valeur par defaut lorsqu'on relit la matrice @@ -93,11 +97,11 @@ } // ecriture de la semantique - for (int i = 0; i < mat.getNbDim(); i++) { - List sem = mat.getSemantics(i); - List semAsXml = new ArrayList(); + for (int i = 0; i < mat.getDimCount(); i++) { + List<?> sem = mat.getSemantic(i); + List<Object> semAsXml = new ArrayList<Object>(); boolean haveNotNull = false; - for (Iterator e = sem.iterator(); e.hasNext();) { + for (Iterator<?> e = sem.iterator(); e.hasNext();) { String xml = getSemanticsAsXml(e.next()); semAsXml.add(xml); haveNotNull = haveNotNull || xml != null; Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixException.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixException.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixException.java 2009-07-17 16:18:45 UTC (rev 168) @@ -30,7 +30,7 @@ public class MatrixException extends RuntimeException { - /** serialVersionUID */ + /** serialVersionUID. */ private static final long serialVersionUID = 1917420713781767581L; public MatrixException(String s) { @@ -41,4 +41,4 @@ super(s, e); } -} // MatriceException +} // MatrixException Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixFactory.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixFactory.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixFactory.java 2009-07-17 16:18:45 UTC (rev 168) @@ -95,32 +95,37 @@ }*/ /** Valeur par defaut si aucun type de Vector n'est donné */ - protected static Class defaultVectorClass = DoubleBigVector.class; + protected static Class<?> defaultVectorClass = DoubleBigVector.class; - protected Class vectorClass = null; + protected Class<?> vectorClass = null; - protected MatrixFactory(Class vectorClass) { + protected MatrixFactory(Class<?> vectorClass) { this.vectorClass = vectorClass; } - public static void setDefaultVectorClass(Class vectorClass) { + public static void setDefaultVectorClass(Class<?> vectorClass) { defaultVectorClass = vectorClass; } - public static Class getDefaultVectorClass() { + public static Class<?> getDefaultVectorClass() { return defaultVectorClass; } /** * Retourne une factory utilisant vectorClass comme classe de base a - * l'implantation des matrices + * l'implantation des matrices. + * + * @param vectorClass vector class implememantation + * @return factory */ - public static MatrixFactory getInstance(Class vectorClass) { + public static MatrixFactory getInstance(Class<?> vectorClass) { return new MatrixFactory(vectorClass); } /** - * Utilise par defaut {@link FloatBigVector} + * Utilise par defaut {@link FloatBigVector}. + * + * @return factory */ public static MatrixFactory getInstance() { return getInstance(defaultVectorClass); @@ -165,7 +170,7 @@ return matrix; } - public MatrixND create(List[] semantics) { + public MatrixND create(List<Object>[] semantics) { return new MatrixNDImpl(this, semantics); } @@ -177,11 +182,11 @@ return new MatrixNDImpl(this, name, dim, dimNames); } - public MatrixND create(String name, List[] semantics) { + public MatrixND create(String name, List<?>[] semantics) { return new MatrixNDImpl(this, name, semantics); } - public MatrixND create(String name, List[] semantics, String[] dimNames) { + public MatrixND create(String name, List<?>[] semantics, String[] dimNames) { return new MatrixNDImpl(this, name, semantics, dimNames); } @@ -207,7 +212,7 @@ protected Vector createVector(int length) { try { - Constructor c = vectorClass + Constructor<?> c = vectorClass .getConstructor(new Class[] { Integer.TYPE }); return (Vector) c.newInstance(new Object[] { length }); } catch (Exception eee) { Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixHelper.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixHelper.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixHelper.java 2009-07-17 16:18:45 UTC (rev 168) @@ -24,9 +24,6 @@ import java.util.NoSuchElementException; import java.util.Stack; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - /** * Contains usefull methods to get information on matrix. * @@ -40,15 +37,12 @@ */ public class MatrixHelper { // MatrixHelper - /** Class logger */ - private static Log log = LogFactory.getLog(MatrixHelper.class); - /** * Convert Matrix to identity matrix must have 2 dimensions. If dimension * haven't same length, then the small dimension is used. * - * @param mat - * @return + * @param mat matrix nd to convert + * @return converted matrix */ public static MatrixND convertToId(MatrixND mat) { int size = mat.getDim(0); @@ -79,9 +73,9 @@ * @param s la chaine representant les listes de liste * @return une liste de liste ... de Double */ - public static List convertStringToList(String s) { - List result = null; - Stack<List> stack = new Stack<List>(); + public static List<Object> convertStringToList(String s) { + List<Object> result = null; + Stack<List<Object>> stack = new Stack<List<Object>>(); StringBuffer number = new StringBuffer(20); // initial to 20 char for (int i = 0; i < s.length(); i++) { @@ -90,7 +84,7 @@ // skip space } if (c == '[') { - stack.push(new ArrayList()); + stack.push(new ArrayList<Object>()); } else if (c == ',') { if (number.length() != 0) { // on a une ',' on doit donc avoir un nombre dans number @@ -108,7 +102,7 @@ number.setLength(0); } - List current = stack.pop(); + List<Object> current = stack.pop(); if (stack.empty()) { result = current; } else { @@ -162,6 +156,10 @@ /** * Permet de savoir si deux dimension sont identiques. + * + * @param dim1 first dimensions + * @param dim2 second dimensions + * @return dimension equality */ public static boolean sameDimension(int[] dim1, int[] dim2) { return Arrays.equals(dim1, dim2); @@ -177,7 +175,7 @@ * a pas de semantique (liste pleine de null) alors un objet Integer * est créer pour représenter la semantique de la dimension. */ - public static Object[] dimensionToSemantics(List[] semantics, + public static Object[] dimensionToSemantics(List<?>[] semantics, int[] coordinates) { Object[] result = new Object[coordinates.length]; for (int i = 0; i < result.length; i++) { @@ -200,7 +198,7 @@ * Integer alors la valeur de l'integer est utilisé pour la * conversion. */ - public static int[] semanticsToDimension(List[] semantics, + public static int[] semanticsToDimension(List<?>[] semantics, Object[] coordinates) { int[] result = new int[coordinates.length]; for (int i = 0; i < coordinates.length; i++) { @@ -223,7 +221,7 @@ * * @throws NoSuchElementException If element doesn't exists */ - public static int indexOf(List[] semantics, int dim, Object o) + public static int indexOf(List<?>[] semantics, int dim, Object o) throws NoSuchElementException { if (o instanceof Integer) { return ((Integer) o).intValue(); Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixIterator.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixIterator.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixIterator.java 2009-07-17 16:18:45 UTC (rev 168) @@ -32,7 +32,9 @@ /** * Retourne les coordonnés de l'élément, en sémantique. Si la matrice n'a - * pas de sémantique alors retourne null + * pas de sémantique alors retourne null. + * + * @return current element semantics */ public Object[] getSemanticsCoordinates(); Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixIteratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixIteratorImpl.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixIteratorImpl.java 2009-07-17 16:18:45 UTC (rev 168) @@ -33,7 +33,7 @@ public class MatrixIteratorImpl implements MatrixIterator { // MatrixIteratorImpl protected BasicMatrixIterator iterator = null; - protected List[] semantics = null; + protected List<?>[] semantics = null; protected int pos = 0; /** @@ -41,7 +41,7 @@ * @param semantics la semantique de matrix, si matrix n'a pas de semantique * alors il faut passer null */ - public MatrixIteratorImpl(BasicMatrixIterator iterator, List[] semantics) { + public MatrixIteratorImpl(BasicMatrixIterator iterator, List<?>[] semantics) { this.iterator = iterator; this.semantics = semantics; pos = 0; @@ -68,14 +68,13 @@ } public Object[] getSemanticsCoordinates() { - if (semantics == null) { - return null; - } else { + Object[] result = null; + if (semantics != null) { int[] coordinates = getCoordinates(); - Object[] result = MatrixHelper.dimensionToSemantics(semantics, + result = MatrixHelper.dimensionToSemantics(semantics, coordinates); - return result; } + return result; } } // MatrixIteratorImpl Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixND.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixND.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixND.java 2009-07-17 16:18:45 UTC (rev 168) @@ -52,7 +52,7 @@ * * @return la liste des semantics */ - public List[] getSemantics(); + public List<?>[] getSemantics(); /** * Retourne la semantique pour une dimension @@ -60,15 +60,39 @@ * @param dim la dimension pour lequel on veut la semantique * @return la semantique de la dimension on null s'il n'y a pas de * semantique + * + * @deprecated use #getSemantic(int) instead */ - public List getSemantics(int dim); + public List<?> getSemantics(int dim); /** + * Retourne la semantique pour une dimension + * + * @param dim la dimension pour lequel on veut la semantique + * @return la semantique de la dimension on null s'il n'y a pas de + * semantique + */ + public List<?> getSemantic(int dim); + + /** * Modifie la semantique d'une dimension + * + * @param dim dimension to modify semantic + * @param sem new semantic to set + * + * @deprecated use #setSemantics(int, List<E>) instead */ - public void setSemantics(int dim, List sem); + public <E> void setSemantics(int dim, List<E> sem); /** + * Modifie la semantique d'une dimension + * + * @param dim dimension to modify semantic + * @param sem new semantic to set + */ + public <E> void setSemantic(int dim, List<E> sem); + + /** * Permet de donner un nom à la matrice. * * @param name name to set @@ -85,6 +109,8 @@ /** * Permet de mettre des noms aux différentes dimension. * + * @param names names to set + * * @deprecated (since 1.0.3) Use #setDimensionNames(String[]) */ public void setDimensionName(String[] names); @@ -144,26 +170,46 @@ /** * Retourne le nombre de dimensions de la matrice. + * + * @return le nombre de dimensions de la matrice. + * @deprecated use #getDimCount() instead */ public int getNbDim(); /** + * Retourne le nombre de dimensions de la matrice. + * + * @return le nombre de dimensions de la matrice. + */ + public int getDimCount(); + + /** * Retourne les dimensions de la matrice. + * + * @return matrix dimension */ public int[] getDim(); /** - * Retourne la dimension de la matrice dans la dimension d + * Retourne la dimension de la matrice dans la dimension d. + * + * @param d dimension + * @return matrix dimension */ public int getDim(int d); /** - * Retourne un iterator sur toute la matrice + * Retourne un iterator sur toute la matrice. + * + * @return matrix iterator */ public MatrixIterator iterator(); /** - * Applique une fonction sur chaque valeur de la matrice + * Applique une fonction sur chaque valeur de la matrice. + * + * @param f function to apply + * @return <tt>this</tt> */ public MatrixND map(MapFunction f); @@ -278,22 +324,19 @@ /** * Copy la matrice pour pouvoir la modifier sans perdre les donnees * initiales. + * + * @return new matrix */ public MatrixND copy(); /** * Créer une nouvelle instance clonée de celle-ci + * + * @return new matrix */ public MatrixND clone(); - // public String toString(); - // /** - // * Verifie si les 2 matrices sont egal - // */ - // public boolean equals(Object o); - - // /** // * Verifie si les dimensions sont valide pour cette matrice // * @return vrai si dim a la même taille que le tableau de dimensions de la // * matrice et si chaque valeur de dim est comprise entre 0 (inclus) et @@ -302,7 +345,9 @@ // public boolean dimValid(int [] dim); /** - * Somme toutes les valeurs de la matrice + * Somme toutes les valeurs de la matrice. + * + * @return sum result */ public double sumAll(); @@ -324,6 +369,7 @@ * </pre> * * @param dim la dimension sur lequel il faut faire la somme + * @return new matrix */ public MatrixND sumOverDim(int dim); @@ -420,6 +466,9 @@ * Modifie la matrice actuel en metant les valeurs de mat passé en parametre * La copie se fait en fonction de la semantique, si un element dans une * dimension n'est pas trouvé, alors il est passé + * + * @param mat matrix to paste + * @return new matrix */ public MatrixND pasteSemantics(MatrixND mat); @@ -473,6 +522,7 @@ * @param nb le nombre d'élément à prendre dans la dimension. si nb est * inférieur ou égal à 0 alors cela indique qu'il faut prendre * tous les éléments jusqu'à la fin de la dimension. + * @return new matrix */ public MatrixND getSubMatrix(int dim, Object start, int nb); @@ -489,6 +539,7 @@ * @param nb le nombre d'élément à prendre dans la dimension si nb est * inférieur ou égal à 0 alors cela indique qu'il faut prendre * tous les éléments jusqu'à la fin de la dimension. + * @return new matrix */ public MatrixND getSubMatrix(int dim, int start, int nb); @@ -499,6 +550,7 @@ * * @param dim la dimension dans lequel on veut une sous matrice * @param elem les éléments dans la dimension à conserver + * @return new matrix */ public MatrixND getSubMatrix(int dim, Object... elem); @@ -509,23 +561,32 @@ * * @param dim la dimension dans lequel on veut une sous matrice * @param elem les éléments dans la dimension à conserver + * @return new matrix */ public MatrixND getSubMatrix(int dim, int[] elem); /** * Addition la matrice courante avec la matrice passe en parametre et ce - * retourne elle meme + * retourne elle meme. + * + * @param m matrix to add + * @return new matrix */ public MatrixND add(MatrixND m); /** * Soustrai la matrice courante avec la matrice passe en parametre et ce - * retourne elle meme + * retourne elle meme. + * + * @param m matrix to minus + * @return new matrix */ public MatrixND minus(MatrixND m); /** - * retourne le transpose de la matrice + * retourne le transpose de la matrice. + * + * @return transposed matrix */ public MatrixND transpose(); @@ -562,48 +623,58 @@ public MatrixND reduceDims(int... dims); /** - * Multiplication normal de 2 matrices 2D. Retourne une nouvelle matrice + * Multiplication normal (produit matriciel) de 2 matrices 2D. + * + * @param m matrix to mult + * @return Retourne une nouvelle matrice. */ public MatrixND mult(MatrixND m); - // /** - // * multiplication terme a terme de la matrice courante avec la - // * matrice passe en parametre et ce retourne elle meme - // */ - // public MatrixND multm(MatrixND m); /** - * Multiplication d'une matrice par un scalaire + * Multiplication d'une matrice par un scalaire. + * + * @param d scalaire + * @return new matrix */ - public MatrixND mults(final double d); + public MatrixND mults(double d); /** - * Multiplication d'une matrice par un scalaire + * Multiplication d'une matrice par un scalaire. + * + * @param d scalaire + * @return new matrix */ - public MatrixND divs(final double d); + public MatrixND divs(double d); /** - * Addition d'un scalaire à une matrice + * Addition d'un scalaire à une matrice. + * + * @param d scalaire + * @return new matrix */ - public MatrixND adds(final double d); + public MatrixND adds(double d); /** - * Soustractiond'un scalaire à une matrice + * Soustraction d'un scalaire à une matrice + * + * @param d scalaire + * @return new matrix */ - public MatrixND minuss(final double d); + public MatrixND minuss(double d); /** * Donne la matrice sous forme de List de list ... de double * - * @return + * @return list matrix representation */ - public List toList(); + public List<Object> toList(); /** * Permet de charger une matrice a partir d'une representation List * * @param list la matrice sous forme de List de list ... de double */ - public void fromList(List list); + public void fromList(List<Object> list); /** * Determine si la matrice supporte l'import et l'export CSV @@ -617,6 +688,7 @@ * * @param reader le reader à importer * @param origin le point à partir duquel il faut faire l'importation + * @throws IOException */ public void importCSV(Reader reader, int[] origin) throws IOException; @@ -626,6 +698,7 @@ * @param writer le writer ou copier la matrice * @param withSemantics export ou pas des semantiques de la matrice dans le * writer + * @throws IOException */ public void exportCSV(Writer writer, boolean withSemantics) throws IOException; @@ -635,7 +708,7 @@ * pas les semantiques * * @param mat - * @return + * @return equlaity on values */ public boolean equalsValues(MatrixND mat); Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixNDImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixNDImpl.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixNDImpl.java 2009-07-17 16:18:45 UTC (rev 168) @@ -43,7 +43,7 @@ matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, List[] semantics) { + protected MatrixNDImpl(MatrixFactory factory, List<?>[] semantics) { super(factory, semantics); matrix = new BasicMatrix(factory, dim); } @@ -59,13 +59,14 @@ matrix = new BasicMatrix(factory, dim); } - protected MatrixNDImpl(MatrixFactory factory, String name, List[] semantics) { + protected MatrixNDImpl(MatrixFactory factory, String name, + List<?>[] semantics) { super(factory, name, semantics); matrix = new BasicMatrix(factory, dim); } protected MatrixNDImpl(MatrixFactory factory, String name, - List[] semantics, String[] dimNames) { + List<?>[] semantics, String[] dimNames) { super(factory, name, semantics, dimNames); matrix = new BasicMatrix(factory, dim); } Modified: trunk/src/main/java/org/nuiton/math/matrix/MatrixStringEncoder.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/MatrixStringEncoder.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/MatrixStringEncoder.java 2009-07-17 16:18:45 UTC (rev 168) @@ -85,7 +85,7 @@ * str must be in following format : * - [name,dim,dimNames,semantics,data] * @param str - * @return + * @return matrix representation */ public MatrixND getMatrixFromString(String str) { @@ -200,15 +200,15 @@ /** * Semantics array to string. * - * @param semanticsArray semantics arrayy + * @param semanticsArray semantics array * @return string names array */ - public String getSemanticsToString(List<Object>[] semanticsArray) { + public String getSemanticsToString(List<?>[] semanticsArray) { StringBuffer result = new StringBuffer("["); for (int i = 0; i < semanticsArray.length; i++) { result.append("["); - List<Object> semantics = semanticsArray[i]; - for (Iterator<Object> it = semantics.iterator(); it.hasNext();) { + List<?> semantics = semanticsArray[i]; + for (Iterator<?> it = semantics.iterator(); it.hasNext();) { appendString(result, it.next()); if (it.hasNext()) { result.append(", "); @@ -223,10 +223,10 @@ } /** - * String to samantics. + * String to semantics. * * @param str la chaine representant la semantique - * @return + * @return semantics list */ public List<Object>[] getSemanticsFromString(String str) { String localStr = str.trim(); @@ -251,6 +251,7 @@ * [null(), java.lang.String("toto"), ...] * * @param str la chaine representant + * @return semantics list */ public List<Object> splitObjects(String str) { List<Object> result = new LinkedList<Object>(); @@ -278,8 +279,7 @@ // if can't create objet, put String representation as semantics o = objectType + "(" + objectString + ")"; if (log.isWarnEnabled()) { - log - .warn("Continuing but can't convert object in matrix from String: '" + log.warn("Continuing but can't convert object in matrix from String: '" + o + "'"); } if (log.isDebugEnabled()) { @@ -324,7 +324,7 @@ * * Can't be overridden to put another impl. * - * @param o object to get qulified name + * @param o object to get qualified name * @return object qualified class name */ public String getQualifiedName(Object o) { Modified: trunk/src/main/java/org/nuiton/math/matrix/SemanticList.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/SemanticList.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/SemanticList.java 2009-07-17 16:18:45 UTC (rev 168) @@ -29,6 +29,8 @@ * * Created: 6 sept. 06 17:18:23 * + * @param <T> elements type + * * @author poussin * @version $Revision$ * @@ -67,19 +69,16 @@ */ @Override public int indexOf(Object o) { - Map index = getIndex(); - Integer result = (Integer) index.get(o); - if (result == null) { - return -1; - } else { - return result.intValue(); + Map<Object, Integer> index = getIndex(); + Integer result = index.get(o); + int resultIndex = -1; + if (result != null) { + resultIndex = result.intValue(); } + return resultIndex; } - /** - * @return - */ - protected Map getIndex() { + protected Map<Object, Integer> getIndex() { if (index == null) { index = new HashMap<Object, Integer>(); for (int i = 0; i < datas.size(); i++) { Modified: trunk/src/main/java/org/nuiton/math/matrix/SubMatrix.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/SubMatrix.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/SubMatrix.java 2009-07-17 16:18:45 UTC (rev 168) @@ -50,7 +50,7 @@ this.matrix = matrix; converter = new ShiftConverter(dim, start, nb); - setSemantics(dim, getSemantics(dim).subList(start, start + nb)); + setSemantic(dim, getSemantic(dim).subList(start, start + nb)); getDim()[dim] = nb; } @@ -61,12 +61,12 @@ converter = new MappingConverter(dim, elem); - List oldSemantic = getSemantics(dim); - List newSemantic = new LinkedList(); + List<?> oldSemantic = getSemantic(dim); + List<Object> newSemantic = new LinkedList<Object>(); for (int i = 0; i < elem.length; i++) { newSemantic.add(oldSemantic.get(elem[i])); } - setSemantics(dim, newSemantic); + setSemantic(dim, newSemantic); getDim()[dim] = elem.length; } @@ -90,10 +90,10 @@ public SubMatrixIteratorImpl(SubMatrix subMatrix) { this.subMatrix = subMatrix; - cpt = new int[subMatrix.getNbDim()]; + cpt = new int[subMatrix.getDimCount()]; cpt[cpt.length - 1] = -1; - last = new int[subMatrix.getNbDim()]; + last = new int[subMatrix.getDimCount()]; for (int i = 0; i < last.length; i++) { last[i] = subMatrix.getDim(i) - 1; } @@ -163,15 +163,16 @@ } public int[] convertCoordinates(int[] coordinates) { + int[] result = null; if (coordinates[dim] < nb) { - int[] result = new int[coordinates.length]; + result = new int[coordinates.length]; System.arraycopy(coordinates, 0, result, 0, result.length); result[dim] = result[dim] + start; - return result; } else { throw new NoSuchElementException( "L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension."); } + return result; } } @@ -193,15 +194,17 @@ } public int[] convertCoordinates(int[] coordinates) { + int[] result = null; if (coordinates[dim] < elem.length) { - int[] result = new int[coordinates.length]; + result = new int[coordinates.length]; System.arraycopy(coordinates, 0, result, 0, result.length); result[dim] = elem[coordinates[dim]]; - return result; + } else { throw new NoSuchElementException( "L'indice est supérieur au nombre d'élements de la sous matrice pour cette dimension."); } + return result; } } Modified: trunk/src/main/java/org/nuiton/math/matrix/Vector.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/Vector.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/Vector.java 2009-07-17 16:18:45 UTC (rev 168) @@ -39,42 +39,61 @@ public int size(); /** - * Permet de savoir si paste est implanté par ce vector + * Permet de savoir si paste est implanté par ce vector. + * + * @param v vector to test + * @return <tt>true</tt> if operation is supported */ public boolean isImplementedPaste(Vector v); /** - * Permet de savoir si add est implanté par ce vector + * Permet de savoir si add est implanté par ce vector. + * + * @param v vector to test + * @return <tt>true</tt> if operation is supported */ public boolean isImplementedAdd(Vector v); /** - * Permet de savoir si minus est implanté par ce vector + * Permet de savoir si minus est implanté par ce vector. + * + * @param v vector to test + * @return <tt>true</tt> if operation is supported */ public boolean isImplementedMinus(Vector v); /** - * Permet de savoir si map est implanté par ce vector + * Permet de savoir si map est implanté par ce vector. + + * @return <tt>true</tt> if operation is supported */ public boolean isImplementedMap(); /** - * Copie les valeurs du vector passé en argument dans ce vector + * Copie les valeurs du vector passé en argument dans ce vector. + * + * @param v vector to paste */ public void paste(Vector v); /** - * Ajoute les valeurs du vector passé en argument a ce vector + * Ajoute les valeurs du vector passé en argument a ce vector. + * + * @param v vector to add */ public void add(Vector v); /** - * soustrai les valeurs du vector passé en argument a ce vector + * Soustrait les valeurs du vector passé en argument a ce vector. + * + * @param v vector to minus */ public void minus(Vector v); /** - * applique a chaque valeur du vector la MapFunction + * applique a chaque valeur du vector la {@link MapFunction}. + * + * @param f funtion to apply */ public void map(MapFunction f); Modified: trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixEditor.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixEditor.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixEditor.java 2009-07-17 16:18:45 UTC (rev 168) @@ -1,4 +1,4 @@ -/** +/* * *##% NuitonMatrix * Copyright (C) 2004 - 2009 CodeLutin * @@ -29,13 +29,16 @@ */ public abstract class MatrixEditor extends JPanel { + /** serialVersionUID. */ + private static final long serialVersionUID = 991329794990004265L; + protected boolean enabled = false; protected boolean visible = false; - // Return JTable componant + // Return JTable component public abstract JTable getTable(); - // Return edit button componant + // Return edit button component public abstract JButton getButtonEdit(); // Fire the matrix @@ -44,7 +47,7 @@ // Return matrixND public abstract MatrixND getMatrix(); - // Inisialize matrixND + // Initialize matrixND public abstract void setMatrix(MatrixND matrix); /** Modified: trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelEditor.java 2009-07-17 16:18:45 UTC (rev 168) @@ -478,7 +478,7 @@ */ MatrixND m = MatrixFactory.getInstance().create("name", - new List<?>[]{sem1, sem2, sem3}, + new List[]{sem1, sem2, sem3}, new String[]{"dim1", "dim2", "dim3"}); m.setValue(0, 0, 0, 1); Modified: trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelListener.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelListener.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPanelListener.java 2009-07-17 16:18:45 UTC (rev 168) @@ -16,6 +16,8 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ package org.nuiton.math.matrix.gui; +import java.util.EventListener; + /** * MatrixPanelListener. * @@ -27,7 +29,7 @@ * Last update: $Date$ * by : $Author$ */ -public interface MatrixPanelListener extends java.util.EventListener { +public interface MatrixPanelListener extends EventListener { /** * called when matrix change Modified: trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixPopupMenu.java 2009-07-17 16:18:45 UTC (rev 168) @@ -251,7 +251,7 @@ int nbSelectedColumn = matrixEditor.getTable().getSelectedColumnCount(); /* Prend en compte le décalage des lignes par rapport aux dimenssions */ - int nbColumnDimRow = matrixEditor.getMatrix().getNbDim() - 1; + int nbColumnDimRow = matrixEditor.getMatrix().getDimCount() - 1; beginSelectedColumn -= nbColumnDimRow; if (beginSelectedColumn < 0) { beginSelectedColumn = 0; @@ -261,14 +261,16 @@ int beginSelectedRow = matrixEditor.getTable().getSelectedRow() - 1; int nbSelectedRow = matrixEditor.getTable().getSelectedRowCount(); - if (getMatrix().getNbDim() == 1) { - return matrixEditor.getMatrix().getSubMatrix(0, + MatrixND result = null; + if (getMatrix().getDimCount() == 1) { + result = matrixEditor.getMatrix().getSubMatrix(0, beginSelectedColumn, nbSelectedColumn); } else { - return matrixEditor.getMatrix().getSubMatrix(0, beginSelectedRow, + result= matrixEditor.getMatrix().getSubMatrix(0, beginSelectedRow, nbSelectedRow).getSubMatrix(1, beginSelectedColumn, nbSelectedColumn); } + return result; } /** @@ -278,7 +280,7 @@ int selectedColumn = matrixEditor.getTable().getSelectedColumn(); /* Prend en compte le décalage des lignes par rapport aux dimenssions */ - int nbColumnDimRow = matrixEditor.getMatrix().getNbDim() - 1; + int nbColumnDimRow = matrixEditor.getMatrix().getDimCount() - 1; selectedColumn -= nbColumnDimRow; if (selectedColumn < 0) { selectedColumn = 0; @@ -382,7 +384,7 @@ return sendToClipBoardCurrentPasteAction; } - private void sendToClipBoardAllCopyPerformed() { + protected void sendToClipBoardAllCopyPerformed() { try { Writer writer = getClipBoardWriter(); getMatrix().exportCSV(writer, withSemantics.getState()); @@ -400,7 +402,7 @@ } } - private void sendToClipBoardAllPastePerformed() { + protected void sendToClipBoardAllPastePerformed() { try { Reader reader = getClipBoardReader(); getMatrix().importCSV(reader, new int[] { 0, 0 }); @@ -415,7 +417,7 @@ } } - private void sendToClipBoardSelectionCopyPerformed() { + protected void sendToClipBoardSelectionCopyPerformed() { try { Writer writer = getClipBoardWriter(); getSelectedMatrix().exportCSV(writer, withSemantics.getState()); @@ -433,7 +435,7 @@ } } - private void sendToClipBoardCurrentPastePerformed() { + protected void sendToClipBoardCurrentPastePerformed() { try { Reader reader = getClipBoardReader(); getMatrix().importCSV(reader, @@ -509,7 +511,7 @@ return sendToFileCurrentPasteAction; } - private void sendToFileAllCopyPerformed() { + protected void sendToFileAllCopyPerformed() { try { Writer writer = getFileChooserWriter(); if (writer != null) { @@ -525,7 +527,7 @@ } } - private void sendToFileAllPastePerformed() { + protected void sendToFileAllPastePerformed() { try { Reader reader = getFileChooserReader(); if (reader != null) { // cancel @@ -542,7 +544,7 @@ } } - private void sendToFileSelectionCopyPerformed() { + protected void sendToFileSelectionCopyPerformed() { try { Writer writer = getFileChooserWriter(); if (writer != null) { @@ -558,7 +560,7 @@ } } - private void sendToFileCurrentPastePerformed() { + protected void sendToFileCurrentPastePerformed() { try { Reader reader = getFileChooserReader(); if (reader != null) { // cancel Modified: trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelLinear.java 2009-07-17 16:18:45 UTC (rev 168) @@ -146,7 +146,7 @@ */ @Override public int getColumnCount() { - return m.getNbDim() + 1; + return m.getDimCount() + 1; } /* @@ -155,7 +155,7 @@ @Override public Object getValueAt(int rowIndex, int columnIndex) { Object result = null; - if (columnIndex < m.getNbDim()) { + if (columnIndex < m.getDimCount()) { result = mappingRowSems.get(rowIndex)[columnIndex]; } else { result = m.getValue(mappingRowSems.get(rowIndex)); @@ -168,7 +168,7 @@ */ @Override public boolean isCellEditable(int rowIndex, int columnIndex) { - return isEnabled() && columnIndex == m.getNbDim(); + return isEnabled() && columnIndex == m.getDimCount(); } /* @@ -194,7 +194,7 @@ @Override public String getColumnName(int column) { String result = null; - if (column < m.getNbDim()) { + if (column < m.getDimCount()) { result = m.getDimensionName(column); } else { result = ""; @@ -211,9 +211,6 @@ return String.class; } - /** - * @return - */ @Override public TableCellRenderer getMatrixCellRenderer() { if (renderer == null) { @@ -249,7 +246,7 @@ hasFocus, row, column); setToolTipText(getText()); - if (column < model.m.getNbDim()) { + if (column < model.m.getDimCount()) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Modified: trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java =================================================================== --- trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/main/java/org/nuiton/math/matrix/gui/MatrixTableModelND.java 2009-07-17 16:18:45 UTC (rev 168) @@ -100,12 +100,12 @@ @Override public void setMatrix(MatrixND m) { this.m = m; - addRow = m.getNbDim() / 2; - addCol = (m.getNbDim() + 1) / 2; + addRow = m.getDimCount() / 2; + addCol = (m.getDimCount() + 1) / 2; // calcule les coefficients multiplicateur pour la correspondance // table/matrice - multRowCol = new int[m.getNbDim()]; + multRowCol = new int[m.getDimCount()]; for (int i = multRowCol.length - 1; i >= 0; i--) { if (i >= multRowCol.length - 2) { multRowCol[i] = 1; @@ -123,7 +123,7 @@ * @return les coordonnées equivalentes dans la matrice */ protected int[] tableToMatrix(int row, int col) { - int[] result = new int[m.getNbDim()]; + int[] result = new int[m.getDimCount()]; for (int i = 0; i < result.length; i++) { int val = row; if (i % 2 == 1) { // si impaire alors la valeur vient de la colonne @@ -184,7 +184,7 @@ */ protected String getSemantic(int dim, int elem) { - Object o = m.getSemantics(dim).get(elem); + Object o = m.getSemantic(dim).get(elem); return (o == null) ? "" : o.toString(); } @@ -206,7 +206,7 @@ @Override public int getRowCount() { int result = 0; - if (m.getNbDim() != 1) { + if (m.getDimCount() != 1) { // result = multRowCol[0] * m.getDim(0) + addRow - 1; // -1 pour le // header result = multRowCol[0] * m.getDim(0) + addRow; @@ -222,7 +222,7 @@ @Override public int getColumnCount() { int result = 0; - if (m.getNbDim() != 1) { + if (m.getDimCount() != 1) { result = multRowCol[1] * m.getDim(1) + addCol; } else { result = m.getDim(0); @@ -238,7 +238,7 @@ @Override public Object getValueAt(int row, int column) { Object result = null; - if (m.getNbDim() != 1) { + if (m.getDimCount() != 1) { // // on fait row + 1 a cause du header // result = getValue(row + 1, column); result = getValue(row, column); @@ -255,12 +255,12 @@ */ @Override public void setValueAt(Object obj, int row, int column) { - if ((m.getNbDim() != 1 && row >= addRow && column >= addCol) - || (m.getNbDim() == 1 && row >= 1)) { + if ((m.getDimCount() != 1 && row >= addRow && column >= addCol) + || (m.getDimCount() == 1 && row >= 1)) { try { double val = Double.parseDouble((String) obj); int[] coord = null; - if (m.getNbDim() != 1) { + if (m.getDimCount() != 1) { // coord = tableToMatrix(row - addRow + 1, column - addCol); // // +1 pour le header coord = tableToMatrix(row - addRow, column - addCol); @@ -280,9 +280,9 @@ @Override public boolean isCellEditable(int row, int column) { - if (m.getNbDim() != 1 && (row < addRow || column < addCol)) { + if (m.getDimCount() != 1 && (row < addRow || column < addCol)) { return false; - } else if (m.getNbDim() == 1 && row < 1) { + } else if (m.getDimCount() == 1 && row < 1) { return false; } return enabled; @@ -333,8 +333,8 @@ hasFocus, row, column); setToolTipText(getText()); - if ((model.m.getNbDim() != 1 && (row < model.addRow || column < model.addCol)) - || (model.m.getNbDim() == 1 && row < 1)) { + if ((model.m.getDimCount() != 1 && (row < model.addRow || column < model.addCol)) + || (model.m.getDimCount() == 1 && row < 1)) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Modified: trunk/src/test/java/org/nuiton/math/matrix/MatrixNDTest.java =================================================================== --- trunk/src/test/java/org/nuiton/math/matrix/MatrixNDTest.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/test/java/org/nuiton/math/matrix/MatrixNDTest.java 2009-07-17 16:18:45 UTC (rev 168) @@ -30,8 +30,8 @@ import org.junit.Assert; import org.junit.Test; -/* * - * AppTestCase.java +/** + * MatrixNDTest.java * * Created: 10 mai 2004 * @@ -48,9 +48,9 @@ @Test public void testNew() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; @@ -66,31 +66,31 @@ @Test public void testSemantique() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; mat = getFactory().create(new int[] { 3, 3, 3 }); - Assert.assertNull(mat.getSemantics(1).get(1)); + Assert.assertNull(mat.getSemantic(1).get(1)); mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }); // la matrice doit avoir ca propre copie des semantiques s2.set(1, "pas bon"); - Assert.assertEquals("f", mat.getSemantics(1).get(1)); + Assert.assertEquals("f", mat.getSemantic(1).get(1)); mat.setSemantics(1, s1); - Assert.assertEquals("b", mat.getSemantics(1).get(1)); + Assert.assertEquals("b", mat.getSemantic(1).get(1)); } @Test public void testName() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; @@ -108,9 +108,9 @@ @Test public void testGetSet() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; @@ -145,9 +145,9 @@ { "c", "f", "l" }, { "c", "f", "m" }, { "c", "g", "k" }, { "c", "g", "l" }, { "c", "g", "m" }, }; - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; @@ -167,9 +167,9 @@ @Test public void testAdd() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -190,9 +190,9 @@ @Test public void testMinus() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -213,9 +213,9 @@ @Test public void testEquals() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -238,9 +238,9 @@ @Test public void testsumOverDim() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat = null; @@ -345,9 +345,9 @@ @Test public void testMults() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -374,9 +374,9 @@ @Test public void testDivs() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -398,9 +398,9 @@ @Test public void testAdds() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -422,9 +422,9 @@ @Test public void testMinuss() throws Exception { - List s1 = Arrays.asList(new String[] { "a", "b", "c" }); - List s2 = Arrays.asList(new String[] { "e", "f", "g" }); - List s3 = Arrays.asList(new String[] { "k", "l", "m" }); + List<String> s1 = Arrays.asList(new String[] { "a", "b", "c" }); + List<String> s2 = Arrays.asList(new String[] { "e", "f", "g" }); + List<String> s3 = Arrays.asList(new String[] { "k", "l", "m" }); MatrixND mat1 = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, @@ -718,7 +718,7 @@ mat1.setValue(0, 0, 0, 1.0E-7); mat1.setValue(1, 1, 0, 2); mat1.setValue(2, 1, 0, 5.0E-7); - List l = mat1.toList(); + List<Object> l = mat1.toList(); System.out.println(l); MatrixND mat2 = getFactory().create(new int[] { 3, 2, 1 }); @@ -730,9 +730,9 @@ Assert.assertEquals(mat1, mat2); String s = String.valueOf(l); - List l2 = convertStringToList2(s); - List l1 = convertStringToList1(s); - List l0 = convertStringToList0(s); + List<Object> l2 = convertStringToList2(s); + List<Object> l1 = convertStringToList1(s); + List<Object> l0 = convertStringToList0(s); System.out.println(l); System.out.println(l2); @@ -746,7 +746,7 @@ { long timeStart = System.nanoTime(); for (int i = 0; i < MAX; i++) { - List tmp = convertStringToList1(s); + List<Object> tmp = convertStringToList1(s); dummy += tmp.size(); } long time = System.nanoTime() - timeStart; @@ -757,7 +757,7 @@ { long timeStart = System.nanoTime(); for (int i = 0; i < MAX; i++) { - List tmp = convertStringToList2(s); + List<Object> tmp = convertStringToList2(s); dummy += tmp.size(); } long time = System.nanoTime() - timeStart; @@ -769,15 +769,18 @@ } /** - * implantation peut performante + * implantation peut performante. + * + * @param s String to parse + * @return converted list */ - public static List convertStringToList1(String s) { - List result = new ArrayList(); - s = s.trim(); - if (s.startsWith("[") && s.endsWith("]")) { - s = s.substring(1, s.length() - 1); + public static List<Object> convertStringToList1(String s) { + List<Object> result = new ArrayList<Object>(); + String locals = s.trim(); + if (locals.startsWith("[") && locals.endsWith("]")) { + locals = locals.substring(1, locals.length() - 1); } - String[] las = StringUtil.split(s, ","); + String[] las = StringUtil.split(locals, ","); for (String l : las) { l = l.trim(); if (l.startsWith("[")) { @@ -793,11 +796,14 @@ } /** - * implantation utilisé actuellement dans MatrixHelper + * implantation utilisé actuellement dans MatrixHelper. + * + * @param s string to parse + * @return converted string */ - public static List convertStringToList2(String s) { - List result = null; - Stack<List> stack = new Stack<List>(); + public static List<Object> convertStringToList2(String s) { + List<Object> result = null; + Stack<List<Object>> stack = new Stack<List<Object>>(); StringBuffer number = new StringBuffer(20); // initial to 20 char for (int i = 0; i < s.length(); i++) { @@ -806,7 +812,7 @@ // skip space } if (c == '[') { - stack.push(new ArrayList()); + stack.push(new ArrayList<Object>()); } else if (c == ',') { if (number.length() != 0) { // on a une ',' on doit donc avoir un nombre dans number @@ -824,7 +830,7 @@ number.setLength(0); } - List current = stack.pop(); + List<Object> current = stack.pop(); if (stack.empty()) { result = current; } else { @@ -841,20 +847,24 @@ } /** - * implantation fausse pour les nombres 5.0E-7 + * implantation fausse pour les nombres 5.0E-7. + * + * @param s string to parse + * @return converted list + * @throws IOException */ - public static List convertStringToList0(String s) throws IOException { - List result = null; - Stack<List> stack = new Stack<List>(); - StringBuffer number = new StringBuffer(20); // initial to 20 char + public static List<Object> convertStringToList0(String s) throws IOException { + List<Object> result = null; + Stack<List<Object>> stack = new Stack<List<Object>>(); + //StringBuffer number = new StringBuffer(20); // initial to 20 char StreamTokenizer tok = new StreamTokenizer(new StringReader(s)); int v = tok.nextToken(); while (v != StreamTokenizer.TT_EOF) { if (v == '[') { - stack.push(new ArrayList()); + stack.push(new ArrayList<Object>()); } else if (v == ']') { - List current = stack.pop(); + List<Object> current = stack.pop(); if (stack.empty()) { result = current; } else { Modified: trunk/src/test/java/org/nuiton/math/matrix/MatrixStringEncoderTest.java =================================================================== --- trunk/src/test/java/org/nuiton/math/matrix/MatrixStringEncoderTest.java 2009-07-17 13:04:34 UTC (rev 167) +++ trunk/src/test/java/org/nuiton/math/matrix/MatrixStringEncoderTest.java 2009-07-17 16:18:45 UTC (rev 168) @@ -97,7 +97,7 @@ List<Serializable> sem0 = new ArrayList<Serializable>(); sem0.add(new String("test")); sem0.add(new Double(3.453)); - mat1.setSemantics(0, sem0); + mat1.setSemantic(0, sem0); List<Serializable> sem1 = new ArrayList<Serializable>(); sem1.add(new Integer(7)); sem1.add(new Character('e'));