Nuiton-matrix-commits
Threads by month
- ----- 2026 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
March 2009
- 3 participants
- 13 discussions
[Lutinmatrix-commits] r131 - lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui
by chatellier@users.labs.libre-entreprise.org March 31, 2009
by chatellier@users.labs.libre-entreprise.org March 31, 2009
March 31, 2009
Author: chatellier
Date: 2009-03-31 08:14:00 +0000 (Tue, 31 Mar 2009)
New Revision: 131
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
Log:
Fix NPE if user choose cancel option.
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-24 15:33:41 UTC (rev 130)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-31 08:14:00 UTC (rev 131)
@@ -47,7 +47,7 @@
import org.codelutin.util.FileUtil;
/**
- * Ajout d'un menu contextuel sur la matrice dans l'editeur
+ * Ajout d'un menu contextuel sur la matrice dans l'editeur.
*
* Created: 22 mars 2006 12:11:46
*
@@ -61,7 +61,7 @@
/** serialVersionUID. */
private static final long serialVersionUID = 3349189688987885915L;
-
+
private MatrixEditor matrixEditor;
private JFileChooser fileChooser;
@@ -507,9 +507,11 @@
private void sendToFileAllCopyPerformed() {
try {
Writer writer = getFileChooserWriter();
- getMatrix().exportCSV(writer, withSemantics.getState());
- writer.close();
- matrixEditor.repaint();
+ if (writer != null) {
+ getMatrix().exportCSV(writer, withSemantics.getState());
+ writer.close();
+ matrixEditor.repaint();
+ }
} catch (Exception e) {
JOptionPane.showMessageDialog(matrixEditor,
_("lutinmatrix.error.file.write"), _("lutinmatrix.error"),
@@ -521,10 +523,12 @@
private void sendToFileAllPastePerformed() {
try {
Reader reader = getFileChooserReader();
- getMatrix().importCSV(reader, new int[] { 0, 0 });
- reader.close();
- matrixEditor.fireEvent();
- matrixEditor.repaint();
+ if (reader != null) { // cancel
+ getMatrix().importCSV(reader, new int[] { 0, 0 });
+ reader.close();
+ matrixEditor.fireEvent();
+ matrixEditor.repaint();
+ }
} catch (Exception e) {
JOptionPane.showMessageDialog(matrixEditor,
_("lutinmatrix.error.file.read"), _("lutinmatrix.error"),
@@ -536,9 +540,11 @@
private void sendToFileSelectionCopyPerformed() {
try {
Writer writer = getFileChooserWriter();
- getSelectedMatrix().exportCSV(writer, withSemantics.getState());
- writer.close();
- matrixEditor.repaint();
+ if (writer != null) {
+ getSelectedMatrix().exportCSV(writer, withSemantics.getState());
+ writer.close();
+ matrixEditor.repaint();
+ }
} catch (Exception e) {
JOptionPane.showMessageDialog(matrixEditor,
_("lutinmatrix.error.file.write"), _("lutinmatrix.error"),
@@ -550,11 +556,13 @@
private void sendToFileCurrentPastePerformed() {
try {
Reader reader = getFileChooserReader();
- getMatrix().importCSV(reader,
- getCoordinatesFirstCellSelectedMatrix());
- reader.close();
- matrixEditor.fireEvent();
- matrixEditor.repaint();
+ if (reader != null) { // cancel
+ getMatrix().importCSV(reader,
+ getCoordinatesFirstCellSelectedMatrix());
+ reader.close();
+ matrixEditor.fireEvent();
+ matrixEditor.repaint();
+ }
} catch (Exception e) {
JOptionPane.showMessageDialog(matrixEditor,
_("lutinmatrix.error.file.read"), _("lutinmatrix.error"),
1
0
[Lutinmatrix-commits] r130 - in lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix: . gui
by sletellier@users.labs.libre-entreprise.org March 24, 2009
by sletellier@users.labs.libre-entreprise.org March 24, 2009
March 24, 2009
Author: sletellier
Date: 2009-03-24 15:33:41 +0000 (Tue, 24 Mar 2009)
New Revision: 130
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java
Log:
Debug
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-23 14:07:41 UTC (rev 129)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-24 15:33:41 UTC (rev 130)
@@ -147,7 +147,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.codelutin.math.matrix.MatrixND#copy()
*/
public MatrixND copy() {
@@ -157,11 +157,11 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#clone()
*/
@Override
- protected Object clone() throws CloneNotSupportedException {
+ public MatrixND clone() {
return copy();
}
@@ -201,25 +201,25 @@
public String[] getDimensionNames() {
return dimNames;
}
-
+
public void setDimensionNames(String[] names) {
for (int i = 0; names != null && i < names.length; i++) {
setDimensionName(i, names[i]);
}
}
-
+
/**
* {@inheritDoc}
- *
+ *
* @deprecated Use #getDimensionNames()
*/
public String[] getDimensionName() {
return getDimensionNames();
}
-
+
/**
* {@inheritDoc}
- *
+ *
* @deprecated Use #setDimensionName(String[])
*/
public void setDimensionName(String[] names) {
@@ -396,7 +396,7 @@
/**
* Verifie si les matrices sont egales en ne regardant que les valeurs et
* pas les semantiques
- *
+ *
* @param mat
* @return
*/
@@ -499,7 +499,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.codelutin.math.matrix.MatrixND#sumAll()
*/
public double sumAll() {
@@ -591,7 +591,7 @@
/**
* Modifie la matrice actuel en metant les valeurs de mat passé en parametre
- *
+ *
* @param origin le point d'origine a partir duquel on colle la matrice
* @param mat une matrice avec le meme nombre de dimension, si la matrice
* que l'on colle est trop grande, les valeurs qui depasse ne
@@ -651,7 +651,7 @@
/**
* Add to desambiguas some call with xpath engine, but do the same thing
* {@link #getSubMatrix(int, Object[])}
- *
+ *
* @param dim
* @param elem
* @return
@@ -798,7 +798,7 @@
/**
* Create new matrice from the current matrix.
- *
+ *
* @param dimName dimension name for new matrix
* @param sem semantic for new matrix
* @param correspondance array to do the link between current matrix and
@@ -876,7 +876,7 @@
});
return this;
}
-
+
public MatrixND adds(final double d) {
map(new MapFunction() {
public double apply(double val) {
@@ -885,7 +885,7 @@
});
return this;
}
-
+
public MatrixND minuss(final double d) {
map(new MapFunction() {
public double apply(double val) {
@@ -897,7 +897,7 @@
/**
* Determine si la matrice supporte l'import et l'export CSV
- *
+ *
* @return support du CSV
*/
public boolean isSupportedCSV() {
@@ -906,7 +906,7 @@
/**
* Import depuis un reader au format CSV des données dans la matrice
- *
+ *
* @param reader le reader à importer
* @param origin le point à partir duquel il faut faire l'importation
* int[]{x,y}
@@ -979,13 +979,13 @@
// StreamTokenizer tokenizer;
// List<Double> row = new ArrayList<Double>();
// boolean stop = false;
- //
+ //
// tokenizer = new StreamTokenizer(reader);
// tokenizer.eolIsSignificant(true);
- //
+ //
// while(!stop) {
// tokenizer.nextToken();
- //
+ //
// switch (tokenizer.ttype) {
// case StreamTokenizer.TT_EOF:
// stop = true; // no break we do next case too
@@ -1017,7 +1017,7 @@
/**
* Export dans un writer au format CSV de la matrice
- *
+ *
* @param writer le writer ou copier la matrice
* @param withSemantics export ou pas des semantiques de la matrice dans le
* writer
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-23 14:07:41 UTC (rev 129)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-24 15:33:41 UTC (rev 130)
@@ -38,25 +38,25 @@
/**
* Retourne la factory qui a permit de creer la matrice.
- *
+ *
* @return la {@link MatrixFactory}
- *
+ *
* @see MatrixFactory
*/
public MatrixFactory getFactory();
/**
* Donne toutes les semantiques de la matrice.
- *
+ *
* Si la matrice n'a pas de semantique retourne null.
- *
+ *
* @return la liste des semantics
*/
public List[] getSemantics();
/**
* 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
@@ -70,55 +70,55 @@
/**
* Permet de donner un nom à la matrice.
- *
+ *
* @param name name to set
*/
public void setName(String name);
/**
* Retourne le nom de la matrice
- *
+ *
* @return le nom de la matrice ou la chaine vide si pas de nom.
*/
public String getName();
/**
* Permet de mettre des noms aux différentes dimension.
- *
+ *
* @deprecated (since 1.0.3) Use #setDimensionNames(String[])
*/
public void setDimensionName(String[] names);
/**
* Permet de mettre des noms aux différentes dimension.
- *
+ *
* @param names names to set
- *
+ *
* @since 1.0.3
*/
public void setDimensionNames(String[] names);
-
+
/**
* Permet de recuperer les noms des dimension.
- *
+ *
* @return tableau des noms de dimension.
- *
+ *
* @deprecated (since 1.0.3) Use #getDimensionNames()
*/
public String[] getDimensionName();
-
+
/**
* Permet de recuperer les noms des dimension.
- *
+ *
* @return tableau des noms de dimension.
- *
+ *
* @since 1.0.3
*/
public String[] getDimensionNames();
-
+
/**
* Permet de mettre un nom à une dimension.
- *
+ *
* @param dim la dimension dont on veut changer le nom
* @param name le nom à donner à la dimension
*/
@@ -126,7 +126,7 @@
/**
* Retourne le nom de la dimension demandé.
- *
+ *
* @param dim la dimension dont on veut le nom
* @return le nom de la dimension ou la chaine vide si la dimension n'a pas
* de nom @ si la dimension demandé n'est pas valide
@@ -137,7 +137,7 @@
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
* plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
* est retourné.
- *
+ *
* @return la valeur la plus nombreuse dans le tableau
*/
public double getMaxOccurence();
@@ -191,14 +191,14 @@
/**
* Renvoie un element de la matrice demandée en fonction des dimensions
* passé en paramètre.<br>
- *
+ *
* Exemple: Si on a un matrice 3D.<br>
* getValue(1,1,1) retourne un element de la matrice.<br>
- *
+ *
* @param dimensions les différentes dimension à extraire. Le tableau doit
* contenir toutes les dimensions de la matrice, et seulement des
* nombres positif
- *
+ *
* @return un entier double.
*/
public double getValue(int[] dimensions);
@@ -246,12 +246,12 @@
/**
* Modifie un element de la matrice en fonction des dimensions passé en
* paramètre.<br>
- *
+ *
* Exemple: Si on a un matrice 3D.<br>
* set([1,1,1], m) modifie un element de la matrice.<br>
- *
+ *
* @param dimensions les différentes dimension à extraire.
- *
+ *
* @param d l'entier double qui doit remplacer l'entier double spécifié par
* l'argument dimensions
*/
@@ -281,6 +281,11 @@
*/
public MatrixND copy();
+ /**
+ * Créer une nouvelle instance clonée de celle-ci
+ */
+ public MatrixND clone();
+
// public String toString();
// /**
@@ -307,17 +312,17 @@
* <p>
* par exemple pour la matrice suivante si on somme sur la dimension 1 cela
* donnera
- *
+ *
* <pre>
* 1 2 3
* 2 3 4
* 3 4 5
* </pre>
- *
+ *
* <pre>
* 6 9 12
* </pre>
- *
+ *
* @param dim la dimension sur lequel il faut faire la somme
*/
public MatrixND sumOverDim(int dim);
@@ -327,24 +332,24 @@
* permet juste de regrouper dans une dimension un certain nombre de valeur.
* <p>
* pour la matrice suivante :
- *
+ *
* <pre>
* 1 2 3 4
* 2 3 4 5
* 3 4 5 6
* 4 5 6 7
* </pre>
- *
+ *
* la somme sur la dimension 1 avec un pas de 2 donnera :
- *
+ *
* <pre>
* 3 5 7 9
* 7 9 11 13
* </pre>
- *
+ *
* c'est à dire que la ligne 0 et la ligne 1 sont sommées. ainsi que la
* ligne 2 avec la ligne 3.
- *
+ *
* @param dim la dimension sur lequel il faut faire les sommes
* @param step le pas qu'il faut utiliser pour regrouper les elements. Si le
* pas est inférieur à 0, le pas se comporte comme si on avait
@@ -367,23 +372,23 @@
/**
* Permet de supprimer des éléments de la matrice. par exemple pour la
* matrice
- *
+ *
* <pre>
* 1 2 3 4
* 2 3 4 5
* 3 4 5 6
* 4 5 6 7
* </pre>
- *
+ *
* un cut(1, [0,2]) donnera
- *
+ *
* <pre>
* 2 4
* 3 5
* 4 6
* 5 7
* </pre>
- *
+ *
* @param dim la dimension dans lequel il faut supprimer des éléments
* @param toCut les éléments à supprimer
* @return une nouvelle matrice, la matrice actuelle n'est pas modifiée
@@ -394,7 +399,7 @@
* Copie une matrice dans la matrice actuelle. La matrice à copier à le même
* nombre de dimension. Si la matrice à copier est trop grande seul les
* éléments pouvant être copier le seront.
- *
+ *
* @param mat la matrice à copier
* @return return la matrice courante.
*/
@@ -404,7 +409,7 @@
* Copie une matrice dans la matrice actuelle. La matrice à copier à le même
* nombre de dimension. Si la matrice à copier est trop grande seul les
* éléments pouvant être copier le seront.
- *
+ *
* @param origin le point à partir duquel il faut faire la copie
* @param mat la matrice à copier
* @return return la matrice courante.
@@ -458,7 +463,7 @@
* Permet de prendre une sous matrice dans la matrice courante. La sous
* matrice a le même nombre de dimensions mais sur une des dimensions on ne
* prend que certain élément.
- *
+ *
* @param dim la dimension dans lequel on veut une sous matrice si dim est
* négatif alors la dimension est prise à partir de la fin par
* exemple si l'on veut la derniere dimension il faut passer -1
@@ -475,7 +480,7 @@
* Permet de prendre une sous matrice dans la matrice courante. La sous
* matrice a le même nombre de dimensions mais sur une des dimensions on ne
* prend que certain élément.
- *
+ *
* @param dim la dimension dans lequel on veut une sous matrice
* @param start la position dans dim d'ou il faut partir pour prendre la
* sous matrice. 0 <= start < dim.size si start est négatif alors
@@ -491,7 +496,7 @@
* Permet de prendre une sous matrice dans la matrice courante. La sous
* matrice a le même nombre de dimensions mais sur une des dimensions on ne
* prend que certain élément.
- *
+ *
* @param dim la dimension dans lequel on veut une sous matrice
* @param elem les éléments dans la dimension à conserver
*/
@@ -501,7 +506,7 @@
* Permet de prendre une sous matrice dans la matrice courante. La sous
* matrice a le même nombre de dimensions mais sur une des dimensions on ne
* prend que certain élément.
- *
+ *
* @param dim la dimension dans lequel on veut une sous matrice
* @param elem les éléments dans la dimension à conserver
*/
@@ -528,7 +533,7 @@
* Reduit la matrice de sorte que toutes les dimensions qui n'ont qu'un
* élement soit supprimée. Au pire cette méthode retourne une matrice à une
* seule dimension à un seul élément.
- *
+ *
* @return une nouvelle matrice plus petite que la matrice actuelle ou egal
* s'il n'y a aucune dimension à supprimer
*/
@@ -538,7 +543,7 @@
* Reduit la matrice de sorte que toutes les dimensions qui n'ont qu'un
* élement soit supprimée. Au pire cette méthode retourne une matrice à une
* seule dimension à un seul élément.
- *
+ *
* @param minNbDim le nombre minimum de dimension que l'on souhaite pour la
* matrice résultat
* @return une nouvelle matrice plus petite que la matrice actuelle ou egal
@@ -550,7 +555,7 @@
* Reduit le matrice seulement sur les dimensions passées en argument. Si
* une des dimensions passées en arguement n'a pas un seul élément, cette
* dimension n'est pas prise en compte.
- *
+ *
* @param dims les dimensions sur lequel il faut faire la reduction
* @return une nouvelle matrice
*/
@@ -575,12 +580,12 @@
* Multiplication d'une matrice par un scalaire
*/
public MatrixND divs(final double d);
-
+
/**
* Addition d'un scalaire à une matrice
*/
public MatrixND adds(final double d);
-
+
/**
* Soustractiond'un scalaire à une matrice
*/
@@ -588,28 +593,28 @@
/**
* Donne la matrice sous forme de List de list ... de double
- *
+ *
* @return
*/
public List 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);
/**
* Determine si la matrice supporte l'import et l'export CSV
- *
+ *
* @return support du CSV
*/
public boolean isSupportedCSV();
/**
* Import depuis un reader au format CSV des données dans la matrice
- *
+ *
* @param reader le reader à importer
* @param origin le point à partir duquel il faut faire l'importation
*/
@@ -617,7 +622,7 @@
/**
* Export dans un writer au format CSV de la matrice
- *
+ *
* @param writer le writer ou copier la matrice
* @param withSemantics export ou pas des semantiques de la matrice dans le
* writer
@@ -628,7 +633,7 @@
/**
* Verifie si les matrices sont egales en ne regardant que les valeurs et
* pas les semantiques
- *
+ *
* @param mat
* @return
*/
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx 2009-03-23 14:07:41 UTC (rev 129)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx 2009-03-24 15:33:41 UTC (rev 130)
@@ -163,10 +163,10 @@
}
]]>
</script>
- <JButton id='buttonEdit' text='lutinmatrix.create.matrix.button' enabled='{isDimensionEdit()}'
- onActionPerformed='btnAction()' constraints='BorderLayout.SOUTH'/>
<JScrollPane id='editArea' constraints='BorderLayout.CENTER'>
<JTable id='table' autoResizeMode='{JTable.AUTO_RESIZE_OFF}'
cellSelectionEnabled='{true}' selectionMode='{ListSelectionModel.SINGLE_INTERVAL_SELECTION}'/>
</JScrollPane>
+ <JButton id='buttonEdit' text='lutinmatrix.create.matrix.button' visible='{isDimensionEdit()}'
+ onActionPerformed='btnAction()' constraints='BorderLayout.SOUTH'/>
</MatrixEditor>
\ No newline at end of file
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java 2009-03-23 14:07:41 UTC (rev 129)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java 2009-03-24 15:33:41 UTC (rev 130)
@@ -33,7 +33,7 @@
// Inisialize matrixND
public abstract void setMatrix(MatrixND matrix);
-
+
/**
* @return Returns the linearModel.
*/
@@ -70,7 +70,6 @@
public void setVisible(Boolean visible){
this.visible = visible;
getTable().setVisible(visible);
- getButtonEdit().setVisible(visible);
super.setVisible(visible);
}
1
0
[Lutinmatrix-commits] r129 - in lutinmatrix/trunk: . src/main/java/org/codelutin/math/matrix/gui
by sletellier@users.labs.libre-entreprise.org March 23, 2009
by sletellier@users.labs.libre-entreprise.org March 23, 2009
March 23, 2009
Author: sletellier
Date: 2009-03-23 14:07:41 +0000 (Mon, 23 Mar 2009)
New Revision: 129
Added:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java
Modified:
lutinmatrix/trunk/pom.xml
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
Log:
JAXX implamentation of MatrixPanelEditor
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-20 13:46:40 UTC (rev 128)
+++ lutinmatrix/trunk/pom.xml 2009-03-23 14:07:41 UTC (rev 129)
@@ -46,6 +46,14 @@
<scope>compile</scope>
</dependency>
+ <!--Jaxx-->
+ <dependency>
+ <groupId>org.codelutin.jaxx</groupId>
+ <artifactId>jaxx-runtime-swing</artifactId>
+ <version>${jaxx.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
@@ -66,7 +74,8 @@
<!-- id du projet du labs -->
<labs.id>63</labs.id>
<labs.project>${project.artifactId}</labs.project>
-
+
+ <jaxx.version>1.3-SNAPSHOT</jaxx.version>
<i18n.version>0.9</i18n.version>
<lutinutil.version>1.0.3</lutinutil.version>
</properties>
@@ -74,6 +83,27 @@
<build>
<plugins>
+ <plugin>
+ <groupId>org.codelutin.jaxx</groupId>
+ <artifactId>maven-jaxx-plugin</artifactId>
+ <version>${jaxx.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <extraImports>
+ <value>jaxx.runtime.SwingUtil</value>
+ <value>static jaxx.runtime.Util.getStringValue</value>
+ </extraImports>
+ <addSourcesToClassPath>true</addSourcesToClassPath>
+ <addProjectClassPath>true</addProjectClassPath>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<!-- plugin i18n -->
<plugin>
<groupId>org.codelutin</groupId>
Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx (rev 0)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/JAXXMatrixEditor.jaxx 2009-03-23 14:07:41 UTC (rev 129)
@@ -0,0 +1,172 @@
+<!--
+/* *##%
+ * Copyright (C) 2005
+ * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin
+ *
+ * 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.
+ *##%*/
+
+/* *
+ * IsisFish.java
+ *
+ * Created: 1 aout 2005 18:37:25 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision: 1312 $
+ *
+ * Last update: $Date: 2008-08-28 10:21:07 +0200 (jeu, 28 aoû 2008) $
+ * by : $Author: sletellier $
+ */
+ -->
+<MatrixEditor id='jaxxMatrixManel' layout='{new BorderLayout()}'>
+
+ <MatrixTableModel id='tableModel' javaBean='null'/>
+
+ <!-- if true, use linear representation of matrix -->
+ <Boolean id='linearModel' javaBean='false'/>
+
+ <!-- if false don't show default value in matrix (ex: 0) -->
+ <Boolean id='linearModelShowDefault' javaBean='false'/>
+
+ <!-- Boolean to autorize matrice dimension changes. -->
+ <Boolean id='dimensionEdit' javaBean='false'/>
+
+ <script><![CDATA[
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.util.Iterator;
+
+import org.codelutin.i18n.I18n;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.math.matrix.MatrixND;
+import org.codelutin.util.ListenerSet;
+
+private final static int DEFAULT_WIDTH = 150;
+
+private final static int DEFAULT_HEIGHT = 150;
+
+protected ListenerSet listeners = new ListenerSet();
+protected MatrixPopupMenu popupMenu = null;
+protected MatrixND matrix = null;
+initObject();
+public JAXXMatrixEditor(MatrixND m, boolean dimensionEdit) {
+ this(dimensionEdit, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+}
+
+public JAXXMatrixEditor(boolean dimensionEdit, int width, int height) {
+ this.dimensionEdit = dimensionEdit;
+ setPreferredSize(new Dimension(width, height));
+}
+
+public JAXXMatrixEditor(boolean dimensionEdit) {
+ this(dimensionEdit, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+}
+
+public void setMatrix(MatrixND m){
+ this.matrix = m;
+ initObject();
+}
+
+public MatrixND getMatrix() {
+ return matrix;
+}
+
+protected MatrixFactory getFactory() {
+ return MatrixFactory.getInstance();
+}
+
+public void addMatrixListener(MatrixPanelListener l) {
+ listeners.add(l);
+}
+
+public void removeMatrixPanelListener(MatrixPanelListener l) {
+ listeners.remove(l);
+}
+
+protected void initObject() {
+ if (getMatrix() == null) {
+ editArea.setViewportView(null);
+ }
+ else {
+ popupMenu = new MatrixPopupMenu(this);
+ table = new JTable() {
+ public void processMouseEvent(MouseEvent event) {
+ if (event.isPopupTrigger()) {
+ popupMenu.show(event.getComponent(), event.getX(), event.getY());
+ }
+ super.processMouseEvent(event);
+ }
+ };
+
+ table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK),"copy");
+ table.getActionMap().put("copy",popupMenu.getSendToClipBoardSelectionCopyAction());
+ table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK),"paste");
+ table.getActionMap().put("paste",popupMenu.getSendToClipBoardCurrentPasteAction());
+ if (isLinearModel()) {
+ setTableModel(new MatrixTableModelLinear(getMatrix(), isLinearModelShowDefault()));
+ }
+ else {
+ setTableModel(new MatrixTableModelND(getMatrix()));
+ }
+
+ getTableModel().addTableModelListener(new TableModelListener() {
+
+ @Override
+ public void tableChanged(TableModelEvent e) {
+ fireEvent();
+ }
+ });
+
+ table.setModel(getTableModel());
+ table.setDefaultRenderer(String.class, tableModel.getMatrixCellRenderer());
+ editArea.setViewportView(table);
+ }
+ repaint();
+}
+
+protected void btnAction(){
+ String dim;
+ dim = JOptionPane.showInputDialog(null, I18n._("lutinmatrix.create.matrix.message"), I18n._("lutinmatrix.create.matrix.title"), JOptionPane.DEFAULT_OPTION);
+
+ if (dim != null) {
+ String[] sdim = dim.split(";");
+ int[] idim = new int[sdim.length];
+ for (int i = 0; i < idim.length; i++) {
+ idim[i] = Integer.parseInt(sdim[i]);
+ }
+ setMatrix(getFactory().create(idim));
+ }
+}
+
+protected void fireEvent() {
+ MatrixPanelEvent e = new MatrixPanelEvent(this);
+ for (Iterator i = listeners.iterator(); i.hasNext();) {
+ MatrixPanelListener l = (MatrixPanelListener) i.next();
+ l.matrixChanged(e);
+ }
+}
+ ]]>
+ </script>
+ <JButton id='buttonEdit' text='lutinmatrix.create.matrix.button' enabled='{isDimensionEdit()}'
+ onActionPerformed='btnAction()' constraints='BorderLayout.SOUTH'/>
+ <JScrollPane id='editArea' constraints='BorderLayout.CENTER'>
+ <JTable id='table' autoResizeMode='{JTable.AUTO_RESIZE_OFF}'
+ cellSelectionEnabled='{true}' selectionMode='{ListSelectionModel.SINGLE_INTERVAL_SELECTION}'/>
+ </JScrollPane>
+</MatrixEditor>
\ No newline at end of file
Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java (rev 0)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixEditor.java 2009-03-23 14:07:41 UTC (rev 129)
@@ -0,0 +1,77 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.codelutin.math.matrix.gui;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import org.codelutin.math.matrix.MatrixND;
+import javax.swing.JTable;
+
+/**
+ *
+ * @author letellier
+ */
+public abstract class MatrixEditor extends JPanel {
+
+ protected boolean enabled = false;
+ protected boolean visible = false;
+
+ // Return JTable componant
+ public abstract JTable getTable();
+
+ // Return edit button componant
+ public abstract JButton getButtonEdit();
+
+ // Fire the matrix
+ protected abstract void fireEvent();
+
+ // Return matrixND
+ public abstract MatrixND getMatrix();
+
+ // Inisialize matrixND
+ public abstract void setMatrix(MatrixND matrix);
+
+ /**
+ * @return Returns the linearModel.
+ */
+ public abstract Boolean isLinearModel();
+
+ /**
+ * @param linearModel The linearModel to set.
+ */
+ public abstract void setLinearModel(Boolean b);
+
+ /**
+ * @return Returns the linearModelShowDefault.
+ */
+ public abstract Boolean isLinearModelShowDefault();
+
+ /**
+ * @param linearModelShowDefault The linearModelShowDefault to set.
+ */
+ public abstract void setLinearModelShowDefault(Boolean b);
+
+ /**
+ * Enabled component
+ */
+ public void setEnabled(Boolean enabled){
+ this.enabled = enabled;
+ getTable().setEnabled(enabled);
+ getButtonEdit().setEnabled(enabled);
+ super.setEnabled(enabled);
+ }
+
+ /**
+ * Enabled component
+ */
+ public void setVisible(Boolean visible){
+ this.visible = visible;
+ getTable().setVisible(visible);
+ getButtonEdit().setVisible(visible);
+ super.setVisible(visible);
+ }
+
+}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-20 13:46:40 UTC (rev 128)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-23 14:07:41 UTC (rev 129)
@@ -64,7 +64,7 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public class MatrixPanelEditor extends JPanel implements TableModelListener { // MatrixPanelEditor
+public class MatrixPanelEditor extends MatrixEditor implements TableModelListener { // MatrixPanelEditor
/** serialVersionUID */
private static final long serialVersionUID = 2097859265435050946L;
@@ -161,7 +161,7 @@
protected JButton bEdit = null;
- protected JButton getButtonEdit() {
+ public JButton getButtonEdit() {
if (bEdit == null) {
bEdit = new JButton(I18n._("lutinmatrix.create.matrix.button"));
bEdit.addActionListener(new ActionListener() {
@@ -191,14 +191,14 @@
/**
* @return Returns the linearModel.
*/
- public boolean isLinearModel() {
+ public Boolean isLinearModel() {
return this.linearModel;
}
/**
* @param linearModel The linearModel to set.
*/
- public void setLinearModel(boolean linearModel) {
+ public void setLinearModel(Boolean linearModel) {
this.linearModel = linearModel;
initObject(m);
}
@@ -206,14 +206,14 @@
/**
* @return Returns the linearModelShowDefault.
*/
- public boolean isLinearModelShowDefault() {
+ public Boolean isLinearModelShowDefault() {
return this.linearModelShowDefault;
}
/**
* @param linearModelShowDefault The linearModelShowDefault to set.
*/
- public void setLinearModelShowDefault(boolean linearModelShowDefault) {
+ public void setLinearModelShowDefault(Boolean linearModelShowDefault) {
this.linearModelShowDefault = linearModelShowDefault;
initObject(m);
}
@@ -345,6 +345,10 @@
if (tableModel != null) {
tableModel.setEnabled(enabled);
}
+ if (table != null){
+ table.setEnabled(enabled);
+ }
+ super.setEnabled(enabled);
// if (text != null) {
// text.setEditable(enabled);
// }
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-20 13:46:40 UTC (rev 128)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-23 14:07:41 UTC (rev 129)
@@ -40,12 +40,12 @@
/**
* @param source
*/
- public MatrixPanelEvent(MatrixPanelEditor source) {
+ public MatrixPanelEvent(MatrixEditor source) {
super(source);
}
public MatrixND getMatrix() {
- MatrixND result = ((MatrixPanelEditor) getSource()).getMatrix();
+ MatrixND result = ((MatrixEditor) getSource()).getMatrix();
return result;
}
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-20 13:46:40 UTC (rev 128)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-23 14:07:41 UTC (rev 129)
@@ -62,7 +62,7 @@
/** serialVersionUID. */
private static final long serialVersionUID = 3349189688987885915L;
- private MatrixPanelEditor matrixEditor;
+ private MatrixEditor matrixEditor;
private JFileChooser fileChooser;
private JMenu sendToClipBoard;
@@ -80,7 +80,7 @@
private Action sendToFileSelectionCopyAction;
private Action sendToFileCurrentPasteAction;
- public MatrixPopupMenu(MatrixPanelEditor matrixEditor) {
+ public MatrixPopupMenu(MatrixEditor matrixEditor) {
super();
this.matrixEditor = matrixEditor;
1
0
[Lutinmatrix-commits] r128 - lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui
by sletellier@users.labs.libre-entreprise.org March 20, 2009
by sletellier@users.labs.libre-entreprise.org March 20, 2009
March 20, 2009
Author: sletellier
Date: 2009-03-20 13:46:40 +0000 (Fri, 20 Mar 2009)
New Revision: 128
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
Log:
Bug visible matrix fixed
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-16 17:59:20 UTC (rev 127)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-20 13:46:40 UTC (rev 128)
@@ -51,11 +51,11 @@
/**
* JPanel contenant une JTable pour afficher une Matrice a une ou deux
* dimension.
- *
+ *
* TODO: Une methode permettant de retourne la sous matrice de la selection que
* la matrice soit reprensentée en lineaire ou non. (avoir un mapping cellule de
* table vers element de matrice
- *
+ *
* Created: 29 oct. 2004
*
* @author Benjamin Poussin <poussin(a)codelutin.com>
@@ -94,12 +94,15 @@
/** Boolean to autorize table editing. */
protected boolean enabled = true;
+ /** Boolean to show matrix. */
+ protected boolean visible = true;
+
/** Boolean to autorize matrice dimension changes. */
protected boolean dimensionEdit;
/**
* Construct a new JPanel to edit matrix.
- *
+ *
* @param m the matrix to edit.
* @param dimensionEdit to enabled matrix dimension changes.
*/
@@ -110,7 +113,7 @@
/**
* Construct a new JPanel to edit matrix.
- *
+ *
* @param dimensionEdit to enabled matrix dimension changes.
* @param width width prefered for the component
* @param height height prefered for the component
@@ -123,7 +126,7 @@
/**
* Construct a new JPanel to edit matrix.
- *
+ *
* @param dimensionEdit to enabled matrix dimension changes.
*/
public MatrixPanelEditor(boolean dimensionEdit) {
@@ -217,7 +220,7 @@
/**
* Get the value of dimensionEdit.
- *
+ *
* @return value of dimensionEdit.
*/
public boolean isDimensionEdit() {
@@ -226,7 +229,7 @@
/**
* Set the value of dimensionEdit.
- *
+ *
* @param v Value to assign to dimensionEdit.
*/
public void setDimensionEdit(boolean v) {
@@ -273,6 +276,7 @@
// editArea.setColumnHeaderView(null);
// }
setEnabled(enabled);
+ setVisible(visible);
repaint();
}
@@ -360,6 +364,20 @@
return enabled;
}
+ /**
+ * Set the matrix visible. By default, the matrix is visible.
+ */
+ public void setVisible(boolean visible) {
+ if (table != null){
+ table.setVisible(visible);
+ }
+ super.setVisible(visible);
+ this.visible = visible;
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
/*
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
*/
1
0
[Lutinmatrix-commits] r127 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by jcouteau@users.labs.libre-entreprise.org March 16, 2009
by jcouteau@users.labs.libre-entreprise.org March 16, 2009
March 16, 2009
Author: jcouteau
Date: 2009-03-16 17:59:20 +0000 (Mon, 16 Mar 2009)
New Revision: 127
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
Log:
Add addition and subtraction with a scalar to MatrixND
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-13 17:27:34 UTC (rev 126)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-16 17:59:20 UTC (rev 127)
@@ -876,6 +876,24 @@
});
return this;
}
+
+ public MatrixND adds(final double d) {
+ map(new MapFunction() {
+ public double apply(double val) {
+ return val + d;
+ }
+ });
+ return this;
+ }
+
+ public MatrixND minuss(final double d) {
+ map(new MapFunction() {
+ public double apply(double val) {
+ return val - d;
+ }
+ });
+ return this;
+ }
/**
* Determine si la matrice supporte l'import et l'export CSV
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-13 17:27:34 UTC (rev 126)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-16 17:59:20 UTC (rev 127)
@@ -575,6 +575,16 @@
* Multiplication d'une matrice par un scalaire
*/
public MatrixND divs(final double d);
+
+ /**
+ * Addition d'un scalaire à une matrice
+ */
+ public MatrixND adds(final double d);
+
+ /**
+ * Soustractiond'un scalaire à une matrice
+ */
+ public MatrixND minuss(final double d);
/**
* Donne la matrice sous forme de List de list ... de double
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-13 17:27:34 UTC (rev 126)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-16 17:59:20 UTC (rev 127)
@@ -395,8 +395,56 @@
Assert.assertEquals(6.5, mat2.getValue(1, 2, 0), 0);
Assert.assertEquals(6.5, mat2.getValue(2, 2, 2), 0);
}
+
+ @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" });
+ MatrixND mat1 = getFactory().create("Ma mat",
+ new List[] { s1, s2, s3 },
+ new String[] { "dim abc", "dim efg", "dim klm" });
+ MatrixND mat2 = getFactory().create("Ma mat",
+ new List[] { s1, s2, s3 },
+ new String[] { "dim abc", "dim efg", "dim klm" });
+
+ MatrixHelper.fill(mat1, 3);
+ MatrixHelper.fill(mat2, 26);
+
+ mat1.adds(3);
+ mat2.adds(4);
+
+ Assert.assertEquals(6, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(30, mat2.getValue(1, 2, 0), 0);
+ Assert.assertEquals(30, mat2.getValue(2, 2, 2), 0);
+ }
+
@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" });
+
+ MatrixND mat1 = getFactory().create("Ma mat",
+ new List[] { s1, s2, s3 },
+ new String[] { "dim abc", "dim efg", "dim klm" });
+ MatrixND mat2 = getFactory().create("Ma mat",
+ new List[] { s1, s2, s3 },
+ new String[] { "dim abc", "dim efg", "dim klm" });
+
+ MatrixHelper.fill(mat1, 3);
+ MatrixHelper.fill(mat2, 26);
+
+ mat1.minuss(3);
+ mat2.minuss(4);
+
+ Assert.assertEquals(0, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(22, mat2.getValue(1, 2, 0), 0);
+ Assert.assertEquals(22, mat2.getValue(2, 2, 2), 0);
+ }
+
+ @Test
public void testPaste() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 6, 7, 8 });
1
0
[Lutinmatrix-commits] r126 - lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org March 13, 2009
by chatellier@users.labs.libre-entreprise.org March 13, 2009
March 13, 2009
Author: chatellier
Date: 2009-03-13 17:27:34 +0000 (Fri, 13 Mar 2009)
New Revision: 126
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
Log:
Fix javadoc for sumOverDim
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-04 10:29:44 UTC (rev 125)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-13 17:27:34 UTC (rev 126)
@@ -326,7 +326,7 @@
* Somme la matrice mais la matrice reste de la même dimension. la somme
* permet juste de regrouper dans une dimension un certain nombre de valeur.
* <p>
- * pour la matrice suivant
+ * pour la matrice suivante :
*
* <pre>
* 1 2 3 4
@@ -335,15 +335,15 @@
* 4 5 6 7
* </pre>
*
- * la somme sur la dimension 1 avec un pas de 2 donnera
+ * la somme sur la dimension 1 avec un pas de 2 donnera :
*
* <pre>
- * 4 6 8 10
- * 6 8 10 12
+ * 3 5 7 9
+ * 7 9 11 13
* </pre>
*
- * c'est à dire que la ligne 0 et la ligne 2 sont sommées. ainsi que la
- * ligne 1 avec la ligne 3.
+ * c'est à dire que la ligne 0 et la ligne 1 sont sommées. ainsi que la
+ * ligne 2 avec la ligne 3.
*
* @param dim la dimension sur lequel il faut faire les sommes
* @param step le pas qu'il faut utiliser pour regrouper les elements. Si le
1
0
[Lutinmatrix-commits] r125 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org March 4, 2009
by chatellier@users.labs.libre-entreprise.org March 4, 2009
March 4, 2009
Author: chatellier
Date: 2009-03-04 10:29:44 +0000 (Wed, 04 Mar 2009)
New Revision: 125
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
Log:
Specials chars on columns names \"
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java 2009-03-04 09:44:40 UTC (rev 124)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java 2009-03-04 10:29:44 UTC (rev 125)
@@ -25,6 +25,7 @@
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.util.StringUtil;
@@ -166,7 +167,7 @@
String result = "[";
String sep = "";
for (int i = 0; i < dimNamesArray.length; i++) {
- result += sep + '"' + dimNamesArray[i] + '"';
+ result += sep + '"' + StringEscapeUtils.escapeJava(dimNamesArray[i]) + '"';
sep = ", ";
}
result += "]";
@@ -188,7 +189,9 @@
for (int i = 0; i < result.length; i++) {
result[i] = result[i].trim();
if (result[i].startsWith("\"") && result[i].endsWith("\"")) {
- result[i] = result[i].substring(1, result[i].length() - 1); // remove " and "
+ String resultString = result[i].substring(1, result[i].length() - 1);// remove " and "
+ resultString = StringEscapeUtils.unescapeJava(resultString);
+ result[i] = resultString;
}
}
return result;
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java 2009-03-04 09:44:40 UTC (rev 124)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java 2009-03-04 10:29:44 UTC (rev 125)
@@ -142,5 +142,39 @@
Assert.assertEquals(2.345, matrix.getValue(1, 1), 0);
Assert.assertEquals(-8.321, matrix.getValue(1, 4), 0);
}
+
+ @Test
+ public void testMatrixNamesSpecialChars() {
+
+ MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
+ mat1.setValue(0, 0, 0, -1.0E-7);
+ mat1.setValue(1, 1, 0, 2);
+ mat1.setValue(2, 1, 0, 5.0E-7);
+ mat1.setDimensionNames(new String[]{"col \"1\", \"2\"","col \"3\", \"4\""});
+ String rep = stringEncoder.getMatrixAsString(mat1);
+
+ System.out.println(rep);
+
+ Assert.assertTrue("Null() semantics missing", rep.indexOf("null()") > 0);
+ Assert.assertTrue("Dimentation missing", rep.indexOf("3, 2, 1") > 0);
+ Assert.assertTrue("Data missing", rep.indexOf("[2.0]") > 0);
+ Assert.assertTrue("Wrong string encoding", rep.indexOf("\"col \\\"1\\\", \\\"2\\\"\", \"col \\\"3\\\", \\\"4\\\"\", \"\"") > 0);
+ }
+
+ @Test
+ public void testMatrixFromNamesSpecialChars() {
+ String representation = "[,[3, 2, 1],[\"col \\\"1\\\", \\\"2\\\"\", \"col \\\"3\\\", \\\"4\\\"\", \"\"],[[null(), null(), null()], [null(), null()], [null()]],[[[-1.0E-7], [0.0]], [[0.0], [2.0]], [[0.0], [5.0E-7]]]]";
+
+ MatrixND matrix = stringEncoder.getMatrixFromString(representation);
+
+ Assert.assertEquals(3, matrix.getDim()[0]);
+ Assert.assertEquals(2, matrix.getDim()[1]);
+ Assert.assertEquals(1, matrix.getDim()[2]);
+ Assert.assertEquals(-1.0E-7, matrix.getValue(0, 0, 0), 0);
+ Assert.assertEquals(2, matrix.getValue(1, 1, 0), 0);
+ Assert.assertEquals(5.0E-7, matrix.getValue(2, 1, 0), 0);
+ Assert.assertEquals("col \"1\", \"2\"", matrix.getDimensionNames()[0]);
+ Assert.assertEquals("col \"3\", \"4\"", matrix.getDimensionNames()[1]);
+ }
} // MatrixHelperTest
1
0
[Lutinmatrix-commits] r124 - lutinmatrix/trunk
by chatellier@users.labs.libre-entreprise.org March 4, 2009
by chatellier@users.labs.libre-entreprise.org March 4, 2009
March 4, 2009
Author: chatellier
Date: 2009-03-04 09:44:40 +0000 (Wed, 04 Mar 2009)
New Revision: 124
Modified:
lutinmatrix/trunk/pom.xml
Log:
Add beanutils dep.
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-04 09:42:17 UTC (rev 123)
+++ lutinmatrix/trunk/pom.xml 2009-03-04 09:44:40 UTC (rev 124)
@@ -31,6 +31,13 @@
<version>2.4</version>
<scope>compile</scope>
</dependency>
+
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.0</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>commons-primitives</groupId>
1
0
[Lutinmatrix-commits] r123 - in lutinmatrix/trunk: . src/main/java/org/codelutin/math/matrix src/test/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org March 4, 2009
by chatellier@users.labs.libre-entreprise.org March 4, 2009
March 4, 2009
Author: chatellier
Date: 2009-03-04 09:42:17 +0000 (Wed, 04 Mar 2009)
New Revision: 123
Added:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
Modified:
lutinmatrix/trunk/pom.xml
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
Log:
Add matrix to string/from string convertion
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/pom.xml 2009-03-04 09:42:17 UTC (rev 123)
@@ -117,8 +117,19 @@
</plugin>
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -198,11 +198,33 @@
return name;
}
- public void setDimensionName(String[] names) {
+ public String[] getDimensionNames() {
+ return dimNames;
+ }
+
+ public void setDimensionNames(String[] names) {
for (int i = 0; names != null && i < names.length; i++) {
setDimensionName(i, names[i]);
}
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @deprecated Use #getDimensionNames()
+ */
+ public String[] getDimensionName() {
+ return getDimensionNames();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @deprecated Use #setDimensionName(String[])
+ */
+ public void setDimensionName(String[] names) {
+ setDimensionNames(names);
+ }
public void setDimensionName(int dim, String name) {
dimNames[dim] = name;
@@ -212,10 +234,6 @@
return dimNames[dim];
}
- public String[] getDimensionName() {
- return dimNames;
- }
-
public double getMaxOccurence() {
// on creer un tableau dans cette classe, car on ne sait pas sur quelle
// implantation on s'appuie. Mais dans les sous classes, si on a deja
@@ -513,7 +531,7 @@
// creation du resultat
MatrixND result = getFactory().create(getName(), semantics,
- getDimensionName());
+ getDimensionNames());
for (int i = 0; i < result.getDim(dim); i++) {
MatrixND temp = getSubMatrix(dim, i * step, step);
@@ -541,7 +559,7 @@
// creation du resultat
MatrixND result = getFactory().create(getName(), semantics,
- getDimensionName());
+ getDimensionNames());
MatrixND sub1 = this.getSubMatrix(dim, 0, start);
MatrixND sub2 = this.getSubMatrix(dim, start, nb).sumOverDim(dim);
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -35,165 +35,185 @@
*/
public class MatrixFactory { // MatrixFactory
- /*
- * following code in only an exception generator since lutinxml in not used
- * anymore :) static {
- * // on essai d'enregistrer le converter XML try { // Il faut le faire par
- * pur introspection sinon l'exception // NoClassDefFoundError est levé
- * avant d'entrer dans le constructeur // static :( Class converterClass =
- * Class .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); Object
- * converter = converterClass.newInstance();
- *
- * Class converterFactoryClass = Class
- * .forName("org.codelutin.xml.XMLConverterFactory"); Method m =
- * converterFactoryClass.getMethod("addConverter", Class.class, Class
- * .forName("org.codelutin.xml.XMLConverter")); m.invoke(null,
- * MatrixND.class, converter);
- * // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, //
- * new MatrixNDXMLConverter()); log.info("Converter XML pour MatrixND
- * ajoute");
- * // on essai d'enregistrer le converter JDBC // le JDBC depend du XML try {
- * converterClass = Class
- * .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); converter =
- * converterClass.newInstance();
- *
- * converterFactoryClass = Class
- * .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- * m = converterFactoryClass .getMethod( "addConverter", Class.class,
- * Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- * m.invoke(null, MatrixND.class, converter);
- * // Class converterClass = //
- * org.codelutin.math.matrix.MatrixNDJDBCConverter(); //
- * JDBCTransformerFactory // .addConverter(MatrixND.class, new
- * MatrixNDJDBCConverter()); log.info("Converter JDBC pour MatrixND
- * ajoute"); } catch (Throwable eee) { log .info("librairie topia non
- * presente. Import/Export JDBC impossible"); log.debug("L'exception etait",
- * eee); }
- * } catch (Throwable eee) { log .info("librairie lutinxml non presente.
- * Import/Export XML impossible"); log.debug("L'exception etait", eee); }
- * }
- */
+ /* following code in only an exception generator since
+ * lutinxml in not used anymore :)
+ static {
- /** Valeur par defaut si aucun type de Vector n'est donné */
- protected static Class defaultVectorClass = DoubleBigVector.class;
+ // on essai d'enregistrer le converter XML
+ try {
+ // Il faut le faire par pur introspection sinon l'exception
+ // NoClassDefFoundError est levé avant d'entrer dans le constructeur
+ // static :(
+ Class converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
+ Object converter = converterClass.newInstance();
- protected Class vectorClass = null;
+ Class converterFactoryClass = Class
+ .forName("org.codelutin.xml.XMLConverterFactory");
+ Method m = converterFactoryClass.getMethod("addConverter",
+ Class.class, Class
+ .forName("org.codelutin.xml.XMLConverter"));
+ m.invoke(null, MatrixND.class, converter);
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
+ // new MatrixNDXMLConverter());
+ log.info("Converter XML pour MatrixND ajoute");
- public static void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ // on essai d'enregistrer le converter JDBC
+ // le JDBC depend du XML
+ try {
+ converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
+ converter = converterClass.newInstance();
- public static Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ converterFactoryClass = Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ m = converterFactoryClass
+ .getMethod(
+ "addConverter",
+ Class.class,
+ Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ m.invoke(null, MatrixND.class, converter);
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- public static MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ // Class converterClass =
+ // org.codelutin.math.matrix.MatrixNDJDBCConverter();
+ // JDBCTransformerFactory
+ // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
+ log.info("Converter JDBC pour MatrixND ajoute");
+ } catch (Throwable eee) {
+ log
+ .info("librairie topia non presente. Import/Export JDBC impossible");
+ log.debug("L'exception etait", eee);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- public static MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ } catch (Throwable eee) {
+ log
+ .info("librairie lutinxml non presente. Import/Export XML impossible");
+ log.debug("L'exception etait", eee);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ }*/
- /**
- * Convert a double array into matrix.
- *
- * @param values
- * The values to fill the matrix
- * @param dim
- * An array representing the dimensions of the matrix
- * @return a 2D matrix filled with the values, null if the dimension is more
- * than 2
- */
- public MatrixND create(double[] values, int[] dim) {
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ protected static Class defaultVectorClass = DoubleBigVector.class;
- if (dim.length > 2) {
- return null;
- }
- MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
+ protected Class vectorClass = null;
- if (dim.length == 2) {
- for (int i = 0; i < dim[0]; i++) {
- for (int j = 0; j < dim[1]; j++) {
- int[] coordinates = { i, j };
- matrix.setValue(coordinates, values[i * dim[1] + j]);
- }
- }
- }
- if (dim.length == 1) {
- for (int i = 0; i < dim[0]; i++) {
- int[] coordinates = { i };
- matrix.setValue(coordinates, values[i]);
- }
- }
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- return matrix;
- }
+ public static void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
+ public static Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ public static MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ public static MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
+ /**
+ * Convert a double array into matrix.
+ *
+ * @param values
+ * The values to fill the matrix
+ * @param dim
+ * An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more
+ * than 2
+ */
+ public MatrixND create(double[] values, int[] dim) {
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size
- * la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = { i, j };
+ matrix.setValue(coordinates, values[i * dim[1] + j]);
+ }
+ }
+ }
+ if (dim.length == 1) {
+ for (int i = 0; i < dim[0]; i++) {
+ int[] coordinates = { i };
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
+ return matrix;
+ }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
+
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
+
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
+
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
+
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
+
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
+
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size
+ * la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
+
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
+
} // MatrixFactory
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -28,7 +28,7 @@
import org.apache.commons.logging.LogFactory;
/**
- * MatrixHelper.
+ * Contains usefull methods to get information on matrix.
*
* Created: 28 oct. 2004
*
@@ -40,6 +40,9 @@
*/
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.
@@ -253,21 +256,6 @@
return mat;
}
- // /**
- // * Crée une nouvelle matrice identité. Une matrice identité est une
- // * matrice à 2 dimensions dont tous les éléments de la diagonale
- // * valent 1
- // * @param size la taille de la matrice
- // * @return une nouvelle matrice identité
- // */
- // static public MatrixND matrixId(int size){
- // MatrixND result = new MatrixNDImpl(new int[]{size, size});
- // for(int i=0; i<size; i++){
- // result.setValue(i, i , 1);
- // }
- // return result;
- // }
-
/**
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
* plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
@@ -335,21 +323,4 @@
return result;
}
- // static public String encodeToXML(MatrixND mat){
- // StringWriter out = new StringWriter();
- // XMLEncoderDecoder.getInstance().encode(out, mat);
- // return out.toString();
- // }
- //
- // static public MatrixND decodeFromXML(String xml){
- // try{
- // return (MatrixND)XMLEncoderDecoder.getInstance().decode(new
- // StringReader(xml));
- // }catch(Exception eee){
- // throw new MatrixException("Erreur durant le decodage de la matrice",
- // eee);
- // }
- // }
-
} // MatrixHelper
-
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -15,8 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-
package org.codelutin.math.matrix;
import java.io.IOException;
@@ -39,13 +37,20 @@
public interface MatrixND extends Serializable, Cloneable { // MatrixND
/**
- * Retourne la factory qui a permit de creer la matrice
+ * Retourne la factory qui a permit de creer la matrice.
+ *
+ * @return la {@link MatrixFactory}
+ *
+ * @see MatrixFactory
*/
public MatrixFactory getFactory();
/**
- * Donne toutes les semantiques de la matrice Si la matrice n'a pas de
- * semantique retourne null
+ * Donne toutes les semantiques de la matrice.
+ *
+ * Si la matrice n'a pas de semantique retourne null.
+ *
+ * @return la liste des semantics
*/
public List[] getSemantics();
@@ -65,6 +70,8 @@
/**
* Permet de donner un nom à la matrice.
+ *
+ * @param name name to set
*/
public void setName(String name);
@@ -77,10 +84,39 @@
/**
* Permet de mettre des noms aux différentes dimension.
+ *
+ * @deprecated (since 1.0.3) Use #setDimensionNames(String[])
*/
public void setDimensionName(String[] names);
/**
+ * Permet de mettre des noms aux différentes dimension.
+ *
+ * @param names names to set
+ *
+ * @since 1.0.3
+ */
+ public void setDimensionNames(String[] names);
+
+ /**
+ * Permet de recuperer les noms des dimension.
+ *
+ * @return tableau des noms de dimension.
+ *
+ * @deprecated (since 1.0.3) Use #getDimensionNames()
+ */
+ public String[] getDimensionName();
+
+ /**
+ * Permet de recuperer les noms des dimension.
+ *
+ * @return tableau des noms de dimension.
+ *
+ * @since 1.0.3
+ */
+ public String[] getDimensionNames();
+
+ /**
* Permet de mettre un nom à une dimension.
*
* @param dim la dimension dont on veut changer le nom
@@ -97,8 +133,6 @@
*/
public String getDimensionName(int dim);
- public String[] getDimensionName();
-
/**
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
* plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -72,7 +72,7 @@
protected MatrixNDImpl(MatrixFactory factory, MatrixND matrix) {
super(factory, matrix.getName(), matrix.getSemantics(), matrix
- .getDimensionName());
+ .getDimensionNames());
this.matrix = new BasicMatrix(factory, dim);
this.paste(matrix);
}
Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java (rev 0)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -0,0 +1,342 @@
+/* *##% lutinmatrix
+ * Copyright (C) 2004 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.math.matrix;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.util.StringUtil;
+
+/**
+ * Convert matrix into {@link String} and inverse.
+ *
+ * Method from this class are non "static" to be overriden.
+ *
+ * Created: 04 mar. 2009
+ *
+ * @author chatellier
+ * @version $Revision: 120 $
+ *
+ * Mise a jour: $Date: 2009-03-03 11:19:18 +0100 (mar. 03 mars 2009) $
+ * par : $Author: chatellier $
+ */
+public class MatrixStringEncoder { // MatrixStringEncoder
+
+ /** Class logger */
+ private static Log log = LogFactory.getLog(MatrixStringEncoder.class);
+
+ /**
+ * Convert a matrix in string representation.
+ *
+ * String representation is composed in (ordered) :
+ * - name
+ * - dim
+ * - dimNames
+ * - semantics
+ * - data
+ *
+ * @param matrix matrix to convert
+ * @return a {@link String} representation
+ */
+ public String getMatrixAsString(MatrixND matrix) {
+ StringBuffer representationBuffer = new StringBuffer();
+ representationBuffer.append("["); // top level
+ representationBuffer.append(matrix.getName());
+ representationBuffer.append(",");
+ representationBuffer.append(getDimToString(matrix.getDim()));
+ representationBuffer.append(",");
+ representationBuffer.append(getDimensionNamesToString(matrix
+ .getDimensionNames()));
+ representationBuffer.append(",");
+ representationBuffer
+ .append(getSemanticsToString(matrix.getSemantics()));
+ representationBuffer.append(",");
+ representationBuffer.append(matrix.toList().toString());
+ representationBuffer.append("]"); // top level
+ return representationBuffer.toString();
+ }
+
+ /**
+ * Parse string as matrix representation.
+ *
+ * str must be in following format :
+ * - [name,dim,dimNames,semantics,data]
+ * @param str
+ * @return
+ */
+ public MatrixND getMatrixFromString(String str) {
+
+ MatrixND matrix = null;
+
+ // composed of 5 groups
+ Pattern matrixPattern = Pattern
+ .compile("^\\[(.*),(\\[.*\\]),(\\[.*\\]),(\\[.*\\]),(\\[.*\\])\\]$");
+ Matcher matcher = matrixPattern.matcher(str);
+
+ if (matcher.find()) {
+ String name = matcher.group(1);
+ String dimString = matcher.group(2);
+ String dimNamesString = matcher.group(3);
+ String semanticsString = matcher.group(4);
+ String dataString = matcher.group(5);
+
+ int[] dim = getDimFromString(dimString);
+ String[] dimNames = getDimensionNamesFromString(dimNamesString);
+ List<Object>[] semantics = getSemanticsFromString(semanticsString);
+
+ matrix = MatrixFactory.getInstance().create(name, semantics,
+ dimNames);
+ List<Object> data = MatrixHelper.convertStringToList(dataString);
+ matrix.fromList(data);
+ } else {
+ throw new IllegalArgumentException("Can't parse \"" + str
+ + "\" as string");
+ }
+
+ return matrix;
+ }
+
+ /**
+ * Matrix dim to string.
+ *
+ * @param dimArray dim to convert.
+ * @return a {@link String} representation
+ */
+ public String getDimToString(int[] dimArray) {
+ String result = "[";
+ String sep = "";
+ for (int i = 0; i < dimArray.length; i++) {
+ result += sep + dimArray[i];
+ sep = ", ";
+ }
+ result += "]";
+ return result;
+ }
+
+ /**
+ * String to matrix dim.
+ *
+ * @param str string to parse
+ * @return dim array
+ */
+ public int[] getDimFromString(String str) {
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ]
+ }
+ String[] dimAsString = StringUtil.split(localStr, ",");
+ int[] result = new int[dimAsString.length];
+ int i = 0;
+ for (String dim : dimAsString) {
+ int val = Integer.parseInt(dim.trim());
+ result[i++] = val;
+ }
+ return result;
+ }
+
+ /**
+ * Dim names to string.
+ *
+ * @param dimNamesArray dim array to convert
+ * @return a {@link String} representation
+ */
+ public String getDimensionNamesToString(String[] dimNamesArray) {
+ String result = "[";
+ String sep = "";
+ for (int i = 0; i < dimNamesArray.length; i++) {
+ result += sep + '"' + dimNamesArray[i] + '"';
+ sep = ", ";
+ }
+ result += "]";
+ return result;
+ }
+
+ /**
+ * String to dim names array.
+ *
+ * @param str string to parse
+ * @return a {@link String} representation
+ */
+ public String[] getDimensionNamesFromString(String str) {
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ]
+ }
+ String[] result = StringUtil.split(localStr, ",");
+ for (int i = 0; i < result.length; i++) {
+ result[i] = result[i].trim();
+ if (result[i].startsWith("\"") && result[i].endsWith("\"")) {
+ result[i] = result[i].substring(1, result[i].length() - 1); // remove " and "
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Semantics array to string.
+ *
+ * @param semanticsArray semantics arrayy
+ * @return string names array
+ */
+ public String getSemanticsToString(List<Object>[] 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();) {
+ appendString(result, it.next());
+ if (it.hasNext()) {
+ result.append(", ");
+ }
+ }
+ result.append("]");
+ if ((i + 1) < semanticsArray.length) {
+ result.append(", ");
+ }
+ }
+ return result.append("]").toString();
+ }
+
+ /**
+ * String to samantics.
+ *
+ * @param str la chaine representant la semantique
+ * @return
+ */
+ public List<Object>[] getSemanticsFromString(String str) {
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ]
+ }
+ String[] sems = StringUtil.split(localStr, ",");
+
+ List<Object>[] result = new List[sems.length];
+
+ for (int i = 0; i < sems.length; i++) {
+ result[i] = splitObjects(sems[i]);
+ }
+
+ return result;
+ }
+
+ /**
+ * Recréé chaque object de la chaine de caractere et l'ajoute dans une liste
+ * la chaine est de la forme.
+ *
+ * [null(), java.lang.String("toto"), ...]
+ *
+ * @param str la chaine representant
+ */
+ public List<Object> splitObjects(String str) {
+ List<Object> result = new LinkedList<Object>();
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1);
+ }
+ String[] elems = StringUtil.split(localStr, ",");
+ for (String elem : elems) {
+ elem = elem.trim();
+ int openbrace = elem.indexOf('(');
+ String objectType = elem.substring(0, openbrace);
+ String objectString = elem.substring(openbrace + 1,
+ elem.length() - 1);
+
+ if ("null".equals(objectType)) {
+ result.add(null);
+ } else {
+ ConvertUtilsBean converter = getConverter();
+ Object o;
+ try {
+ o = converter.convert(objectString, Class
+ .forName(objectType));
+ } catch (Exception e) {
+ // 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: '"
+ + o + "'");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "Continuing but can't convert object in matrix from String: '"
+ + o + "'", e);
+ }
+ }
+ result.add(o);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Append object type and value.
+ *
+ * qualifiedName(value)
+ * java.lang.String(test)
+ * java.lang.Double(4.5)
+ *
+ * @param buffer buffer to append to
+ * @param o object to put on buffer
+ * @return buffer
+ */
+ public StringBuffer appendString(StringBuffer buffer, Object o) {
+ if (o == null) {
+ buffer.append("null()");
+ } else {
+ String qualifiedName = getQualifiedName(o);
+ buffer.append(qualifiedName).append("(");
+ ConvertUtilsBean converter = getConverter();
+ buffer.append(converter.convert(o));
+ buffer.append(")");
+ }
+ return buffer;
+ }
+
+ /**
+ * Get object qualified name.
+ *
+ * Can't be overridden to put another impl.
+ *
+ * @param o object to get qulified name
+ * @return object qualified class name
+ */
+ public String getQualifiedName(Object o) {
+ String qualifiedName = o.getClass().getName();
+ return qualifiedName;
+ }
+
+ /**
+ * Get commons-beanutils bean converter.
+ * @return a {@link ConvertUtilsBean}
+ */
+ public ConvertUtilsBean getConverter() {
+ BeanUtilsBean instance = BeanUtilsBean.getInstance();
+ ConvertUtilsBean cub = instance.getConvertUtils();
+ return cub;
+ }
+
+} // MatrixStringEncoder
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -46,7 +46,7 @@
public SubMatrix(MatrixND matrix, int dim, int start, int nb) {
super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(),
- matrix.getDimensionName());
+ matrix.getDimensionNames());
this.matrix = matrix;
converter = new ShiftConverter(dim, start, nb);
@@ -56,7 +56,7 @@
public SubMatrix(MatrixND matrix, int dim, int[] elem) {
super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(),
- matrix.getDimensionName());
+ matrix.getDimensionNames());
this.matrix = matrix;
converter = new MappingConverter(dim, elem);
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -39,49 +39,51 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(MatrixHelperTest.class);
-
- public MatrixFactory getFactory() throws Exception {
+
+ public MatrixFactory getFactory() {
return MatrixFactory.getInstance();
}
@Test
- public void testCoordinatesToString() throws Exception {
- Assert.assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 }));
- Assert.assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2,
- 3, 4, 5 }));
- Assert.assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] {
- 2, 3, 4, 5, 234 }));
+ public void testCoordinatesToString() {
+ Assert.assertEquals("1", MatrixHelper
+ .coordinatesToString(new int[] { 1 }));
+ Assert.assertEquals("2,3,4,5", MatrixHelper
+ .coordinatesToString(new int[] { 2, 3, 4, 5 }));
+ Assert.assertEquals("2,3,4,5,234", MatrixHelper
+ .coordinatesToString(new int[] { 2, 3, 4, 5, 234 }));
Assert.assertEquals("a", MatrixHelper
.coordinatesToString(new String[] { "a" }));
- Assert.assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] {
- "a", "b", "n", "m" }));
+ Assert.assertEquals("a,b,n,m", MatrixHelper
+ .coordinatesToString(new String[] { "a", "b", "n", "m" }));
Assert.assertEquals("a,b,f,e,aze",
MatrixHelper.coordinatesToString(new String[] { "a", "b", "f",
"e", "aze" }));
}
@Test
- public void testSameDimension() throws Exception {
- Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 }));
- Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] {
- 1, 2 }));
+ public void testSameDimension() {
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 },
+ new int[] { 1 }));
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 },
+ new int[] { 1, 2 }));
Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 },
new int[] { 1, 324, 3 }));
}
@Test
- public void testDimensionToSemantics() throws Exception {
+ public void testDimensionToSemantics() {
// TODO faire un test pour dimensionToSemantics
}
@Test
- public void testSemanticsToDimension() throws Exception {
+ public void testSemanticsToDimension() {
// TODO faire un test pour semanticsToDimension
}
@Test
- public void testFill() throws Exception {
+ public void testFill() {
MatrixND mat = getFactory().create(new int[] { 3, 3 });
MatrixHelper.fill(mat, 4);
@@ -89,9 +91,10 @@
}
@Test
- public void testMatrixId() throws Exception {
+ public void testMatrixId() {
MatrixND mat = getFactory().matrixId(4);
- Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim()));
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat
+ .getDim()));
Assert.assertEquals(0, mat.getValue(1, 2), 0);
Assert.assertEquals(1, mat.getValue(0, 0), 0);
Assert.assertEquals(1, mat.getValue(1, 1), 0);
@@ -100,7 +103,7 @@
}
@Test
- public void testToList() throws Exception {
+ public void testToList() {
MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
mat1.setValue(0, 0, 0, -1.0E-7);
mat1.setValue(1, 1, 0, 2);
@@ -118,7 +121,7 @@
}
@Test
- public void testMaxOccurence() throws Exception {
+ public void testMaxOccurence() {
double[] val = new double[5];
Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
@@ -154,7 +157,7 @@
val = new double[0];
try {
MatrixHelper.maxOccurence(val);
- Assert.fail("AN exception must be thrown");
+ Assert.fail("An exception must be thrown");
} catch (IllegalArgumentException e) {
if (log.isDebugEnabled()) {
log.debug("Exception normally thrown", e);
@@ -162,6 +165,6 @@
}
}
-
+
} // MatrixHelperTest
Added: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java (rev 0)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -0,0 +1,146 @@
+/* *##% lutinmatrix
+ * Copyright (C) 2004 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.math.matrix;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * MatrixHelperTest.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision: 120 $
+ *
+ * Mise a jour: $Date: 2009-03-03 11:19:18 +0100 (mar. 03 mars 2009) $
+ * par : $Author: chatellier $
+ */
+public class MatrixStringEncoderTest { // MatrixHelperTest
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(MatrixStringEncoderTest.class);
+
+ protected MatrixStringEncoder stringEncoder;
+
+ @Before
+ public void setUp() {
+ stringEncoder = new MatrixStringEncoder();
+ }
+
+ public MatrixFactory getFactory() {
+ return MatrixFactory.getInstance();
+ }
+
+ @Test
+ public void testMatrixStringRepresentation() {
+
+ MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
+ mat1.setValue(0, 0, 0, -1.0E-7);
+ mat1.setValue(1, 1, 0, 2);
+ mat1.setValue(2, 1, 0, 5.0E-7);
+
+ String rep = stringEncoder.getMatrixAsString(mat1);
+
+ System.out.println(rep);
+
+ Assert.assertTrue("Null() semantics missing", rep.indexOf("null()") > 0);
+ Assert.assertTrue("Dimentation missing", rep.indexOf("3, 2, 1") > 0);
+ Assert.assertTrue("Data missing", rep.indexOf("[2.0]") > 0);
+ }
+
+ @Test
+ public void testMatrixFromString() {
+ String representation = "[,[3, 2, 1],[\"\", \"\", \"\"],[[null(), null(), null()], [null(), null()], [null()]],[[[-1.0E-7], [0.0]], [[0.0], [2.0]], [[0.0], [5.0E-7]]]]";
+
+ MatrixND matrix = stringEncoder.getMatrixFromString(representation);
+
+ Assert.assertEquals(3, matrix.getDim()[0]);
+ Assert.assertEquals(2, matrix.getDim()[1]);
+ Assert.assertEquals(1, matrix.getDim()[2]);
+ Assert.assertEquals(-1.0E-7, matrix.getValue(0, 0, 0), 0);
+ Assert.assertEquals(2, matrix.getValue(1, 1, 0), 0);
+ Assert.assertEquals(5.0E-7, matrix.getValue(2, 1, 0), 0);
+ }
+
+ @Test
+ public void testMatrixStringRepresentationWithMoreInfos() {
+
+ MatrixND mat1 = getFactory().create(new int[] { 2, 5 });
+ mat1.setName("StringRepresentationWithMoreInfos");
+ mat1.setValue(0, 0, -2);
+ mat1.setValue(1, 1, 2.345);
+ mat1.setValue(1, 4, -8.321);
+
+ List<Serializable> sem0 = new ArrayList<Serializable>();
+ sem0.add(new String("test"));
+ sem0.add(new Double(3.453));
+ mat1.setSemantics(0, sem0);
+ List<Serializable> sem1 = new ArrayList<Serializable>();
+ sem1.add(new Integer(7));
+ sem1.add(new Character('e'));
+ sem1.add(Byte.valueOf("1"));
+ sem1.add(Short.valueOf("3"));
+ sem1.add(new Integer(12));
+ mat1.setSemantics(1, sem1);
+
+ mat1.setDimensionNames(new String[] {"col1", "col2"});
+
+ String rep = stringEncoder.getMatrixAsString(mat1);
+
+ System.out.println(rep);
+
+ Assert.assertTrue("java.lang.String semantics missing", rep.indexOf("java.lang.String") > 0);
+ Assert.assertTrue("Dimentation missing", rep.indexOf("[2, 5]") > 0);
+ Assert.assertTrue("Data missing", rep.indexOf("[0.0, 2.345, 0.0, 0.0, -8.321]") > 0);
+ Assert.assertTrue("Columns name missing", rep.indexOf("[\"col1\", \"col2\"]") > 0);
+ Assert.assertTrue("Name missing", rep.indexOf("StringRepresentationWithMoreInfos") > 0);
+
+ }
+
+ @Test
+ public void testMatrixFromStringWithMoreInfos() {
+ String representation = "[StringRepresentationWithMoreInfos,[2, 5],[\"col1\", \"col2\"],[[java.lang.String(test), java.lang.Double(3.453)], [java.lang.Integer(7), java.lang.Character(e), java.lang.Byte(1), java.lang.Short(3), java.lang.Integer(12)]],[[-2.0, 0.0, 0.0, 0.0, 0.0], [0.0, 2.345, 0.0, 0.0, -8.321]]]";
+
+ MatrixND matrix = stringEncoder.getMatrixFromString(representation);
+
+ Assert.assertEquals("StringRepresentationWithMoreInfos", matrix.getName());
+ Assert.assertEquals(2, matrix.getDim()[0]);
+ Assert.assertEquals(5, matrix.getDim()[1]);
+ Assert.assertEquals("col1", matrix.getDimensionNames()[0]);
+ Assert.assertEquals("col2", matrix.getDimensionNames()[1]);
+ Assert.assertEquals("test", matrix.getSemantics(0).get(0));
+ Assert.assertEquals(3.453, matrix.getSemantics(0).get(1));
+ Assert.assertEquals(7, matrix.getSemantics(1).get(0));
+ Assert.assertEquals('e', matrix.getSemantics(1).get(1));
+ Assert.assertEquals(Byte.valueOf("1"), matrix.getSemantics(1).get(2));
+ Assert.assertEquals(Short.valueOf("3"), matrix.getSemantics(1).get(3));
+ Assert.assertEquals(12, matrix.getSemantics(1).get(4));
+ Assert.assertEquals(-2, matrix.getValue(0, 0), 0);
+ Assert.assertEquals(2.345, matrix.getValue(1, 1), 0);
+ Assert.assertEquals(-8.321, matrix.getValue(1, 4), 0);
+ }
+} // MatrixHelperTest
+
1
0
[Lutinmatrix-commits] r122 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by jcouteau@users.labs.libre-entreprise.org March 3, 2009
by jcouteau@users.labs.libre-entreprise.org March 3, 2009
March 3, 2009
Author: jcouteau
Date: 2009-03-03 14:01:27 +0000 (Tue, 03 Mar 2009)
New Revision: 122
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
Log:
Correct bug on asymmetrical matrices.
Add tests.
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 10:26:11 UTC (rev 121)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 14:01:27 UTC (rev 122)
@@ -26,190 +26,174 @@
* representation interne des matrices de facon simple.
* <p>
* Created: 11 octobre 2005 20:15:20 CEST
- *
+ *
* @author Benjamin POUSSIN <poussin(a)codelutin.com>
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ *
+ * Last update: $Date$ by :
+ * $Author$
*/
public class MatrixFactory { // MatrixFactory
- /* following code in only an exception generator since
- * lutinxml in not used anymore :)
- static {
+ /*
+ * following code in only an exception generator since lutinxml in not used
+ * anymore :) static {
+ * // on essai d'enregistrer le converter XML try { // Il faut le faire par
+ * pur introspection sinon l'exception // NoClassDefFoundError est levé
+ * avant d'entrer dans le constructeur // static :( Class converterClass =
+ * Class .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); Object
+ * converter = converterClass.newInstance();
+ *
+ * Class converterFactoryClass = Class
+ * .forName("org.codelutin.xml.XMLConverterFactory"); Method m =
+ * converterFactoryClass.getMethod("addConverter", Class.class, Class
+ * .forName("org.codelutin.xml.XMLConverter")); m.invoke(null,
+ * MatrixND.class, converter);
+ * // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, //
+ * new MatrixNDXMLConverter()); log.info("Converter XML pour MatrixND
+ * ajoute");
+ * // on essai d'enregistrer le converter JDBC // le JDBC depend du XML try {
+ * converterClass = Class
+ * .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); converter =
+ * converterClass.newInstance();
+ *
+ * converterFactoryClass = Class
+ * .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ * m = converterFactoryClass .getMethod( "addConverter", Class.class,
+ * Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ * m.invoke(null, MatrixND.class, converter);
+ * // Class converterClass = //
+ * org.codelutin.math.matrix.MatrixNDJDBCConverter(); //
+ * JDBCTransformerFactory // .addConverter(MatrixND.class, new
+ * MatrixNDJDBCConverter()); log.info("Converter JDBC pour MatrixND
+ * ajoute"); } catch (Throwable eee) { log .info("librairie topia non
+ * presente. Import/Export JDBC impossible"); log.debug("L'exception etait",
+ * eee); }
+ * } catch (Throwable eee) { log .info("librairie lutinxml non presente.
+ * Import/Export XML impossible"); log.debug("L'exception etait", eee); }
+ * }
+ */
- // on essai d'enregistrer le converter XML
- try {
- // Il faut le faire par pur introspection sinon l'exception
- // NoClassDefFoundError est levé avant d'entrer dans le constructeur
- // static :(
- Class converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
- Object converter = converterClass.newInstance();
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ protected static Class defaultVectorClass = DoubleBigVector.class;
- Class converterFactoryClass = Class
- .forName("org.codelutin.xml.XMLConverterFactory");
- Method m = converterFactoryClass.getMethod("addConverter",
- Class.class, Class
- .forName("org.codelutin.xml.XMLConverter"));
- m.invoke(null, MatrixND.class, converter);
+ protected Class vectorClass = null;
- // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
- // new MatrixNDXMLConverter());
- log.info("Converter XML pour MatrixND ajoute");
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- // on essai d'enregistrer le converter JDBC
- // le JDBC depend du XML
- try {
- converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
- converter = converterClass.newInstance();
+ public static void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- converterFactoryClass = Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- m = converterFactoryClass
- .getMethod(
- "addConverter",
- Class.class,
- Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- m.invoke(null, MatrixND.class, converter);
+ public static Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- // Class converterClass =
- // org.codelutin.math.matrix.MatrixNDJDBCConverter();
- // JDBCTransformerFactory
- // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
- log.info("Converter JDBC pour MatrixND ajoute");
- } catch (Throwable eee) {
- log
- .info("librairie topia non presente. Import/Export JDBC impossible");
- log.debug("L'exception etait", eee);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ public static MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- } catch (Throwable eee) {
- log
- .info("librairie lutinxml non presente. Import/Export XML impossible");
- log.debug("L'exception etait", eee);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ public static MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- }*/
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- /** Valeur par defaut si aucun type de Vector n'est donné */
- protected static Class defaultVectorClass = DoubleBigVector.class;
+ /**
+ * Convert a double array into matrix.
+ *
+ * @param values
+ * The values to fill the matrix
+ * @param dim
+ * An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more
+ * than 2
+ */
+ public MatrixND create(double[] values, int[] dim) {
- protected Class vectorClass = null;
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = { i, j };
+ matrix.setValue(coordinates, values[i * dim[1] + j]);
+ }
+ }
+ }
+ if (dim.length == 1) {
+ for (int i = 0; i < dim[0]; i++) {
+ int[] coordinates = { i };
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- public static void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ return matrix;
+ }
- public static Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- public static MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- public static MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
- /**
- * Convert a double array into matrix.
- *
- * @param values The values to fill the matrix
- * @param dim An array representing the dimensions of the matrix
- * @return a 2D matrix filled with the values, null if the dimension is more than 2
- */
- public MatrixND create(double[] values, int[] dim) {
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
- if (dim.length > 2) {
- return null;
- }
- MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
- if (dim.length == 2) {
- for (int i = 0; i < dim[0]; i++) {
- for (int j = 0; j < dim[1]; j++) {
- int[] coordinates = { i, j };
- matrix.setValue(coordinates, values[i * dim[0] + j]);
- }
- }
- }
- if (dim.length == 1) {
- for (int i = 0; i < dim[0]; i++) {
- int[] coordinates = { i };
- matrix.setValue(coordinates, values[i]);
- }
- }
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size
+ * la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
- return matrix;
- }
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
-
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
-
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
-
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
-
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
-
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
-
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
-
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
-
} // MatrixFactory
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 10:26:11 UTC (rev 121)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 14:01:27 UTC (rev 122)
@@ -543,7 +543,33 @@
Assert.assertEquals(7, (int) mat.getValue(new int[] { 2, 0 }));
Assert.assertEquals(8, (int) mat.getValue(new int[] { 2, 1 }));
Assert.assertEquals(9, (int) mat.getValue(new int[] { 2, 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6},
+ new int[] { 2, 3 });
+ Assert.assertEquals(2, mat.getDim().length);
+ Assert.assertEquals(2, mat.getDim(0));
+ Assert.assertEquals(3, mat.getDim(1));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 0, 2 }));
+ Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 0 }));
+ Assert.assertEquals(5, (int) mat.getValue(new int[] { 1, 1 }));
+ Assert.assertEquals(6, (int) mat.getValue(new int[] { 1, 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6},
+ new int[] { 3, 2 });
+
+ Assert.assertEquals(2, mat.getDim().length);
+ Assert.assertEquals(3, mat.getDim(0));
+ Assert.assertEquals(2, mat.getDim(1));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 1, 0 }));
+ Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 1 }));
+ Assert.assertEquals(5, (int) mat.getValue(new int[] { 2, 0 }));
+ Assert.assertEquals(6, (int) mat.getValue(new int[] { 2, 1 }));
+
mat = getFactory().create(new double[] { 1, 2, 3 }, new int[] { 3 });
Assert.assertEquals(1, mat.getDim().length);
Assert.assertEquals(3, mat.getDim(0));
1
0
[Lutinmatrix-commits] r121 - lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org March 3, 2009
by chatellier@users.labs.libre-entreprise.org March 3, 2009
March 3, 2009
Author: chatellier
Date: 2009-03-03 10:26:11 +0000 (Tue, 03 Mar 2009)
New Revision: 121
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
Log:
Improve code style
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:19:18 UTC (rev 120)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:26:11 UTC (rev 121)
@@ -75,7 +75,7 @@
/**
* Separateur CSV par défaut le point virgule.
*/
- public static char CSV_SEPARATOR = ';';
+ public static final char CSV_SEPARATOR = ';';
protected static final Pattern NUMBER = Pattern
.compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *");
1
0
[Lutinmatrix-commits] r120 - in lutinmatrix/trunk: . src/main/java/org/codelutin/math/matrix src/main/java/org/codelutin/math/matrix/gui src/test src/test/java/org/codelutin/math/matrix src/test/java/org/codelutin/math/matrix/gui src/test/resources
by chatellier@users.labs.libre-entreprise.org March 3, 2009
by chatellier@users.labs.libre-entreprise.org March 3, 2009
March 3, 2009
Author: chatellier
Date: 2009-03-03 10:19:18 +0000 (Tue, 03 Mar 2009)
New Revision: 120
Added:
lutinmatrix/trunk/src/test/resources/
lutinmatrix/trunk/src/test/resources/log4j.properties
Removed:
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java
Modified:
lutinmatrix/trunk/changelog.txt
lutinmatrix/trunk/pom.xml
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java
Log:
Clean code, move test to junit4.
Remove converter form lutinxml.
Modified: lutinmatrix/trunk/changelog.txt
===================================================================
--- lutinmatrix/trunk/changelog.txt 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/changelog.txt 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,3 +1,8 @@
+ver-1.3 chatellier 2009xxxx
+ * Move test to junit 4
+ * Update copyright
+ * Ajout de la serialisation des matrices
+
ver-1.2 chemit 20090218
* Switch to lutinutil 1.0
* Use lutinproject:3.4
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/pom.xml 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
<modelVersion>4.0.0</modelVersion>
<!-- ************************************************************* -->
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * AbstractMatrixND.java
- *
- * Created: 29 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.IOException;
@@ -45,26 +33,53 @@
import org.apache.commons.logging.LogFactory;
import org.codelutin.util.ArrayUtil;
+/**
+ * AbstractMatrixND.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
public abstract class AbstractMatrixND implements MatrixND { // AbstractMatrixND
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -6838751468730930727L;
+
/** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(AbstractMatrixND.class);
+ private static Log log = LogFactory.getLog(AbstractMatrixND.class);
- abstract public MatrixIterator iterator();
+ public abstract MatrixIterator iterator();
- abstract public double getValue(int[] coordinates);
+ public abstract double getValue(int[] coordinates);
- abstract public void setValue(int[] coordinates, double d);
+ public abstract void setValue(int[] coordinates, double d);
- transient protected DimensionHelper dimHelper = new DimensionHelper();
+ protected transient DimensionHelper dimHelper = new DimensionHelper();
- transient protected MatrixFactory factory = null;
+ protected transient MatrixFactory factory = null;
+
protected String name = "";
+
protected String[] dimNames = null;
+
protected int[] dim = null;
+
protected List[] semantics = null;
+
protected double defaultValue = 0;
+ /**
+ * Separateur CSV par défaut le point virgule.
+ */
+ public static char CSV_SEPARATOR = ';';
+
+ protected static final Pattern NUMBER = Pattern
+ .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *");
+
protected void init(int[] dim) {
this.dim = new int[dim.length];
System.arraycopy(dim, 0, this.dim, 0, dim.length);
@@ -279,7 +294,7 @@
public double getValue(int x, int y, int z, int t) {
return getValue(dimHelper.get(x, y, z, t));
- };
+ }
public void setValue(Object[] coordinates, double d) {
setValue(
@@ -845,11 +860,6 @@
}
/**
- * Separateur CSV par défaut la virgule
- */
- public static char CSV_SEPARATOR = ';';
-
- /**
* Determine si la matrice supporte l'import et l'export CSV
*
* @return support du CSV
@@ -858,9 +868,6 @@
return getNbDim() <= 2;
}
- Pattern NUMBER = Pattern
- .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *");
-
/**
* Import depuis un reader au format CSV des données dans la matrice
*
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * BasicMatrix.java
- *
- * Created: 27 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.Arrays;
@@ -37,6 +25,14 @@
/**
* Objet matrice qui ne permet que le stockage de double dans un matrice à
* autant de dimension que l'on souhaite.
+ *
+ * Created: 27 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class BasicMatrix { // BasicMatrix
@@ -46,6 +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
@@ -208,8 +205,8 @@
for (int i = 0; i < dim.length; i++) {
if (dim[i] <= 0) {
throw new IllegalArgumentException(I18n._(
- "lutinmatrix.invalid.size", new Integer(i),
- new Integer(dim[i])));
+ "lutinmatrix.invalid.size", Integer.valueOf(i),
+ Integer.valueOf(dim[i])));
}
}
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * BasicMatrixIterator.java
+package org.codelutin.math.matrix;
+
+/**
+ * BasicMatrixIterator.
*
* Created: 28 oct. 2004
*
@@ -26,35 +28,32 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface BasicMatrixIterator { // BasicMatrixIterator
/**
- * Retourne vrai s'il existe un suivant
+ * Retourne vrai s'il existe un suivant.
*
* @return vrai s'il y a un suivant, faux sinon
*/
public boolean hasNext();
/**
- * Passe à l'élément suivant
+ * Passe à l'élément suivant.
*/
public boolean next();
/**
- * Retourne les coordonnés de l'élément
+ * Retourne les coordonnés de l'élément.
*/
public int[] getCoordinates();
/**
- * Retourne la valeur courant pointé par l'iterator
+ * Retourne la valeur courant pointé par l'iterator.
*/
public double getValue();
/**
- * Modifie la valeur courant pointé par l'iterator
+ * Modifie la valeur courant pointé par l'iterator.
*/
public void setValue(double value);
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * DimensionHelper.java
- *
- * Created: 29 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
/**
@@ -36,6 +24,14 @@
* cette classe, par exemple il ne faut pas l'utiliser dans une méthode qui
* appelle une autre methode réutilisant le meme objet, car il sera alors
* modifier alors qu'il ne le faut pas pour la premiere methode appelée.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class DimensionHelper { // DimensionHelper
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * DoubleBigVector.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+
+/**
+ * DoubleBigVector.
*
* Created: 6 octobre 2005 02:54:36 CEST
*
@@ -26,11 +30,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-
public class DoubleBigVector implements Vector { // DoubleBigVector
protected double data[] = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatVector.java
- *
- * Created: 6 octobre 2005 01:29:23 CEST
- *
- * @author Benjamin POUSSIN <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.Arrays;
@@ -34,10 +22,18 @@
import org.apache.commons.collections.primitives.ArrayDoubleList;
/**
- * Permet de stocker des données à une position lineair et de la redemander
+ * Permet de stocker des données à une position lineaire et de la redemander.
* Cette classe ne gére que les données lineaire. L'avantage de cette classe est
* de ne conserver que les elements differents de la valeur par defaut, ce qui
* minimize la taille du tableau necessaire a conserver les données.
+ *
+ * Created: 6 octobre 2005 01:29:23 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class DoubleVector implements Vector { // FloatVector
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatBigVector.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+
+/**
+ * FloatBigVector.
*
* Created: 6 octobre 2005 02:54:36 CEST
*
@@ -26,11 +30,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-
public class FloatBigVector implements Vector { // FloatBigVector
protected float data[] = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatVector.java
- *
- * Created: 6 octobre 2005 01:29:23 CEST
- *
- * @author Benjamin POUSSIN <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.Arrays;
@@ -38,6 +26,14 @@
* Cette classe ne gére que les données lineaire. L'avantage de cette classe est
* de ne conserver que les elements differents de la valeur par defaut, ce qui
* minimize la taille du tableau necessaire a conserver les données.
+ *
+ * Created: 6 octobre 2005 01:29:23 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class FloatVector implements Vector { // FloatVector
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,11 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MapFunction.java
+package org.codelutin.math.matrix;
+
+/**
+ * Permet de faire un traitement sur des valeurs et d'en retourner
+ * des nouvelles.
*
* Created: 27 oct. 2004
*
@@ -26,9 +29,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface MapFunction { // MapFunction
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,16 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatriceEncoder.java
+package org.codelutin.math.matrix;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * MatriceEncoder.
*
* Created: 21 oct. 2004
*
@@ -26,15 +34,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
public class MatrixEncoder { // MatriceEncoder
protected Writer out = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,216 +15,201 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixFactory.java
- *
- * Created: 11 octobre 2005 20:15:20 CEST
- *
- * @author Benjamin POUSSIN <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* Cette classe permet de creer des matrices, toutes les creations de matrice
* doivent etre faite a travers cette classe. Cette classe permet de modifier la
* representation interne des matrices de facon simple.
* <p>
- *
+ * Created: 11 octobre 2005 20:15:20 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class MatrixFactory { // MatrixFactory
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(MatrixFactory.class);
+ /* following code in only an exception generator since
+ * lutinxml in not used anymore :)
+ static {
- static {
- // on essai d'enregistrer le converter XML
- try {
- // Il faut le faire par pur introspection sinon l'exception
- // NoClassDefFoundError est levé avant d'entrer dans le constructeur
- // static :(
- Class converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
- Object converter = converterClass.newInstance();
+ // on essai d'enregistrer le converter XML
+ try {
+ // Il faut le faire par pur introspection sinon l'exception
+ // NoClassDefFoundError est levé avant d'entrer dans le constructeur
+ // static :(
+ Class converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
+ Object converter = converterClass.newInstance();
- Class converterFactoryClass = Class
- .forName("org.codelutin.xml.XMLConverterFactory");
- Method m = converterFactoryClass.getMethod("addConverter",
- Class.class, Class
- .forName("org.codelutin.xml.XMLConverter"));
- m.invoke(null, MatrixND.class, converter);
+ Class converterFactoryClass = Class
+ .forName("org.codelutin.xml.XMLConverterFactory");
+ Method m = converterFactoryClass.getMethod("addConverter",
+ Class.class, Class
+ .forName("org.codelutin.xml.XMLConverter"));
+ m.invoke(null, MatrixND.class, converter);
- // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
- // new MatrixNDXMLConverter());
- log.info("Converter XML pour MatrixND ajoute");
+ // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
+ // new MatrixNDXMLConverter());
+ log.info("Converter XML pour MatrixND ajoute");
- // on essai d'enregistrer le converter JDBC
- // le JDBC depend du XML
- try {
- converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
- converter = converterClass.newInstance();
+ // on essai d'enregistrer le converter JDBC
+ // le JDBC depend du XML
+ try {
+ converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
+ converter = converterClass.newInstance();
- converterFactoryClass = Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- m = converterFactoryClass
- .getMethod(
- "addConverter",
- Class.class,
- Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- m.invoke(null, MatrixND.class, converter);
+ converterFactoryClass = Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ m = converterFactoryClass
+ .getMethod(
+ "addConverter",
+ Class.class,
+ Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ m.invoke(null, MatrixND.class, converter);
- // Class converterClass =
- // org.codelutin.math.matrix.MatrixNDJDBCConverter();
- // JDBCTransformerFactory
- // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
- log.info("Converter JDBC pour MatrixND ajoute");
- } catch (Throwable eee) {
- log
- .info("librairie topia non presente. Import/Export JDBC impossible");
- log.debug("L'exception etait", eee);
- }
+ // Class converterClass =
+ // org.codelutin.math.matrix.MatrixNDJDBCConverter();
+ // JDBCTransformerFactory
+ // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
+ log.info("Converter JDBC pour MatrixND ajoute");
+ } catch (Throwable eee) {
+ log
+ .info("librairie topia non presente. Import/Export JDBC impossible");
+ log.debug("L'exception etait", eee);
+ }
- } catch (Throwable eee) {
- log
- .info("librairie lutinxml non presente. Import/Export XML impossible");
- log.debug("L'exception etait", eee);
- }
+ } catch (Throwable eee) {
+ log
+ .info("librairie lutinxml non presente. Import/Export XML impossible");
+ log.debug("L'exception etait", eee);
+ }
- }
+ }*/
- /** Valeur par defaut si aucun type de Vector n'est donné */
- static protected Class defaultVectorClass = DoubleBigVector.class;
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ protected static Class defaultVectorClass = DoubleBigVector.class;
- protected Class vectorClass = null;
+ protected Class vectorClass = null;
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- static public void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ public static void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- static public Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ public static Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- static public MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ public static MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- static public MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ public static MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- /**
- *
- * @param values
- * The values to fill the matrix
- * @param dim
- * An array representing the dimensions of the matrix
- * @return a 2D matrix filled with the values, null if the dimension is more
- * than 2
- */
+ /**
+ * Convert a double array into matrix.
+ *
+ * @param values The values to fill the matrix
+ * @param dim An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more than 2
+ */
+ public MatrixND create(double[] values, int[] dim) {
- public MatrixND create(double[] values, int[] dim) {
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- if (dim.length > 2) {
- return null;
- }
- MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = { i, j };
+ matrix.setValue(coordinates, values[i * dim[0] + j]);
+ }
+ }
+ }
+ if (dim.length == 1) {
+ for (int i = 0; i < dim[0]; i++) {
+ int[] coordinates = { i };
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- if (dim.length == 2) {
- for (int i = 0; i < dim[0]; i++) {
- for (int j = 0; j < dim[1]; j++) {
- int[] coordinates = {i,j};
- matrix.setValue(coordinates, values[i * dim[0] + j]);
- }
- }
- }
- if (dim.length == 1){
- for (int i=0;i<dim[0];i++) {
- int[] coordinates = {i};
- matrix.setValue(coordinates, values[i]);
- }
- }
+ return matrix;
+ }
- return matrix;
- }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size
- * la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
-
} // MatrixFactory
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixHelper.java
- *
- * Created: 28 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.StreamTokenizer;
@@ -39,23 +27,27 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class MatrixHelper {
+/**
+ * MatrixHelper.
+ *
+ * Created: 28 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class MatrixHelper { // MatrixHelper
/**
- * Logger for this class
- */
- private static final Log log = LogFactory.getLog(MatrixHelper.class);
-
- // MatrixHelper
-
- /**
* Convert Matrix to identity matrix must have 2 dimensions. If dimension
* haven't same length, then the small dimension is used.
*
* @param mat
* @return
*/
- static public MatrixND convertToId(MatrixND mat) {
+ public static MatrixND convertToId(MatrixND mat) {
int size = mat.getDim(0);
if (size > mat.getDim(1)) {
size = mat.getDim(1);
@@ -72,7 +64,7 @@
/**
* Permet de relire une chaine du type [[[1, 2], [3, 4]],[[3, 5], [1, 4]]]
* <p>
- * Remarque: une premiere implatantion avait ete faite en utilisant
+ * Remarque: une premiere implantantion avait ete faite en utilisant
* {@link StreamTokenizer} mais en fait il y a un bug dedans, il ne sait pas
* parser les chiffres avec un exposant: 5.0E-7 par exemple est lu comme 5.0
* :(
@@ -84,7 +76,7 @@
* @param s la chaine representant les listes de liste
* @return une liste de liste ... de Double
*/
- static public List convertStringToList(String s) {
+ public static List convertStringToList(String s) {
List result = null;
Stack<List> stack = new Stack<List>();
StringBuffer number = new StringBuffer(20); // initial to 20 char
@@ -130,12 +122,12 @@
}
/**
- * permet de donner une repr�sentation String d'un tableau de coordonn�es
+ * permet de donner une représentation String d'un tableau de coordonnées
*
- * @param coordinates les coordonn�es
- * @return la chaine demand�e de la forme 1,3,34,23
+ * @param coordinates les coordonnées
+ * @return la chaine demandée de la forme 1,3,34,23
*/
- static public String coordinatesToString(int[] coordinates) {
+ public static String coordinatesToString(int[] coordinates) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < coordinates.length; i++) {
sb.append(coordinates[i]);
@@ -147,47 +139,48 @@
}
/**
- * permet de donner une repr�sentation String d'un tableau de coordonn�es
+ * permet de donner une représentation String d'un tableau de coordonnées
*
- * @param coordinates les coordonn�es
- * @return la chaine demand�e de la forme "Ob1","Ob2,"Ob3", ... la chaine
- * prise pour l'objet est celle retourn�e par la m�thode toString de
+ * @param coordinates les coordonnées
+ * @return la chaine demandée de la forme "Ob1","Ob2,"Ob3", ... la chaine
+ * prise pour l'objet est celle retournée par la méthode toString de
* l'objet
*/
- static public String coordinatesToString(Object[] coordinates) {
+ public static String coordinatesToString(Object[] coordinates) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < coordinates.length; i++) {
sb.append(coordinates[i]);
- if (i + 1 < coordinates.length)
+ if (i + 1 < coordinates.length) {
sb.append(',');
+ }
}
return sb.toString();
}
/**
- * Permet de savoir si deux dimension sont identique
+ * Permet de savoir si deux dimension sont identiques.
*/
- static public boolean sameDimension(int[] dim1, int[] dim2) {
+ public static boolean sameDimension(int[] dim1, int[] dim2) {
return Arrays.equals(dim1, dim2);
}
/**
- * Permet de convertir des coordonn�es d�fini par des entiers en coordonn�e
+ * Permet de convertir des coordonnées définies par des entiers en coordonnées
* semantique par des objets
*
- * @param semantics la semantique � utilis� pour la conversion
- * @param coordinates les coordonn�es � convertir
- * @return un tableau donnant les coordonn�es sous forme semantique s'il n'y
+ * @param semantics la semantique à utilisé pour la conversion
+ * @param coordinates les coordonnées à convertir
+ * @return un tableau donnant les coordonnées sous forme semantique s'il n'y
* a pas de semantique (liste pleine de null) alors un objet Integer
- * est cr�er pour repr�senter la semantique de la dimension.
+ * est créer pour représenter la semantique de la dimension.
*/
- static public 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++) {
result[i] = semantics[i].get(coordinates[i]);
if (result[i] == null) {
- result[i] = new Integer(coordinates[i]);
+ result[i] = Integer.valueOf(coordinates[i]);
}
}
return result;
@@ -204,7 +197,7 @@
* Integer alors la valeur de l'integer est utilisé pour la
* conversion.
*/
- static public 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++) {
@@ -220,12 +213,14 @@
/**
* Permet de retrouver la position d'un objet dans une liste
*
- * @param semantics la semantique � utilis� pour la recherche
+ * @param semantics la semantique à utilisé pour la recherche
* @param dim la dimension dans lequel il faut faire la recherche
- * @param o l'objet � rechercher
- * @return la position de l'objet dans la dimension demand�e
+ * @param o l'objet à rechercher
+ * @return la position de l'objet dans la dimension demandée
+ *
+ * @throws NoSuchElementException If element doesn't exists
*/
- static public 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();
@@ -236,20 +231,20 @@
}
if (result == -1) {
throw new NoSuchElementException(
- "L'objet pass� en argument n'a pas �t� retrouve ou la dimension donn�e ne convient pas:"
+ "L'objet passé en argument n'a pas été retrouvé ou la dimension donnée ne convient pas:"
+ o + " in " + semantics[dim]);
}
return result;
}
/**
- * Permet de remplir toute la matrice avec la m�me donn�e
+ * Permet de remplir toute la matrice avec la même donnée
*
- * @param mat la matrice � remplir
+ * @param mat la matrice à remplir
* @param value la valeur de remplissage
- * @return la matrice pass� en param�tre
+ * @return la matrice passé en paramêtre
*/
- static public MatrixND fill(MatrixND mat, final double value) {
+ public static MatrixND fill(MatrixND mat, final double value) {
mat.map(new MapFunction() {
public double apply(double v) {
return value;
@@ -259,11 +254,11 @@
}
// /**
- // * Cr�e une nouvelle matrice identit�. Une matrice identit� est une
- // matrice
- // * � 2 dimensions dont tous les �l�ments de la diagonal vaut 1
+ // * Crée une nouvelle matrice identité. Une matrice identité est une
+ // * matrice à 2 dimensions dont tous les éléments de la diagonale
+ // * valent 1
// * @param size la taille de la matrice
- // * @return une nouvelle matrice identit�
+ // * @return une nouvelle matrice identité
// */
// static public MatrixND matrixId(int size){
// MatrixND result = new MatrixNDImpl(new int[]{size, size});
@@ -275,19 +270,19 @@
/**
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
- * plusieurs valeurs ont le m�me nombre d'occurence la plus petite valeur
- * est retourn�.
+ * plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
+ * est retournée.
*
* @param tab le tableau de valeur
* @return la valeur la plus nombreuse dans le tableau
*/
- static public double maxOccurence(double[] tab) {
+ public static double maxOccurence(double[] tab) {
double[] tmp = new double[tab.length];
System.arraycopy(tab, 0, tmp, 0, tab.length);
return maxOccurence1(tmp);
}
- static public double maxOccurence(float[] tab) {
+ public static double maxOccurence(float[] tab) {
double[] tmp = new double[tab.length];
for (int i = 0; i < tab.length; i++) {
tmp[i] = tab[i];
@@ -297,9 +292,9 @@
/**
* le tableau en entre est trie durant l'execution de la methode, il est
- * donc modifi�
+ * donc modifié
*/
- static protected double maxOccurence1(double[] tmp) {
+ protected static double maxOccurence1(double[] tmp) {
if (tmp.length == 0) {
throw new IllegalArgumentException("Array must be not empty");
}
@@ -313,7 +308,7 @@
int count = 1;
// la valeur la plus rencontrer
double result = tmp[0];
- // la valeur que l'on vient de traiter pr�c�dement
+ // la valeur que l'on vient de traiter précédement
double old = tmp[0];
// la valeur courante lu dans le tableaux
double current = tmp[0];
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixIterator.java
+package org.codelutin.math.matrix;
+
+/**
+ * MatrixIterator.
*
* Created: 28 oct. 2004
*
@@ -26,9 +28,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface MatrixIterator extends BasicMatrixIterator { // MatrixIterator
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixIteratorImpl.java
+package org.codelutin.math.matrix;
+
+import java.util.List;
+
+/**
+ * MatrixIteratorImpl.
*
* Created: 28 oct. 2004
*
@@ -26,11 +30,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.List;
-
public class MatrixIteratorImpl implements MatrixIterator { // MatrixIteratorImpl
protected BasicMatrixIterator iterator = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,18 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixND.java
+
+
+package org.codelutin.math.matrix;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * MatrixND.
*
* Created: 29 oct. 2004
*
@@ -26,15 +36,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Serializable;
-import java.io.Writer;
-import java.util.List;
-
public interface MatrixND extends Serializable, Cloneable { // MatrixND
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,13 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixNDImpl.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * MatrixNDImpl.
*
* Created: 29 oct. 2004
*
@@ -26,15 +31,9 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-import java.util.List;
-
public class MatrixNDImpl extends AbstractMatrixND { // MatrixNDImpl
- /** */
+ /** serialVersionUID. */
private static final long serialVersionUID = 1L;
protected BasicMatrix matrix = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * SemanticList.java
- *
- * Created: 6 sept. 06 17:18:23
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.AbstractList;
@@ -37,7 +25,15 @@
import java.util.RandomAccess;
/**
+ * SemanticList.
+ *
+ * Created: 6 sept. 06 17:18:23
+ *
* @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class SemanticList<T> extends AbstractList<T> implements RandomAccess {
@@ -49,8 +45,6 @@
}
/*
- * (non-Javadoc)
- *
* @see java.util.AbstractList#get(int)
*/
@Override
@@ -60,8 +54,6 @@
}
/*
- * (non-Javadoc)
- *
* @see java.util.AbstractCollection#size()
*/
@Override
@@ -71,8 +63,6 @@
}
/*
- * (non-Javadoc)
- *
* @see java.util.AbstractList#indexOf(java.lang.Object)
*/
@Override
@@ -89,7 +79,7 @@
/**
* @return
*/
- private Map getIndex() {
+ protected Map getIndex() {
if (index == null) {
index = new HashMap<Object, Integer>();
for (int i = 0; i < datas.size(); i++) {
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * SubMatrix.java
- *
- * Created: 29 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.Serializable;
@@ -39,12 +27,20 @@
* Pour l'instant une sous matrice a obligatoirement le meme nombre de dimension
* que la matrice qu'elle contient. Elle permet juste de reduire le nombre
* d'element d'une dimension.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class SubMatrix extends AbstractMatrixND { // SubMatrix
- /** */
- private static final long serialVersionUID = 1L;
-
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 4092234115185263506L;
+
protected MatrixND matrix = null;
protected DimensionConverter converter = null;
@@ -183,9 +179,10 @@
* La conversion est le mapping d'un element vers un autre element
*/
protected class MappingConverter implements DimensionConverter {
- /** */
- private static final long serialVersionUID = 1L;
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -6367416559713556559L;
+
protected int dim;
protected int[] elem = null;
@@ -203,7 +200,7 @@
return result;
} else {
throw new NoSuchElementException(
- "L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension.");
+ "L'indice est supérieur au nombre d'élements de la sous matrice pour cette dimension.");
}
}
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * Vector.java
+package org.codelutin.math.matrix;
+
+/**
+ * Vector.
*
* Created: 6 octobre 2005 02:51:12 CEST
*
@@ -26,9 +28,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface Vector { // Vector
public double getMaxOccurence();
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,6 +1,6 @@
/*
* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -55,10 +55,18 @@
* TODO: Une methode permettant de retourne la sous matrice de la selection que
* la matrice soit reprensentée en lineaire ou non. (avoir un mapping cellule de
* table vers element de matrice
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class MatrixPanelEditor extends JPanel implements TableModelListener { // MatrixPanelEditor
- /** */
+ /** serialVersionUID */
private static final long serialVersionUID = 2097859265435050946L;
private final static int DEFAULT_WIDTH = 150;
@@ -148,7 +156,7 @@
initDimensionEdit();
}
- JButton bEdit = null;
+ protected JButton bEdit = null;
protected JButton getButtonEdit() {
if (bEdit == null) {
@@ -316,13 +324,6 @@
fireEvent();
}
- /**
- * @deprecated use setMatrix
- */
- public void setMatrice(MatrixND m) throws MatrixException {
- setMatrix(m);
- }
-
public MatrixND getMatrix() {
// if (m == null) {
return m;
@@ -334,13 +335,6 @@
}
/**
- * @deprecated use setMatrix
- */
- public MatrixND getMatrice() {
- return getMatrix();
- }
-
- /**
* Enable the matrix to be edited. By default, the matrix is editable.
*/
public void setEnabled(boolean enabled) {
@@ -367,10 +361,7 @@
}
/*
- * (non-Javadoc)
- *
- * @seejavax.swing.event.TableModelListener#tableChanged(javax.swing.event.
- * TableModelEvent)
+ * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
*/
public void tableChanged(TableModelEvent e) {
fireEvent();
@@ -440,7 +431,6 @@
// final MatrixPanelEditor mp = ed;
frame.addWindowListener(new WindowAdapter() {
-
public void windowClosing(WindowEvent e) {
System.exit(0);
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -15,8 +15,14 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixPanelEvent.java
+package org.codelutin.math.matrix.gui;
+
+import java.util.EventObject;
+
+import org.codelutin.math.matrix.MatrixND;
+
+/**
+ * MatrixPanelEvent.
*
* Created: 21 mars 2006 14:53:25
*
@@ -26,20 +32,11 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix.gui;
-
-import java.util.EventObject;
-
-import org.codelutin.math.matrix.MatrixND;
-
-/**
- * @author poussin
- *
- */
-
public class MatrixPanelEvent extends EventObject {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 368165247855055401L;
+
/**
* @param source
*/
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixPanelListener.java
+package org.codelutin.math.matrix.gui;
+
+/**
+ * MatrixPanelListener.
*
* Created: 21 mars 2006 14:54:05
*
@@ -26,14 +28,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix.gui;
-
-/**
- * @author poussin
- *
- */
-
public interface MatrixPanelListener {
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixPopupMenu.java
- *
- * Created: 22 mars 2006 12:11:46
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import static org.codelutin.i18n.I18n._;
@@ -61,11 +49,19 @@
/**
* Ajout d'un menu contextuel sur la matrice dans l'editeur
*
+ * Created: 22 mars 2006 12:11:46
+ *
* @author ruchaud
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class MatrixPopupMenu extends JPopupMenu {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 3349189688987885915L;
+
private MatrixPanelEditor matrixEditor;
private JFileChooser fileChooser;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModel.java
- *
- * Created: 22 mars 2006 12:53:22
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import javax.swing.table.TableCellRenderer;
@@ -35,10 +23,16 @@
import org.codelutin.math.matrix.MatrixND;
/**
+ * MatrixTableModel.
+ *
+ * Created: 22 mars 2006 12:53:22
+ *
* @author poussin
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
-
public interface MatrixTableModel extends TableModel {
public void setMatrix(MatrixND m);
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModelLinear.java
- *
- * Created: 22 mars 2006 12:11:46
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import java.awt.Color;
@@ -49,19 +37,25 @@
import org.codelutin.math.matrix.MatrixND;
/**
+ * MatrixTableModelLinear.
+ *
+ * Created: 22 mars 2006 12:11:46
+ *
* @author poussin
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
-
public class MatrixTableModelLinear extends AbstractTableModel implements
MatrixTableModel {
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory
- .getLog(MatrixTableModelLinear.class);
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -7498520067143762434L;
+ /** Logger for this class. */
+ private static Log log = LogFactory.getLog(MatrixTableModelLinear.class);
+
protected boolean enabled = true;
protected MatrixND m = null;
protected boolean showDefault = false;
@@ -138,8 +132,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() {
@@ -147,8 +139,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() {
@@ -156,8 +146,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex) {
@@ -171,8 +159,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
*/
@Override
@@ -181,10 +167,7 @@
}
/*
- * (non-Javadoc)
- *
- * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object,
- * int, int)
+ * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
@@ -201,8 +184,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.AbstractTableModel#getColumnName(int)
*/
@Override
@@ -235,6 +216,9 @@
class MatrixCellRenderer extends DefaultTableCellRenderer {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 6537813058357761914L;
+
protected MatrixTableModelLinear model = null;
protected Color bg = null;
protected Color fg = null;
@@ -249,9 +233,6 @@
border = getBorder();
}
- /** */
- private static final long serialVersionUID = 6537813058357761914L;
-
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModel.java
- *
- * Created: 21 mars 2006 19:01:27
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import java.awt.Color;
@@ -47,20 +35,23 @@
import org.codelutin.math.matrix.MatrixND;
/**
- * @author poussin
+ * Extension de AbstractTableModel pour definir un TableModel avec une
+ * MatrixND comme support d'information.
*
+ * TODO changer les 'matrice' en 'matrix', s'il y a des methodes public
+ * avec les nom 'matice' les laisser mais les mettres depreciées
+ *
+ * Created: 21 mars 2006 19:01:27
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
+public class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel {
-public/*
- * Extension de AbstractTableModel pour definir un TableModel avec une
- * MatrixND comme support d'information.
- *
- * @todo changer les 'matrice' en 'matrix', s'il y a des methodes public
- * avec les nom 'matice' les laisser mais les mettres depreciées
- */
-class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel {
-
- /** */
+ /** serialVersionUID. */
private static final long serialVersionUID = 983978774901981167L;
protected MatrixND m;
@@ -318,6 +309,9 @@
class MatrixCellRenderer extends DefaultTableCellRenderer {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 6537813058357761914L;
+
protected MatrixTableModelND model = null;
protected Color bg = null;
protected Color fg = null;
@@ -332,9 +326,6 @@
border = getBorder();
}
- /** */
- private static final long serialVersionUID = 6537813058357761914L;
-
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatriceTest.java
+package org.codelutin.math.matrix;
+
+/**
+ * BasicMatrixBigTest.
*
* Created: 27 oct. 2004
*
@@ -26,14 +28,11 @@
* Mise a jour: $Date$
* par : $Author$
*/
+public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixBigTest
-package org.codelutin.math.matrix;
-
-public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixTest
-
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance(FloatBigVector.class);
}
-} // BasicMatrixTest
+} // BasicMatrixBigTest
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -15,8 +15,17 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatriceTest.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * BasicMatrixTest.
*
* Created: 27 oct. 2004
*
@@ -26,96 +35,89 @@
* Mise a jour: $Date$
* par : $Author$
*/
+public class BasicMatrixTest { // BasicMatrixTest
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-import java.util.NoSuchElementException;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-
-public class BasicMatrixTest extends TestCase { // BasicMatrixTest
-
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance();
}
+ @Test
public void testNew() throws Exception {
BasicMatrix mat = null;
try {
mat = new BasicMatrix(getFactory(), null);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (NullPointerException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
try {
mat = new BasicMatrix(getFactory(), new int[] { 0 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IllegalArgumentException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
mat = new BasicMatrix(getFactory(), new int[] { 100 });
mat = new BasicMatrix(getFactory(), new int[] { 10, 1 });
- assertEquals(0.0, mat.getMaxOccurence());
+ Assert.assertEquals(0.0, mat.getMaxOccurence(), 0);
mat = new BasicMatrix(getFactory(), new int[] { 10, 10, 10, 10 });
try {
mat = new BasicMatrix(getFactory(), new int[] { -10 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IllegalArgumentException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
try {
mat = new BasicMatrix(getFactory(), new int[] { 10, 20, -10, 20 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IllegalArgumentException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
}
+ @Test
public void testDimension() throws Exception {
BasicMatrix mat = null;
mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 30, 5 });
- assertEquals(4, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(10, mat.getDim(1));
- assertEquals(30, mat.getDim(2));
- assertEquals(5, mat.getDim(3));
+ Assert.assertEquals(4, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(10, mat.getDim(1));
+ Assert.assertEquals(30, mat.getDim(2));
+ Assert.assertEquals(5, mat.getDim(3));
try {
mat.getDim(-3);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IndexOutOfBoundsException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
try {
mat.getDim(4);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IndexOutOfBoundsException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
}
+ @Test
public void testGetSet() throws Exception {
BasicMatrix mat = null;
// test avec la plus petit BasicMatrix possible
mat = new BasicMatrix(getFactory(), new int[] { 1 });
// test la valeur par defaut doit etre 0
- assertEquals(0, mat.getValue(new int[] { 0 }), 0);
+ Assert.assertEquals(0, mat.getValue(new int[] { 0 }), 0);
mat.setValue(new int[] { 0 }, 30);
- assertEquals(30, mat.getValue(new int[] { 0 }), 0);
+ Assert.assertEquals(30, mat.getValue(new int[] { 0 }), 0);
// acces a un element qui n'existe pas
try {
mat.getValue(new int[] { 1 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (NoSuchElementException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 5 });
@@ -134,37 +136,39 @@
mat.setValue(new int[] { 0, 2, 2 }, 22);
mat.setValue(new int[] { 0, 9, 4 }, 98);
mat.setValue(new int[] { 0, 4, 2 }, 97);
- assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0);
- assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0);
- assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0);
+ Assert.assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0);
+ Assert.assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0);
+ Assert.assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0);
// System.out.println(mat.toString());
// acces a un element qui n'existe pas
try {
mat.setValue(new int[] { 0, 9, 5 }, 44);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (NoSuchElementException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
}
+ @Test
public void testEquals() throws Exception {
BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3, 3 });
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3, 3 });
- assertEquals(m1, m2);
+ Assert.assertEquals(m1, m2);
m1.setValue(new int[] { 1, 2, 1, 2 }, 123);
m2.setValue(new int[] { 1, 2, 1, 2 }, 123);
- assertEquals(m1, m2);
+ Assert.assertEquals(m1, m2);
m1.setValue(new int[] { 1, 0, 1, 0 }, 321);
- assertFalse(m1.equals(m2));
+ Assert.assertFalse(m1.equals(m2));
}
+ @Test
public void testIterator() throws Exception {
int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
@@ -184,7 +188,7 @@
cpt++;
}
- assertEquals(27, cpt);
+ Assert.assertEquals(27, cpt);
cpt = 0;
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 1 });
@@ -194,15 +198,16 @@
cpt++;
}
- assertEquals(1, cpt);
+ Assert.assertEquals(1, cpt);
}
- MapFunction f = new MapFunction() {
+ protected MapFunction f = new MapFunction() {
public double apply(double value) {
return value + 2;
}
};
+ @Test
public void testPerfLineaire() throws Exception {
long time = System.nanoTime();
BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
@@ -214,6 +219,7 @@
"s'.'S"));
}
+ @Test
public void testPerfCoordonnee() throws Exception {
long time = System.nanoTime();
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
@@ -245,6 +251,7 @@
}
+ @Test
public void testPerfCoordonnee2() throws Exception {
long time = System.nanoTime();
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
@@ -276,6 +283,7 @@
}
+ @Test
public void testPerfCoordonnee4() throws Exception {
long time = System.nanoTime();
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,15 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatVectorTest.java
+package org.codelutin.math.matrix;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * FloatVectorTest.
*
* Created: 6 octobre 2005 01:54:49 CEST
*
@@ -26,27 +33,26 @@
* Last update: $Date$
* by : $Author$
*/
+public class FloatVectorTest { // FloatVectorTest
-package org.codelutin.math.matrix;
-
-import junit.framework.TestCase;
-
-public class FloatVectorTest extends TestCase { // FloatVectorTest
-
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(FloatVectorTest.class);
+
+ @Test
public void testAll() throws Exception {
FloatVector v = new FloatVector(16);
- assertEquals(0.0, v.getMaxOccurence());
+ Assert.assertEquals(0.0, v.getMaxOccurence(), 0);
v.setValue(0, 1);
- assertEquals(1.0, v.getValue(0));
+ Assert.assertEquals(1.0, v.getValue(0), 0);
v.setValue(15, 16);
- assertEquals(16.0, v.getValue(15));
+ Assert.assertEquals(16.0, v.getValue(15), 0);
- assertEquals(2, v.positionSize);
+ Assert.assertEquals(2, v.positionSize);
v.setValue(0, 0);
- assertEquals(0.0, v.getValue(0));
- assertEquals(1, v.positionSize);
+ Assert.assertEquals(0.0, v.getValue(0), 0);
+ Assert.assertEquals(1, v.positionSize);
v.setValue(0, 4);
v.setValue(1, 4);
@@ -55,27 +61,30 @@
v.setValue(4, 4);
v.setValue(5, 4);
v.setValue(6, 4);
- assertEquals(0.0, v.getMaxOccurence());
+ Assert.assertEquals(0.0, v.getMaxOccurence(), 0);
v.setValue(8, 4);
- assertEquals(4.0, v.getMaxOccurence());
+ Assert.assertEquals(4.0, v.getMaxOccurence(), 0);
v.setValue(0, 0);
- assertEquals(0.0, v.getMaxOccurence());
+ Assert.assertEquals(0.0, v.getMaxOccurence(), 0);
try {
v.getValue(-1);
- assertTrue(false);
- } catch (IllegalArgumentException eee) {
- assertTrue(true);
+ Assert.fail("An exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception normally thrown", e);
+ }
}
try {
v.getValue(20);
- assertTrue(false);
- } catch (IllegalArgumentException eee) {
- assertTrue(true);
+ Assert.fail("An exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception normally thrown", e);
+ }
}
}
} // FloatVectorTest
-
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,6 +1,5 @@
-/*
- * *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+/* *##% lutinmatrix
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -24,26 +23,32 @@
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
/**
- * Test de l'import et export CSV
+ * Test de l'import et export CSV.
*
* @author ruchaud
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
-public class ImportExportMatrixTest extends TestCase {
+public class ImportExportMatrixTest {
- private MatrixND mat1D;
- private MatrixND mat2D;
- private MatrixND mat2DSemantics;
+ protected MatrixND mat1D;
+ protected MatrixND mat2D;
+ protected MatrixND mat2DSemantics;
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance(DoubleVector.class);
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
mat1D = new MatrixNDImpl(getFactory(), new int[] { 10 });
mat1D.setValue(new int[] { 0 }, 0);
mat1D.setValue(new int[] { 1 }, 1);
@@ -70,6 +75,7 @@
sem1, sem2 }, new String[] { "dim1", "dim2" });
}
+ @Test
public void testImport() throws IOException {
String test = "5.0E-7;1.0;2.0;3.0;4.0;4.0;4.0;4.0;0.3;0.0\n"
+ "0.0;0.0;7.0;0.0;0.0;2.0;0.0;0.0;4.0;0.0\n"
@@ -77,19 +83,20 @@
StringReader reader = new StringReader(test);
mat2D.importCSV(reader, new int[] { 0, 0 });
- assertEquals(mat2D.getValue(0, 0), 5.0E-7);
- assertEquals(mat2D.getValue(1, 2), 7.0);
- assertEquals(mat2D.getValue(2, 2), 8.0);
- assertEquals(mat2D.getValue(1, 8), 4.0);
+ Assert.assertEquals(mat2D.getValue(0, 0), 5.0E-7, 0);
+ Assert.assertEquals(mat2D.getValue(1, 2), 7.0, 0);
+ Assert.assertEquals(mat2D.getValue(2, 2), 8.0, 0);
+ Assert.assertEquals(mat2D.getValue(1, 8), 4.0, 0);
reader = new StringReader(test);
mat2D.importCSV(reader, new int[] { 1, 1 });
- assertEquals(mat2D.getValue(1, 1), 5.0E-7);
- assertEquals(mat2D.getValue(2, 3), 7.0);
- assertEquals(mat2D.getValue(3, 3), 8.0);
- assertEquals(mat2D.getValue(2, 9), 4.0);
+ Assert.assertEquals(mat2D.getValue(1, 1), 5.0E-7, 0);
+ Assert.assertEquals(mat2D.getValue(2, 3), 7.0, 0);
+ Assert.assertEquals(mat2D.getValue(3, 3), 8.0, 0);
+ Assert.assertEquals(mat2D.getValue(2, 9), 4.0, 0);
}
+ @Test
public void testExport() throws IOException {
testExport(mat1D, false);
testExport(mat2D, false);
@@ -101,7 +108,8 @@
testExport(mat2DSemantics, true);
}
- private void testExport(MatrixND matrixND, boolean withSemantics)
+ @Ignore
+ protected void testExport(MatrixND matrixND, boolean withSemantics)
throws IOException {
StringWriter writer = new StringWriter();
matrixND.exportCSV(writer, withSemantics);
@@ -112,15 +120,16 @@
StringWriter readerToWriter = new StringWriter();
matrixND.exportCSV(readerToWriter, withSemantics);
- assertEquals(writer.toString(), readerToWriter.toString());
+ Assert.assertEquals(writer.toString(), readerToWriter.toString());
}
+ @Test
public void testSupport() throws Exception {
- assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 })
+ Assert.assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 })
.isSupportedCSV());
- assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 })
+ Assert.assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 })
.isSupportedCSV());
- assertEquals(false, new MatrixNDImpl(getFactory(),
+ Assert.assertEquals(false, new MatrixNDImpl(getFactory(),
new int[] { 3, 3, 3 }).isSupportedCSV());
}
}
Deleted: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,82 +0,0 @@
-/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * MatrixEncoderDecoderTest.java
- *
- * Created: 31 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
-package org.codelutin.math.matrix;
-
-import junit.framework.TestCase;
-
-/**
- * FIXME comment test since lutinxml is not used any.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class MatrixEncoderDecoderTest extends TestCase { // MatrixEncoderDecoderTest
-
- public void testDummy() {
- // dummy test for hudson compilation work, perhaps remove this class if we put something about XML in TODO
- assertTrue(true);
- }
-
- /*
- * public MatrixFactory getFactory() throws Exception { return
- * MatrixFactory.getInstance(); }
- *
- * protected void subtestEncoderDecoder(MatrixND mat) throws Exception { //
- * encodage en XML String xml = MatrixHelper.encodeToXML(mat); // decodage
- * depuis le XML MatrixND mat2 = MatrixHelper.decodeFromXML(xml); //
- * reencodage de la matrice resultat String xml2 =
- * MatrixHelper.encodeToXML(mat2); // on verifie que les 2 matrices sont
- * egals et leur representation // XML aussi assertEquals(mat, mat2);
- * assertEquals(xml, xml2); }
- *
- * public void testEncoderDecoder() 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"});
- *
- * MatrixND mat = null;
- *
- * mat = getFactory().create("Ma mat", new int[]{3,3,3});
- * subtestEncoderDecoder(mat);
- *
- * mat = getFactory().create("Ma mat", new List[]{s1, s2, s3});
- * subtestEncoderDecoder(mat);
- *
- * // on modifie S1 pour avoir un null au milieu s1.set(1, null); mat =
- * getFactory().create("Ma mat", new List[]{s1, s2, s3}, new
- * String[]{"dim abc", "dim efg", "dim klm"}); mat.setSemantics(1,
- * Collections.nCopies(3, null)); subtestEncoderDecoder(mat); }
- */
-
-} // MatrixEncoderDecoderTest
-
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,17 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixHelperTest.java
+package org.codelutin.math.matrix;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * MatrixHelperTest.
*
* Created: 29 oct. 2004
*
@@ -26,68 +35,71 @@
* Mise a jour: $Date$
* par : $Author$
*/
+public class MatrixHelperTest { // MatrixHelperTest
-package org.codelutin.math.matrix;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class MatrixHelperTest extends TestCase { // MatrixHelperTest
-
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(MatrixHelperTest.class);
+
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance();
}
+ @Test
public void testCoordinatesToString() throws Exception {
- assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 }));
- assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2,
+ Assert.assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 }));
+ Assert.assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2,
3, 4, 5 }));
- assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] {
+ Assert.assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] {
2, 3, 4, 5, 234 }));
- assertEquals("a", MatrixHelper
+ Assert.assertEquals("a", MatrixHelper
.coordinatesToString(new String[] { "a" }));
- assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] {
+ Assert.assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] {
"a", "b", "n", "m" }));
- assertEquals("a,b,f,e,aze",
+ Assert.assertEquals("a,b,f,e,aze",
MatrixHelper.coordinatesToString(new String[] { "a", "b", "f",
"e", "aze" }));
}
+ @Test
public void testSameDimension() throws Exception {
- assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 }));
- assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] {
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 }));
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] {
1, 2 }));
- assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 },
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 },
new int[] { 1, 324, 3 }));
}
+ @Test
public void testDimensionToSemantics() throws Exception {
// TODO faire un test pour dimensionToSemantics
}
+ @Test
public void testSemanticsToDimension() throws Exception {
// TODO faire un test pour semanticsToDimension
}
+ @Test
public void testFill() throws Exception {
MatrixND mat = getFactory().create(new int[] { 3, 3 });
MatrixHelper.fill(mat, 4);
- assertEquals(4, mat.getValue(1, 1), 0);
+ Assert.assertEquals(4, mat.getValue(1, 1), 0);
}
+ @Test
public void testMatrixId() throws Exception {
MatrixND mat = getFactory().matrixId(4);
- assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim()));
- assertEquals(0, mat.getValue(1, 2), 0);
- assertEquals(1, mat.getValue(0, 0), 0);
- assertEquals(1, mat.getValue(1, 1), 0);
- assertEquals(1, mat.getValue(2, 2), 0);
- assertEquals(1, mat.getValue(3, 3), 0);
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim()));
+ Assert.assertEquals(0, mat.getValue(1, 2), 0);
+ Assert.assertEquals(1, mat.getValue(0, 0), 0);
+ Assert.assertEquals(1, mat.getValue(1, 1), 0);
+ Assert.assertEquals(1, mat.getValue(2, 2), 0);
+ Assert.assertEquals(1, mat.getValue(3, 3), 0);
}
+ @Test
public void testToList() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
mat1.setValue(0, 0, 0, -1.0E-7);
@@ -101,49 +113,52 @@
System.out.println(l);
System.out.println(l2);
- assertEquals(l, l2);
+ Assert.assertEquals(l, l2);
}
+ @Test
public void testMaxOccurence() throws Exception {
double[] val = new double[5];
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[2] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[0] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[1] = -1;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[4] = -3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[3] = 3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val = new double[6];
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[2] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[0] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[1] = -1;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[4] = -3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[3] = -3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[5] = -3;
- assertEquals(-3, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-3, MatrixHelper.maxOccurence(val), 0);
val = new double[0];
try {
MatrixHelper.maxOccurence(val);
- assertFalse(true); // on ne passe pas ici
- } catch (IllegalArgumentException eee) {
- assertTrue(true); // on passe ici
+ Assert.fail("AN exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception normally thrown", e);
+ }
}
}
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,17 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * AppTestCase.java
- *
- * Created: 10 mai 2004
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.IOException;
@@ -36,17 +25,28 @@
import java.util.List;
import java.util.Stack;
-import junit.framework.TestCase;
-
import org.apache.commons.lang.time.DurationFormatUtils;
import org.codelutin.util.StringUtil;
+import org.junit.Assert;
+import org.junit.Test;
-public class MatrixNDTest extends TestCase {
+/* *
+ * AppTestCase.java
+ *
+ * Created: 10 mai 2004
+ *
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class MatrixNDTest {
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance(DoubleVector.class);
}
+ @Test
public void testNew() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -60,10 +60,11 @@
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 },
new String[] { "dim abc", "dim efg", "dim klm" });
- assertEquals(0.0, mat.getMaxOccurence());
+ Assert.assertEquals(0.0, mat.getMaxOccurence(), 0);
}
+ @Test
public void testSemantique() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -73,18 +74,19 @@
mat = getFactory().create(new int[] { 3, 3, 3 });
- assertTrue(null == mat.getSemantics(1).get(1));
+ Assert.assertNull(mat.getSemantics(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");
- assertEquals("f", mat.getSemantics(1).get(1));
+ Assert.assertEquals("f", mat.getSemantics(1).get(1));
mat.setSemantics(1, s1);
- assertEquals("b", mat.getSemantics(1).get(1));
+ Assert.assertEquals("b", mat.getSemantics(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" });
@@ -95,15 +97,16 @@
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 },
new String[] { "dim abc", "dim efg", "dim klm" });
- assertEquals("Ma mat", mat.getName());
+ Assert.assertEquals("Ma mat", mat.getName());
mat.setName("Renamed");
- assertEquals("Renamed", mat.getName());
+ Assert.assertEquals("Renamed", mat.getName());
- assertEquals("dim abc", mat.getDimensionName(0));
+ Assert.assertEquals("dim abc", mat.getDimensionName(0));
mat.setDimensionName(0, "dim renamed");
- assertEquals("dim renamed", mat.getDimensionName(0));
+ Assert.assertEquals("dim renamed", mat.getDimensionName(0));
}
+ @Test
public void testGetSet() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -115,12 +118,13 @@
new String[] { "dim abc", "dim efg", "dim klm" });
mat.setValue(1, 1, 1, 34);
- assertEquals(34, mat.getValue("b", "f", "l"), 0);
+ Assert.assertEquals(34, mat.getValue("b", "f", "l"), 0);
mat.setValue("a", "f", "m", 22);
- assertEquals(22, mat.getValue(0, 1, 2), 0);
+ Assert.assertEquals(22, mat.getValue(0, 1, 2), 0);
}
+ @Test
public void testIterator() throws Exception {
int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
{ 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 },
@@ -153,13 +157,15 @@
int cpt = 0;
for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- assertTrue(Arrays.equals(val27[cpt], i.getCoordinates()));
- assertTrue(Arrays.equals(vals27[cpt], i.getSemanticsCoordinates()));
+ Assert.assertTrue(Arrays.equals(val27[cpt], i.getCoordinates()));
+ Assert.assertTrue(Arrays.equals(vals27[cpt], i
+ .getSemanticsCoordinates()));
cpt++;
}
- assertEquals(27, cpt);
+ Assert.assertEquals(27, cpt);
}
+ @Test
public void testAdd() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -177,11 +183,12 @@
mat1.add(mat2);
- assertEquals(29, mat1.getValue(0, 0, 0), 0);
- assertEquals(29, mat1.getValue(1, 2, 0), 0);
- assertEquals(29, mat1.getValue(2, 2, 2), 0);
+ Assert.assertEquals(29, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(29, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(29, mat1.getValue(2, 2, 2), 0);
}
+ @Test
public void testMinus() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -199,11 +206,12 @@
mat1.minus(mat2);
- assertEquals(-23, mat1.getValue(0, 0, 0), 0);
- assertEquals(-23, mat1.getValue(1, 2, 0), 0);
- assertEquals(-23, mat1.getValue(2, 2, 2), 0);
+ Assert.assertEquals(-23, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(-23, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(-23, mat1.getValue(2, 2, 2), 0);
}
+ @Test
public void testEquals() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -225,9 +233,10 @@
mat1.add(mat2);
- assertEquals(mat1, mat3);
+ Assert.assertEquals(mat1, mat3);
}
+ @Test
public void testsumOverDim() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -242,35 +251,35 @@
mi.setValue(++i);
}
- assertEquals(mat, mat2);
+ Assert.assertEquals(mat, mat2);
mat2 = mat.sumOverDim(1, 0);
- assertEquals(mat, mat2);
+ Assert.assertEquals(mat, mat2);
mat2 = mat.sumOverDim(1, 1);
- assertEquals(mat, mat2);
+ Assert.assertEquals(mat, mat2);
mat2 = mat.sumOverDim(1, 2);
- assertEquals(2, mat2.getDim(1));
- assertEquals(3, mat2.getValue(0, 0), 0);
- assertEquals(7, mat2.getValue(0, 1), 0);
- assertEquals(11, mat2.getValue(1, 0), 0);
- assertEquals(15, mat2.getValue(1, 1), 0);
- assertEquals(19, mat2.getValue(2, 0), 0);
- assertEquals(23, mat2.getValue(2, 1), 0);
- assertEquals(27, mat2.getValue(3, 0), 0);
- assertEquals(31, mat2.getValue(3, 1), 0);
+ Assert.assertEquals(2, mat2.getDim(1));
+ Assert.assertEquals(3, mat2.getValue(0, 0), 0);
+ Assert.assertEquals(7, mat2.getValue(0, 1), 0);
+ Assert.assertEquals(11, mat2.getValue(1, 0), 0);
+ Assert.assertEquals(15, mat2.getValue(1, 1), 0);
+ Assert.assertEquals(19, mat2.getValue(2, 0), 0);
+ Assert.assertEquals(23, mat2.getValue(2, 1), 0);
+ Assert.assertEquals(27, mat2.getValue(3, 0), 0);
+ Assert.assertEquals(31, mat2.getValue(3, 1), 0);
mat2 = mat.sumOverDim(1, 3);
- assertEquals(1, mat2.getDim(1));
- assertEquals(6, mat2.getValue(0, 0), 0);
- assertEquals(18, mat2.getValue(1, 0), 0);
- assertEquals(30, mat2.getValue(2, 0), 0);
- assertEquals(42, mat2.getValue(3, 0), 0);
+ Assert.assertEquals(1, mat2.getDim(1));
+ Assert.assertEquals(6, mat2.getValue(0, 0), 0);
+ Assert.assertEquals(18, mat2.getValue(1, 0), 0);
+ Assert.assertEquals(30, mat2.getValue(2, 0), 0);
+ Assert.assertEquals(42, mat2.getValue(3, 0), 0);
mat2 = mat.sumOverDim(1, 4);
- assertEquals(1, mat2.getDim(1));
- assertEquals(10, mat2.getValue(0, 0), 0);
- assertEquals(26, mat2.getValue(1, 0), 0);
- assertEquals(42, mat2.getValue(2, 0), 0);
- assertEquals(58, mat2.getValue(3, 0), 0);
+ Assert.assertEquals(1, mat2.getDim(1));
+ Assert.assertEquals(10, mat2.getValue(0, 0), 0);
+ Assert.assertEquals(26, mat2.getValue(1, 0), 0);
+ Assert.assertEquals(42, mat2.getValue(2, 0), 0);
+ Assert.assertEquals(58, mat2.getValue(3, 0), 0);
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 },
new String[] { "dim abc", "dim efg", "dim klm" });
@@ -279,12 +288,12 @@
mat.setValue(0, 0, 0, 2);
mat.setValue(2, 2, 2, 4);
mat = mat.sumOverDim(1);
- assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat
.getDim()));
- assertEquals(8, mat.getValue(0, 0, 0), 0);
- assertEquals(9, mat.getValue(2, 0, 1), 0);
- assertEquals(10, mat.getValue(2, 0, 2), 0);
+ Assert.assertEquals(8, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(9, mat.getValue(2, 0, 1), 0);
+ Assert.assertEquals(10, mat.getValue(2, 0, 2), 0);
mat = getFactory().create(new int[] { 6, 6, 6 });
@@ -297,14 +306,15 @@
mat.setValue(0, 5, 0, 5);
mat = mat.sumOverDim(1, 3);
- assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat
.getDim()));
- assertEquals(3, mat.getValue(0, 0, 0), 0);
- assertEquals(12, mat.getValue(0, 1, 0), 0);
- assertEquals(9, mat.getValue(1, 1, 5), 0);
- assertEquals(9, mat.getValue(5, 0, 3), 0);
+ Assert.assertEquals(3, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(12, mat.getValue(0, 1, 0), 0);
+ Assert.assertEquals(9, mat.getValue(1, 1, 5), 0);
+ Assert.assertEquals(9, mat.getValue(5, 0, 3), 0);
}
+ @Test
public void testTranspose() throws Exception {
MatrixND mat = null;
@@ -315,10 +325,10 @@
mat.setValue(1, 0, 46);
mat = mat.transpose();
- assertEquals(56, mat.getValue(3, 1), 0);
- assertEquals(34, mat.getValue(2, 0), 0);
- assertEquals(64, mat.getValue(1, 0), 0);
- assertEquals(46, mat.getValue(0, 1), 0);
+ Assert.assertEquals(56, mat.getValue(3, 1), 0);
+ Assert.assertEquals(34, mat.getValue(2, 0), 0);
+ Assert.assertEquals(64, mat.getValue(1, 0), 0);
+ Assert.assertEquals(46, mat.getValue(0, 1), 0);
mat = getFactory().create(new int[] { 4 });
mat.setValue(1, 56);
@@ -327,12 +337,13 @@
mat.setValue(0, 46);
mat = mat.transpose();
- assertEquals(56, mat.getValue(0, 1), 0);
- assertEquals(34, mat.getValue(0, 2), 0);
- assertEquals(64, mat.getValue(0, 3), 0);
- assertEquals(46, mat.getValue(0, 0), 0);
+ Assert.assertEquals(56, mat.getValue(0, 1), 0);
+ Assert.assertEquals(34, mat.getValue(0, 2), 0);
+ Assert.assertEquals(64, mat.getValue(0, 3), 0);
+ Assert.assertEquals(46, mat.getValue(0, 0), 0);
}
+ @Test
public void testMults() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -351,16 +362,17 @@
mat1.mults(3);
mat2.mults(0);
- assertEquals(9, mat1.getValue(0, 0, 0), 0);
- assertEquals(9, mat1.getValue(1, 2, 0), 0);
- assertEquals(0, mat2.getValue(2, 2, 2), 0);
+ Assert.assertEquals(9, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(9, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(0, mat2.getValue(2, 2, 2), 0);
MatrixND mat0 = getFactory().create(new int[] { 4, 4 });
MatrixND matId = getFactory().matrixId(4);
matId.mults(0);
- assertEquals(mat0, matId);
+ Assert.assertEquals(mat0, matId);
}
+ @Test
public void testDivs() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -379,11 +391,12 @@
mat1.divs(3);
mat2.divs(4);
- assertEquals(1, mat1.getValue(0, 0, 0), 0);
- assertEquals(6.5, mat2.getValue(1, 2, 0), 0);
- assertEquals(6.5, mat2.getValue(2, 2, 2), 0);
+ Assert.assertEquals(1, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(6.5, mat2.getValue(1, 2, 0), 0);
+ Assert.assertEquals(6.5, mat2.getValue(2, 2, 2), 0);
}
+ @Test
public void testPaste() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 6, 7, 8 });
@@ -394,12 +407,13 @@
mat1.paste(new int[] { 3, 0, 4 }, mat2);
- assertEquals(3, mat1.getValue(0, 0, 0), 0);
- assertEquals(26, mat1.getValue(3, 0, 4), 0);
- assertEquals(26, mat1.getValue(4, 1, 5), 0);
- assertEquals(3, mat1.getValue(5, 2, 6), 0);
+ Assert.assertEquals(3, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(26, mat1.getValue(3, 0, 4), 0);
+ Assert.assertEquals(26, mat1.getValue(4, 1, 5), 0);
+ Assert.assertEquals(3, mat1.getValue(5, 2, 6), 0);
}
+ @Test
public void testSumOverDim() throws Exception {
MatrixND mat = null;
@@ -425,9 +439,10 @@
mat = mat.sumOverDim(0, 1, 3);
mat = mat.sumOverDim(0, 2, 2);
- assertTrue(result.equalsValues(mat));
+ Assert.assertTrue(result.equalsValues(mat));
}
+ @Test
public void testReduce() throws Exception {
MatrixND mat = null;
@@ -436,25 +451,25 @@
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduce();
- assertEquals(2, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(8, mat.getDim(1));
- assertEquals(21, mat.getValue(0, 0), 0);
- assertEquals(21, mat.getValue(5, 7), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(8, mat.getDim(1));
+ Assert.assertEquals(21, mat.getValue(0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduce();
- assertEquals(1, mat.getNbDim());
- assertEquals(2, mat.getDim(0));
- assertEquals(104, mat.getValue(0), 0);
- assertEquals(104, mat.getValue(1), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(2, mat.getDim(0));
+ Assert.assertEquals(104, mat.getValue(0), 0);
+ Assert.assertEquals(104, mat.getValue(1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -462,36 +477,36 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduce();
- assertEquals(1, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(48, mat.getValue(0), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(48, mat.getValue(0), 0);
mat = getFactory().create(new int[] { 6, 7, 8 });
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduce(2);
- assertEquals(2, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(8, mat.getDim(1));
- assertEquals(21, mat.getValue(0, 0), 0);
- assertEquals(21, mat.getValue(5, 7), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(8, mat.getDim(1));
+ Assert.assertEquals(21, mat.getValue(0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduce(2);
- assertEquals(2, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(2, mat.getDim(1));
- assertEquals(104, mat.getValue(0, 0), 0);
- assertEquals(104, mat.getValue(0, 1), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(2, mat.getDim(1));
+ Assert.assertEquals(104, mat.getValue(0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -499,46 +514,50 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduce(5);
- assertEquals(3, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(1, mat.getDim(1));
- assertEquals(1, mat.getDim(2));
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(3, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(1, mat.getDim(1));
+ Assert.assertEquals(1, mat.getDim(2));
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
}
-
+
+ @Test
public void testCreateFromDoubleArray() throws Exception {
- MatrixND mat = null;
-
- mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8,9}, new int[] {3,3});
-
- assertEquals(2,mat.getDim().length);
- assertEquals(3,mat.getDim(0));
- assertEquals(3,mat.getDim(1));
- assertEquals(1,(int)mat.getValue(new int[] {0,0}));
- assertEquals(2,(int)mat.getValue(new int[] {0,1}));
- assertEquals(3,(int)mat.getValue(new int[] {0,2}));
- assertEquals(4,(int)mat.getValue(new int[] {1,0}));
- assertEquals(5,(int)mat.getValue(new int[] {1,1}));
- assertEquals(6,(int)mat.getValue(new int[] {1,2}));
- assertEquals(7,(int)mat.getValue(new int[] {2,0}));
- assertEquals(8,(int)mat.getValue(new int[] {2,1}));
- assertEquals(9,(int)mat.getValue(new int[] {2,2}));
-
- mat = getFactory().create(new double[] {1,2,3}, new int[]{3});
- assertEquals(1,mat.getDim().length);
- assertEquals(3,mat.getDim(0));
- assertEquals(1,(int)mat.getValue(new int[] {0}));
- assertEquals(2,(int)mat.getValue(new int[] {1}));
- assertEquals(3,(int)mat.getValue(new int[] {2}));
-
- mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8}, new int[] {2,2,2});
- assertNull(mat);
-
+ MatrixND mat = null;
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+ new int[] { 3, 3 });
+
+ Assert.assertEquals(2, mat.getDim().length);
+ Assert.assertEquals(3, mat.getDim(0));
+ Assert.assertEquals(3, mat.getDim(1));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 0, 2 }));
+ Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 0 }));
+ Assert.assertEquals(5, (int) mat.getValue(new int[] { 1, 1 }));
+ Assert.assertEquals(6, (int) mat.getValue(new int[] { 1, 2 }));
+ Assert.assertEquals(7, (int) mat.getValue(new int[] { 2, 0 }));
+ Assert.assertEquals(8, (int) mat.getValue(new int[] { 2, 1 }));
+ Assert.assertEquals(9, (int) mat.getValue(new int[] { 2, 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3 }, new int[] { 3 });
+ Assert.assertEquals(1, mat.getDim().length);
+ Assert.assertEquals(3, mat.getDim(0));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8 },
+ new int[] { 2, 2, 2 });
+ Assert.assertNull(mat);
+
}
+ @Test
public void testReduceDims() throws Exception {
MatrixND mat = null;
@@ -547,25 +566,25 @@
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1);
- assertEquals(2, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(8, mat.getDim(1));
- assertEquals(21, mat.getValue(0, 0), 0);
- assertEquals(21, mat.getValue(5, 7), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(8, mat.getDim(1));
+ Assert.assertEquals(21, mat.getValue(0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1, 0);
- assertEquals(1, mat.getNbDim());
- assertEquals(2, mat.getDim(0));
- assertEquals(104, mat.getValue(0), 0);
- assertEquals(104, mat.getValue(1), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(2, mat.getDim(0));
+ Assert.assertEquals(104, mat.getValue(0), 0);
+ Assert.assertEquals(104, mat.getValue(1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -573,37 +592,37 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1, 2, 0);
- assertEquals(1, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(48, mat.getValue(0), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(48, mat.getValue(0), 0);
mat = getFactory().create(new int[] { 6, 7, 8 });
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(0);
- assertEquals(3, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(1, mat.getDim(1));
- assertEquals(8, mat.getDim(2));
- assertEquals(21, mat.getValue(0, 0, 0), 0);
- assertEquals(21, mat.getValue(5, 0, 7), 0);
+ Assert.assertEquals(3, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(1, mat.getDim(1));
+ Assert.assertEquals(8, mat.getDim(2));
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 0, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1);
- assertEquals(2, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(2, mat.getDim(1));
- assertEquals(104, mat.getValue(0, 0), 0);
- assertEquals(104, mat.getValue(0, 1), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(2, mat.getDim(1));
+ Assert.assertEquals(104, mat.getValue(0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -611,14 +630,15 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(0, 1, 2);
- assertEquals(1, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(48, mat.getValue(0), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(48, mat.getValue(0), 0);
}
+ @Test
public void testToList() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
mat1.setValue(0, 0, 0, 1.0E-7);
@@ -633,7 +653,7 @@
System.out.println(mat1);
System.out.println(mat2);
- assertEquals(mat1, mat2);
+ Assert.assertEquals(mat1, mat2);
String s = String.valueOf(l);
List l2 = convertStringToList2(s);
@@ -645,7 +665,7 @@
System.out.println(l1);
System.out.println(l0); // implatation fausse
- assertEquals(l, l2);
+ Assert.assertEquals(l, l2);
int MAX = 10000;
int dummy = 0;
@@ -677,7 +697,7 @@
/**
* implantation peut performante
*/
- static public List convertStringToList1(String s) {
+ public static List convertStringToList1(String s) {
List result = new ArrayList();
s = s.trim();
if (s.startsWith("[") && s.endsWith("]")) {
@@ -701,7 +721,7 @@
/**
* implantation utilisé actuellement dans MatrixHelper
*/
- static public List convertStringToList2(String s) {
+ public static List convertStringToList2(String s) {
List result = null;
Stack<List> stack = new Stack<List>();
StringBuffer number = new StringBuffer(20); // initial to 20 char
@@ -749,7 +769,7 @@
/**
* implantation fausse pour les nombres 5.0E-7
*/
- static public List convertStringToList0(String s) 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
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,7 +15,15 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
+package org.codelutin.math.matrix;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.junit.Test;
+
+/**
* PerfTest.java
*
* Created: 7 sept. 06 02:28:51
@@ -26,26 +34,12 @@
* Last update: $Date$
* by : $Author$
*/
+public class PerfTest {
-package org.codelutin.math.matrix;
+ protected static final char CMAX = 'j';
+ protected static final int MAX = 10;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-
-/**
- * @author poussin
- *
- */
-
-public class PerfTest extends TestCase {
-
- static char CMAX = 'j';
- static int MAX = 10;
-
+ @Test
public void testDoubleVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -77,6 +71,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -112,6 +107,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
@@ -150,6 +146,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleBigVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -181,6 +178,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleBigVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -216,6 +214,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleBigVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
@@ -254,6 +253,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -285,6 +285,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -320,6 +321,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
@@ -358,6 +360,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatBigVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -389,6 +392,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatBigVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -424,6 +428,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatBigVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -20,25 +20,27 @@
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
/**
- * SubMatrixTest.java
+ * SubMatrixTest.
*
* Created: 29 oct. 2004
*
* @author Benjamin Poussin <poussin(a)codelutin.com>
* @version $Revision$
*
- * Mise a jour: $Date$
- * par : $Author$
+ * Mise a jour: $Date$
+ * par : $Author$
*/
-public class SubMatrixTest extends TestCase { // SubMatrixTest
+public class SubMatrixTest { // SubMatrixTest
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance();
}
+ @Test
public void testNew() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -50,9 +52,10 @@
new String[] { "dim abc", "dim efg", "dim klm" });
MatrixND smat = mat.getSubMatrix(1, 0, 2);
- assertTrue(Arrays.equals(new int[] { 3, 2, 3 }, smat.getDim()));
+ Assert.assertTrue(Arrays.equals(new int[] { 3, 2, 3 }, smat.getDim()));
}
+ @Test
public void testIterator() throws Exception {
int[][] val18 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
{ 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 1, 0, 0 },
@@ -90,13 +93,14 @@
// System.out.println(MatrixHelper.coordinatesToString(i.
// getSemanticsCoordinates()));
- assertTrue(Arrays.equals(val18[cpt], i.getCoordinates()));
- assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates()));
+ Assert.assertTrue(Arrays.equals(val18[cpt], i.getCoordinates()));
+ Assert.assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates()));
cpt++;
}
- assertEquals(18, cpt);
+ Assert.assertEquals(18, cpt);
}
+ @Test
public void testSubSubMatrix() throws Exception {
int[][] val6 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
{ 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, };
@@ -119,7 +123,7 @@
//System.out.println(" smat2.getDim: "+MatrixHelper.coordinatesToString(
// smat2.getDim()));
- assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim()));
+ Assert.assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim()));
// System.out.println(MatrixHelper.coordinatesToString(smat2.getDim()));
@@ -127,13 +131,14 @@
for (MatrixIterator i = smat2.iterator(); i.hasNext();) {
i.next();
- assertTrue(Arrays.equals(val6[cpt], i.getCoordinates()));
- assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates()));
+ Assert.assertTrue(Arrays.equals(val6[cpt], i.getCoordinates()));
+ Assert.assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates()));
cpt++;
}
- assertEquals(6, cpt);
+ Assert.assertEquals(6, cpt);
}
+ @Test
public void testSubSubGetSet() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -148,11 +153,12 @@
MatrixND smat2 = smat1.getSubMatrix(0, 2, 1);
smat2.setValue(0, 0, 0, 34);
- assertEquals(34, smat2.getValue("c", "e", "k"), 0);
+ Assert.assertEquals(34, smat2.getValue("c", "e", "k"), 0);
smat2.setValue("c", "f", "l", 23);
- assertEquals(23, smat2.getValue(0, 1, 1), 0);
+ Assert.assertEquals(23, smat2.getValue(0, 1, 1), 0);
}
+ @Test
public void testSubMapping() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -164,29 +170,30 @@
new String[] { "dim abc", "dim efg", "dim klm" });
MatrixND smat1 = mat.getSubMatrix(1, new int[] { 0, 1 });
- assertEquals(2, smat1.getDim(1));
- assertEquals(Arrays.asList(new String[] { "e", "f" }), smat1
+ Assert.assertEquals(2, smat1.getDim(1));
+ Assert.assertEquals(Arrays.asList(new String[] { "e", "f" }), smat1
.getSemantics(1));
MatrixND smat2 = smat1.getSubMatrix(0, new Object[] { "c" });
- assertEquals(1, smat2.getDim(0));
- assertEquals(Arrays.asList(new String[] { "c" }), smat2.getSemantics(0));
+ Assert.assertEquals(1, smat2.getDim(0));
+ Assert.assertEquals(Arrays.asList(new String[] { "c" }), smat2.getSemantics(0));
mat.setValue("c", "f", "k", 12);
- assertEquals(12, smat1.getValue(2, 1, 0), 0);
- assertEquals(12, smat1.getValue("c", "f", "k"), 0);
- assertEquals(12, smat2.getValue(0, 1, 0), 0);
- assertEquals(12, smat2.getValue("c", "f", "k"), 0);
+ Assert.assertEquals(12, smat1.getValue(2, 1, 0), 0);
+ Assert.assertEquals(12, smat1.getValue("c", "f", "k"), 0);
+ Assert.assertEquals(12, smat2.getValue(0, 1, 0), 0);
+ Assert.assertEquals(12, smat2.getValue("c", "f", "k"), 0);
smat2.setValue(0, 0, 0, 34);
- assertEquals(34, smat2.getValue("c", "e", "k"), 0);
- assertEquals(34, mat.getValue(2, 0, 0), 0);
- assertEquals(34, mat.getValue("c", "e", "k"), 0);
+ Assert.assertEquals(34, smat2.getValue("c", "e", "k"), 0);
+ Assert.assertEquals(34, mat.getValue(2, 0, 0), 0);
+ Assert.assertEquals(34, mat.getValue("c", "e", "k"), 0);
smat2.setValue("c", "f", "l", 23);
- assertEquals(23, smat2.getValue(0, 1, 1), 0);
- assertEquals(23, mat.getValue(2, 1, 1), 0);
- assertEquals(23, mat.getValue("c", "f", "l"), 0);
+ Assert.assertEquals(23, smat2.getValue(0, 1, 1), 0);
+ Assert.assertEquals(23, mat.getValue(2, 1, 1), 0);
+ Assert.assertEquals(23, mat.getValue("c", "f", "l"), 0);
}
+ @Test
public void testSubAdd() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -208,37 +215,38 @@
smat1.add(smat2);
- assertEquals(5, mat1.getValue(0, 1, 0), 0);
- assertEquals(5, mat1.getValue(0, 1, 1), 0);
- assertEquals(5, mat1.getValue(0, 1, 2), 0);
- assertEquals(5, mat1.getValue(1, 1, 0), 0);
- assertEquals(5, mat1.getValue(1, 1, 1), 0);
- assertEquals(5, mat1.getValue(1, 1, 2), 0);
- assertEquals(5, mat1.getValue(2, 1, 0), 0);
- assertEquals(5, mat1.getValue(2, 1, 1), 0);
- assertEquals(5, mat1.getValue(2, 1, 2), 0);
- assertEquals(5, mat1.getValue(0, 2, 0), 0);
- assertEquals(5, mat1.getValue(0, 2, 1), 0);
- assertEquals(5, mat1.getValue(0, 2, 2), 0);
- assertEquals(5, mat1.getValue(1, 2, 0), 0);
- assertEquals(5, mat1.getValue(1, 2, 1), 0);
- assertEquals(5, mat1.getValue(1, 2, 2), 0);
- assertEquals(5, mat1.getValue(2, 2, 0), 0);
- assertEquals(5, mat1.getValue(2, 2, 1), 0);
- assertEquals(5, mat1.getValue(2, 2, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 1, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 1, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 1, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 1, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 1, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 1, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 1, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 1, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 1, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 2, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 2, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 2, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 2, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 2, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 2, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 2, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 2, 2), 0);
- assertEquals(8, mat1.getValue(0, 0, 0), 0);
- assertEquals(8, mat1.getValue(0, 0, 1), 0);
- assertEquals(8, mat1.getValue(0, 0, 2), 0);
- assertEquals(8, mat1.getValue(1, 0, 0), 0);
- assertEquals(8, mat1.getValue(1, 0, 1), 0);
- assertEquals(8, mat1.getValue(1, 0, 2), 0);
- assertEquals(8, mat1.getValue(2, 0, 0), 0);
- assertEquals(8, mat1.getValue(2, 0, 1), 0);
- assertEquals(8, mat1.getValue(2, 0, 2), 0);
+ Assert.assertEquals(8, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(8, mat1.getValue(0, 0, 1), 0);
+ Assert.assertEquals(8, mat1.getValue(0, 0, 2), 0);
+ Assert.assertEquals(8, mat1.getValue(1, 0, 0), 0);
+ Assert.assertEquals(8, mat1.getValue(1, 0, 1), 0);
+ Assert.assertEquals(8, mat1.getValue(1, 0, 2), 0);
+ Assert.assertEquals(8, mat1.getValue(2, 0, 0), 0);
+ Assert.assertEquals(8, mat1.getValue(2, 0, 1), 0);
+ Assert.assertEquals(8, mat1.getValue(2, 0, 2), 0);
}
+ @Test
public void testSubSubMults() throws Exception {
MatrixND mat = null;
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,42 +15,38 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModelND.java
- *
- * Created: 21 mars 2006 19:05:06
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
-
import org.codelutin.math.matrix.MatrixFactory;
import org.codelutin.math.matrix.MatrixND;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
+ * MatrixTableModelND.
+ *
+ * Created: 21 mars 2006 19:05:06
+ *
* @author poussin
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
+public class MatrixTableModelTest {
-public class MatrixTableModelTest extends TestCase {
+ protected MatrixTableModelND model = null;
+ protected MatrixND mat = null;
- MatrixTableModelND model = null;
- MatrixND mat = null;
-
/*
* @see TestCase#setUp()
*/
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
List dim0 = Arrays.asList(new String[] { "dim0-0", "dim0-1", "dim0-2",
"dim0-3" });
List dim1 = Arrays.asList(new String[] { "dim1-0", "dim1-1" });
@@ -65,70 +61,76 @@
model = new MatrixTableModelND(mat);
}
+ @Test
public void testSetMatrix() {
- assertEquals(2, model.addRow);
- assertEquals(3, model.addCol);
+ Assert.assertEquals(2, model.addRow);
+ Assert.assertEquals(3, model.addCol);
int[] val = model.multRowCol;
- assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 },
+ val));
}
/*
- * Test method for
- * 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int,
- * int)'
+ * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int, int)'
*/
+ @Test
public void testIsCellEditable() {
- assertEquals(false, model.isCellEditable(model.addRow - 1,
+ Assert.assertEquals(false, model.isCellEditable(model.addRow - 1,
model.addCol - 1));
- assertEquals(true, model.isCellEditable(model.addRow, model.addCol));
- assertEquals(true, model.isCellEditable(model.addRow + 1,
+ Assert.assertEquals(true, model.isCellEditable(model.addRow,
+ model.addCol));
+ Assert.assertEquals(true, model.isCellEditable(model.addRow + 1,
model.addCol + 1));
}
/*
- * Test method for
- * 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int,
- * int)'
+ * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int, int)'
*/
+ @Test
public void testTableToMatrix() {
int[] val = model.tableToMatrix(5, 4);
- assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 },
+ val));
val = model.tableToMatrix(0, 0);
- assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 },
+ val));
val = model.tableToMatrix(23, 5);
- assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 },
+ val));
}
/*
- * Test method for
- * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)'
+ * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)'
*/
+ @Test
public void testGetValue() {
- assertEquals("dim0-0", model.getValue(2, 0));
- assertEquals("dim0-0", model.getValue(3, 0));
- assertEquals("dim0-0", model.getValue(4, 0));
- assertEquals("dim0-0", model.getValue(7, 0));
- assertEquals("dim0-1", model.getValue(8, 0));
+ Assert.assertEquals("dim0-0", model.getValue(2, 0));
+ Assert.assertEquals("dim0-0", model.getValue(3, 0));
+ Assert.assertEquals("dim0-0", model.getValue(4, 0));
+ Assert.assertEquals("dim0-0", model.getValue(7, 0));
+ Assert.assertEquals("dim0-1", model.getValue(8, 0));
- assertEquals("dim2-0", model.getValue(2, 1));
- assertEquals("dim2-0", model.getValue(3, 1));
- assertEquals("dim2-1", model.getValue(5, 1));
+ Assert.assertEquals("dim2-0", model.getValue(2, 1));
+ Assert.assertEquals("dim2-0", model.getValue(3, 1));
+ Assert.assertEquals("dim2-1", model.getValue(5, 1));
- assertEquals("dim4-0", model.getValue(2, 2));
- assertEquals("dim4-1", model.getValue(3, 2));
- assertEquals("dim4-2", model.getValue(4, 2));
- assertEquals("dim4-0", model.getValue(5, 2));
+ Assert.assertEquals("dim4-0", model.getValue(2, 2));
+ Assert.assertEquals("dim4-1", model.getValue(3, 2));
+ Assert.assertEquals("dim4-2", model.getValue(4, 2));
+ Assert.assertEquals("dim4-0", model.getValue(5, 2));
- assertEquals("dim1-0", model.getValue(0, 3));
+ Assert.assertEquals("dim1-0", model.getValue(0, 3));
- assertEquals(0.0, model.getValue(model.addRow, model.addCol));
- assertEquals(0.0, model.getValue(23 + model.addRow, 5 + model.addCol));
+ Assert.assertEquals(0.0, model.getValue(model.addRow, model.addCol));
+ Assert.assertEquals(0.0, model.getValue(23 + model.addRow,
+ 5 + model.addCol));
}
/*
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnName(int)'
*/
+ @Test
public void testGetColumnNameInt() {
}
@@ -137,6 +139,7 @@
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getRowCount()'
*/
+ @Test
public void testGetRowCount() {
}
@@ -145,6 +148,7 @@
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnCount()'
*/
+ @Test
public void testGetColumnCount() {
}
@@ -153,6 +157,7 @@
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValueAt(int, int)'
*/
+ @Test
public void testGetValueAt() {
}
@@ -162,6 +167,7 @@
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.setValueAt(Object, int,
* int)'
*/
+ @Test
public void testSetValueAtObjectIntInt() {
}
Added: lutinmatrix/trunk/src/test/resources/log4j.properties
===================================================================
--- lutinmatrix/trunk/src/test/resources/log4j.properties (rev 0)
+++ lutinmatrix/trunk/src/test/resources/log4j.properties 2009-03-03 10:19:18 UTC (rev 120)
@@ -0,0 +1,10 @@
+# Global logging configuration
+log4j.rootLogger=ERROR, stdout
+
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+
+# package level
+log4j.logger.org.codelutin.math=DEBUG
\ No newline at end of file
1
0
[Lutinmatrix-commits] r119 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by jcouteau@users.labs.libre-entreprise.org March 3, 2009
by jcouteau@users.labs.libre-entreprise.org March 3, 2009
March 3, 2009
Author: jcouteau
Date: 2009-03-03 09:07:38 +0000 (Tue, 03 Mar 2009)
New Revision: 119
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
Log:
Adding a create(double[],int[]) method for 1D and 2D matrices.
Adding tests accordingly.
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-02-23 08:48:20 UTC (rev 118)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 09:07:38 UTC (rev 119)
@@ -45,150 +45,186 @@
*/
public class MatrixFactory { // MatrixFactory
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(MatrixFactory.class);
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(MatrixFactory.class);
- static {
- // on essai d'enregistrer le converter XML
- try {
- // Il faut le faire par pur introspection sinon l'exception
- // NoClassDefFoundError est levé avant d'entrer dans le constructeur
- // static :(
- Class converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
- Object converter = converterClass.newInstance();
+ static {
+ // on essai d'enregistrer le converter XML
+ try {
+ // Il faut le faire par pur introspection sinon l'exception
+ // NoClassDefFoundError est levé avant d'entrer dans le constructeur
+ // static :(
+ Class converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
+ Object converter = converterClass.newInstance();
- Class converterFactoryClass = Class
- .forName("org.codelutin.xml.XMLConverterFactory");
- Method m = converterFactoryClass.getMethod("addConverter",
- Class.class, Class
- .forName("org.codelutin.xml.XMLConverter"));
- m.invoke(null, MatrixND.class, converter);
+ Class converterFactoryClass = Class
+ .forName("org.codelutin.xml.XMLConverterFactory");
+ Method m = converterFactoryClass.getMethod("addConverter",
+ Class.class, Class
+ .forName("org.codelutin.xml.XMLConverter"));
+ m.invoke(null, MatrixND.class, converter);
- //org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
- // new MatrixNDXMLConverter());
- log.info("Converter XML pour MatrixND ajoute");
+ // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
+ // new MatrixNDXMLConverter());
+ log.info("Converter XML pour MatrixND ajoute");
- // on essai d'enregistrer le converter JDBC
- // le JDBC depend du XML
- try {
- converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
- converter = converterClass.newInstance();
+ // on essai d'enregistrer le converter JDBC
+ // le JDBC depend du XML
+ try {
+ converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
+ converter = converterClass.newInstance();
- converterFactoryClass = Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- m = converterFactoryClass
- .getMethod(
- "addConverter",
- Class.class,
- Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- m.invoke(null, MatrixND.class, converter);
+ converterFactoryClass = Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ m = converterFactoryClass
+ .getMethod(
+ "addConverter",
+ Class.class,
+ Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ m.invoke(null, MatrixND.class, converter);
- // Class converterClass =
- // org.codelutin.math.matrix.MatrixNDJDBCConverter();
- // JDBCTransformerFactory
- // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
- log.info("Converter JDBC pour MatrixND ajoute");
- } catch (Throwable eee) {
- log
- .info("librairie topia non presente. Import/Export JDBC impossible");
- log.debug("L'exception etait", eee);
- }
+ // Class converterClass =
+ // org.codelutin.math.matrix.MatrixNDJDBCConverter();
+ // JDBCTransformerFactory
+ // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
+ log.info("Converter JDBC pour MatrixND ajoute");
+ } catch (Throwable eee) {
+ log
+ .info("librairie topia non presente. Import/Export JDBC impossible");
+ log.debug("L'exception etait", eee);
+ }
- } catch (Throwable eee) {
- log
- .info("librairie lutinxml non presente. Import/Export XML impossible");
- log.debug("L'exception etait", eee);
- }
+ } catch (Throwable eee) {
+ log
+ .info("librairie lutinxml non presente. Import/Export XML impossible");
+ log.debug("L'exception etait", eee);
+ }
- }
+ }
- /** Valeur par defaut si aucun type de Vector n'est donné */
- static protected Class defaultVectorClass = DoubleBigVector.class;
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ static protected Class defaultVectorClass = DoubleBigVector.class;
- protected Class vectorClass = null;
+ protected Class vectorClass = null;
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- static public void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ static public void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- static public Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ static public Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- static public MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ static public MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- static public MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ static public MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
+ /**
+ *
+ * @param values
+ * The values to fill the matrix
+ * @param dim
+ * An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more
+ * than 2
+ */
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
+ public MatrixND create(double[] values, int[] dim) {
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = {i,j};
+ matrix.setValue(coordinates, values[i * dim[0] + j]);
+ }
+ }
+ }
+ if (dim.length == 1){
+ for (int i=0;i<dim[0];i++) {
+ int[] coordinates = {i};
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
+ return matrix;
+ }
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
+
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
+
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
+
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size
+ * la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
+
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
+
} // MatrixFactory
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-02-23 08:48:20 UTC (rev 118)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 09:07:38 UTC (rev 119)
@@ -508,6 +508,36 @@
assertEquals(48, mat.getValue(0, 0, 0), 0);
}
+
+ public void testCreateFromDoubleArray() throws Exception {
+ MatrixND mat = null;
+
+ mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8,9}, new int[] {3,3});
+
+ assertEquals(2,mat.getDim().length);
+ assertEquals(3,mat.getDim(0));
+ assertEquals(3,mat.getDim(1));
+ assertEquals(1,(int)mat.getValue(new int[] {0,0}));
+ assertEquals(2,(int)mat.getValue(new int[] {0,1}));
+ assertEquals(3,(int)mat.getValue(new int[] {0,2}));
+ assertEquals(4,(int)mat.getValue(new int[] {1,0}));
+ assertEquals(5,(int)mat.getValue(new int[] {1,1}));
+ assertEquals(6,(int)mat.getValue(new int[] {1,2}));
+ assertEquals(7,(int)mat.getValue(new int[] {2,0}));
+ assertEquals(8,(int)mat.getValue(new int[] {2,1}));
+ assertEquals(9,(int)mat.getValue(new int[] {2,2}));
+
+ mat = getFactory().create(new double[] {1,2,3}, new int[]{3});
+ assertEquals(1,mat.getDim().length);
+ assertEquals(3,mat.getDim(0));
+ assertEquals(1,(int)mat.getValue(new int[] {0}));
+ assertEquals(2,(int)mat.getValue(new int[] {1}));
+ assertEquals(3,(int)mat.getValue(new int[] {2}));
+
+ mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8}, new int[] {2,2,2});
+ assertNull(mat);
+
+ }
public void testReduceDims() throws Exception {
1
0