|
From: <de...@us...> - 2009-06-01 22:32:13
|
Revision: 4828
http://fudaa.svn.sourceforge.net/fudaa/?rev=4828&view=rev
Author: deniger
Date: 2009-06-01 22:32:04 +0000 (Mon, 01 Jun 2009)
Log Message:
-----------
Modified Paths:
--------------
trunk/soft/fudaa-crue/dodico/.classpath
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluAnalyze.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluDefaultLogFormatter.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueHelper.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueXmlReaderWriterImpl.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/ErrorHandlerDefault.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPointFF.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPtProfil.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBReader.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBSequentialReader.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/STRSequentialReader.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/metier/emh/PtEvolutionFF.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/metier/emh/PtProfil.java
trunk/soft/fudaa-crue/dodico/src/main/resources/org/fudaa/dodico/crue/io/adrienMessages.properties
trunk/soft/fudaa-crue/dodico/src/main/resources/org/fudaa/dodico/crue/io/caroleMessages.properties
trunk/soft/fudaa-crue/dodico/src/main/resources/org/fudaa/dodico/crue/io/messages.properties
trunk/soft/fudaa-crue/dodico/src/main/resources/xsd/common-1.0.0.xsd
trunk/soft/fudaa-crue/dodico/src/main/resources/xsd/etu-1.0.0.xsd
trunk/soft/fudaa-crue/dodico/src/test/java/org/fudaa/dodico/crue/io/AbstractIOTestCase.java
trunk/soft/fudaa-crue/dodico/src/test/java/org/fudaa/dodico/crue/io/TestCrueFCB.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/builder/CrueScenarioBuilder.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/common/CrueCommomImplementation.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/explorer/CrueApplicationManager.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/explorer/CrueExplorer.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/explorer/CrueSupervisorImplementation.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/projet/CrueProjet.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/projet/ScenarioLoader.java
trunk/soft/fudaa-crue/fudaa/src/main/java/org/fudaa/fudaa/crue/view/CrueErrorManager.java
Added Paths:
-----------
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/AbstractSingleConverterPoint.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBValueObject.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/metier/emh/Point2D.java
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/validation/ValidationFichierScenario.java
trunk/soft/fudaa-crue/planning/Thumbs.db
Removed Paths:
-------------
trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/metier/emh/PtEvolutionDF.java
Modified: trunk/soft/fudaa-crue/dodico/.classpath
===================================================================
--- trunk/soft/fudaa-crue/dodico/.classpath 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/.classpath 2009-06-01 22:32:04 UTC (rev 4828)
@@ -10,8 +10,8 @@
<classpathentry exported="true" kind="lib" path="lib/trove.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xstream-1.3.jar" sourcepath="lib/xstream-distribution-1.3.1-src.zip"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="lib/commons-lang-2.4.jar" sourcepath="lib/commons-lang-2.4-sources.jar"/>
- <classpathentry kind="lib" path="lib/commons-beanutils-core-1.8.0.jar" sourcepath="lib/commons-beanutils-1.8.0-sources.jar"/>
- <classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar" sourcepath="lib/commons-collections-3.2.1-sources.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-lang-2.4.jar" sourcepath="lib/commons-lang-2.4-sources.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-beanutils-core-1.8.0.jar" sourcepath="lib/commons-beanutils-1.8.0-sources.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-collections-3.2.1.jar" sourcepath="lib/commons-collections-3.2.1-sources.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluAnalyze.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluAnalyze.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluAnalyze.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -106,7 +106,14 @@
* @param i le numero de ligne de l'erreur
*/
public void addErrorFromFile(final String msg, final int i, Object... data) {
- addRecord(Level.SEVERE, msg, i, data);
+ if (data == null) {
+ addRecord(Level.SEVERE, msg, i);
+ } else {
+ Object[] all = new Object[data.length + 1];
+ System.arraycopy(data, 0, all, 1, data.length);
+ all[0] = i;
+ addRecord(Level.SEVERE, msg, all);
+ }
}
/**
@@ -115,7 +122,7 @@
* @param reader le reader occasionnant l'erreur
*/
public void addErrorFromFile(final String msg, final LineNumberReader reader, Object... data) {
- addRecord(Level.SEVERE, msg, reader.getLineNumber(), data);
+ addErrorFromFile(msg, reader.getLineNumber(), data);
}
/**
@@ -358,7 +365,7 @@
* @param msg le message
*/
public void manageException(final Exception _e, final String msg) {
- addRecord(Level.SEVERE, msg).setThrown(_e);
+ addRecord(Level.SEVERE, msg, _e.getMessage()).setThrown(_e);
}
/**
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluDefaultLogFormatter.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluDefaultLogFormatter.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/ctulu/CtuluDefaultLogFormatter.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -4,7 +4,9 @@
*/
package org.fudaa.ctulu;
+import java.text.MessageFormat;
import java.util.Collection;
+import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
@@ -18,6 +20,17 @@
*/
public final class CtuluDefaultLogFormatter extends SimpleFormatter {
+ Date dat = new Date();
+ private final static String format = "{0,date} {0,time}";
+ private MessageFormat formatter;
+
+ private final Object args[] = new Object[1];
+
+ // Line separator string. This is the value of the line.separator
+ // property at the moment that the SimpleFormatter was created.
+ private final String lineSeparator = (String) java.security.AccessController
+ .doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
+
/**
* Formateur par defaut pour les logs
*/
@@ -61,6 +74,38 @@
}
@Override
+ public synchronized String format(LogRecord record) {
+ StringBuilder sb = new StringBuilder(256);
+ // Minimize memory allocations here.
+ // dat.setTime(record.getMillis());
+ // args[0] = dat;
+ // if (formatter == null) {
+ // formatter = new MessageFormat(format);
+ // }
+
+ sb.append(record.getLevel().getLocalizedName());
+ sb.append(": ");
+ // StringBuffer text = new StringBuffer();
+ // formatter.format(args, text, null);
+ // sb.append(" ");
+ sb.append(formatMessage(record));
+ // sb.append(": ");
+ // sb.append(text);
+
+ // sb.append(lineSeparator);
+ // if (record.getThrown() != null) {
+ // try {
+ // StringWriter sw = new StringWriter();
+ // PrintWriter pw = new PrintWriter(sw);
+ // record.getThrown().printStackTrace(pw);
+ // pw.close();
+ // sb.append(sw.toString());
+ // } catch (Exception ex) {}
+ // }
+ return sb.toString();
+ }
+
+ @Override
public synchronized String formatMessage(final LogRecord record) {
String format = record.getMessage();
final java.util.ResourceBundle catalog = record.getResourceBundle();
Added: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/AbstractSingleConverterPoint.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/AbstractSingleConverterPoint.java (rev 0)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/AbstractSingleConverterPoint.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -0,0 +1,61 @@
+/**
+ * Licence GPL
+ * Copyright Genesis
+ */
+package org.fudaa.dodico.crue.io.dao;
+
+import org.apache.commons.lang.StringUtils;
+import org.fudaa.ctulu.CtuluLibString;
+import org.fudaa.dodico.crue.io.common.AbstractSingleConverter;
+import org.fudaa.dodico.crue.metier.emh.Point2D;
+
+// TODO pour Fred : cette classe est similaire à SingleConverterPtProfil (seuls les objets métier utilisés sont différents). Ne pourrait-on pas mutualiser l'analyse et l'affichage du point FF ?
+/**
+ * @author deniger
+ */
+public abstract class AbstractSingleConverterPoint extends AbstractSingleConverter {
+
+ final Class clazz;
+
+ /**
+ * @param clazz la classe acceptee par ce converter
+ */
+ public AbstractSingleConverterPoint(final Class clazz) {
+ super();
+ this.clazz = clazz;
+ }
+
+ protected abstract Object createFor(double x, double y);
+
+ public boolean canConvert(final Class type) {
+ return clazz.equals(type);
+ }
+
+ public Object fromString(final String str) {
+ if (CtuluLibString.isEmpty(str)) { return null; }
+ final String[] xy = StringUtils.split(str);
+ if (xy == null || xy.length != 2) {
+ if (analyse != null) {
+ analyse.addError("io.convert.PtEvolutionFF.error", str);
+ }
+ return null;
+ }
+ Object res = null;
+ try {
+ res = createFor(Double.parseDouble(xy[0]), Double.parseDouble(xy[1]));
+ } catch (final NumberFormatException e) {
+ if (analyse != null) {
+ analyse.addError("io.convert.PtEvolutionFF.error", str);
+ }
+ return null;
+ }
+ return res;
+ }
+
+ public String toString(final Object obj) {
+ if (obj == null) { return CtuluLibString.EMPTY_STRING; }
+ final Point2D in = (Point2D) obj;
+ return in.getAbscisse() + " " + in.getOrdonnee();
+ }
+
+}
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueHelper.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueHelper.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueHelper.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -49,37 +49,8 @@
public final static String RPTI = "RPTI"; //$NON-NLS-1$
public final static String RCAL = "RCAL"; //$NON-NLS-1$
- // /**
- // * Construit un ptProfil a partir d'une chaine de caracteres. Utilisé pour DPTG
- // *
- // * @param buff
- // * @param listeMessageError
- // * @param nameError
- // * @return
- // */
- // public static PtProfil createFormString(final StringBuffer buff, final CtuluAnalyze analyser, final String
- // nameError) {
- // final int indiceCesure = buff.lastIndexOf(" "); //$NON-NLS-1$
- // final String val1 = buff.substring(0, indiceCesure);
- // final String val2 = buff.substring(indiceCesure + 1, buff.length());
- // double x = 0;
- // try {
- // x = Double.parseDouble(val1);
- //
- // } catch (final NumberFormatException e) {
- // addWarn("io.ptProfil.x.error", nameError, buff, analyser); //$NON-NLS-1$
- // }
- // double y = 0;
- // try {
- // y = Double.parseDouble(val2);
- // } catch (final NumberFormatException e) {
- // addWarn("io.ptProfil.y.error", nameError, buff, analyser); //$NON-NLS-1$
- // }
- //
- // final PtProfil profil = new PtProfil(x, y);
- // return profil;
- // }
+
/**
* Compare l'égalité de 2 pt profils
*
@@ -92,106 +63,7 @@
}
- // public static PtEvolutionFF createPtEvolutionFFfromString(final String buff, final CtuluAnalyze analyser,
- // final String nomEMH) {
- // final int indiceCesure = buff.lastIndexOf(" "); //$NON-NLS-1$
- // final String val1 = buff.substring(0, indiceCesure);
- // final String val2 = buff.substring(indiceCesure + 1, buff.length());
- // double x = 0;
- // try {
- // x = Double.parseDouble(val1);
- //
- // } catch (final NumberFormatException e) {
- // addWarn("io.ptEvolutionFF.x.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- // double y = 0;
- // try {
- // y = Double.parseDouble(val2);
- // } catch (final NumberFormatException e) {
- // addWarn("io.ptEvolutionFF.y.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- //
- // final PtEvolutionFF evolution = new PtEvolutionFF();
- // evolution.setX(x);
- // evolution.setY(y);
- // return evolution;
- // }
- // private static void addWarn(final String msg, final String nom, final Object data, final CtuluAnalyze analyser) {
- // // final Map m = createMapNom(nom);
- // // m.put("{data}", data); //$NON-NLS-1$
- // analyser.addWarn(msg, data);
- // }
-
- // public static PtEvolutionDF createEvolutionDFfromString(final String buff, final CtuluAnalyze analyser,
- // final String nomEMH) {
- //
- // try {
- // final StringTokenizer strToken = new StringTokenizer(buff.toString());
- //
- // String strnbJours = null, strnbHeures = null, strnbMinutes = null, strnbSecondes = null, stry = null;
- //
- // if (strToken.hasMoreTokens()) {
- // strnbJours = strToken.nextToken();
- // }
- // if (strToken.hasMoreTokens()) {
- // strnbHeures = strToken.nextToken();
- // }
- // if (strToken.hasMoreTokens()) {
- // strnbMinutes = strToken.nextToken();
- // }
- // if (strToken.hasMoreTokens()) {
- // strnbSecondes = strToken.nextToken();
- // }
- // if (strToken.hasMoreTokens()) {
- // stry = strToken.nextToken();
- // }
- //
- // int nbJours = -1, nbHeures = -1, nbMinutes = -1, nbSecondes = -1;
- // double y = 0;
- // // TODO a revoir avec le nouveau format date !
- // try {
- // nbJours = Integer.parseInt(strnbJours);
- // } catch (final NumberFormatException ex) {
- // addWarn("io.date.jour.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- // try {
- // nbHeures = Integer.parseInt(strnbHeures);
- // } catch (final NumberFormatException ex) {
- // addWarn("io.date.heure.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- // try {
- // nbMinutes = Integer.parseInt(strnbMinutes);
- // } catch (final NumberFormatException ex) {
- // addWarn("io.date.minute.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- // try {
- // nbSecondes = Integer.parseInt(strnbSecondes);
- // } catch (final NumberFormatException ex) {
- // addWarn("io.date.seconde.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- // try {
- // y = Double.parseDouble(stry);
- // } catch (final NumberFormatException ex) {
- // addWarn("io.evolutionDF.y.error", nomEMH, buff, analyser); //$NON-NLS-1$
- // }
- //
- // final CrueDate duree = new CrueDate(nbJours, nbHeures, nbMinutes, nbSecondes);
- //
- // final PtEvolutionDF evolution = new PtEvolutionDF();
- // evolution.setDate(duree);
- // evolution.setY(y);
- // return evolution;
- // } catch (final Exception e) {
- // return new PtEvolutionDF();
- // }
- //
- // }
-
- // public static PtProfil createFormString(final String buff, final CtuluAnalyze analyser, final String nameError) {
- // return createFormString(new StringBuffer(buff), analyser, nameError);
- // }
-
/**
* Message qui indique la balise n'est pas reconnue par les structures de données EMH.
*
@@ -203,20 +75,9 @@
out.addInfo("io.unknownEMH.error", balise, nomEMH);
}
- // private static Map<String, Object> createMapBaliseNom(final String balise, final String nom) {
- // final Map<String, Object> m = createBaliseMap(balise);
- // m.put("{nom}", nom); //$NON-NLS-1$
- // return m;
- // }
- // public static Map<String, Object> createMapNom(final String nom) {
- // return CtuluAnalyze.createMap("{nom}", nom); //$NON-NLS-1$
- // }
-
public static void unknowdataFromFile(final String balise, final String FileType, final String nom,
final CtuluAnalyze out) {
- // final Map m = createMapBaliseNom(balise, nom);
- // m.put("{fileType}", FileType); //$NON-NLS-1$
out.addInfo("io.unknownDataFromFile.error", balise, FileType, nom); //$NON-NLS-1$
}
@@ -248,9 +109,6 @@
}
- // private static Map<String, Object> createBaliseMap(final String balise) {
- // return CtuluAnalyze.createMap("{balise}", balise); //$NON-NLS-1$
- // }
/**
* Message qui indique la balise n'est pas reconnue par les structures de données EMH.
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueXmlReaderWriterImpl.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueXmlReaderWriterImpl.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/CrueXmlReaderWriterImpl.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -1,16 +1,6 @@
package org.fudaa.dodico.crue.io.dao;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
+import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
@@ -20,16 +10,16 @@
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
+import com.memoire.fu.FuLogCrue;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
import org.fudaa.ctulu.CtuluAnalyze;
import org.fudaa.ctulu.CtuluLibFile;
import org.fudaa.dodico.crue.io.common.Messages;
import org.fudaa.dodico.crue.metier.CrueData;
import org.xml.sax.InputSource;
-import com.memoire.fu.FuLogCrue;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
/**
* File format customisé pour Crue. Indique si le fichier est de type crue 9 ou 10. Contient un validator xsd pour le
* fichier donné. Contient une méthode statique très pratique qui permet de retourner automatiquement le bon FileFormat
@@ -156,11 +146,13 @@
final URL xsdURL = getClass().getResource(xsdPath);
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final Schema schema = schemaFactory.newSchema(xsdURL);
+
final Validator validator = schema.newValidator();
+ validator.setErrorHandler(handler);
validator.validate(new SAXSource(new InputSource(xml.toString())));
} catch (final Exception e) {
- res.manageException(e);
+ // res.manageException(e);
FuLogCrue.error(e);
return false;
}
@@ -185,7 +177,7 @@
* @return
*/
public D readDao(final File fichier, final CtuluAnalyze analyser, final Object dataLinked) {
- // TODO a remettre if (!isValide(fichier, analyser)) { return null; }
+ if (!isValide(fichier, analyser)) { return null; }
FileInputStream in = null;
D newData = null;
try {
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/ErrorHandlerDefault.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/ErrorHandlerDefault.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/ErrorHandlerDefault.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -24,12 +24,12 @@
public void error(final SAXParseException exception) throws SAXException {
hasError = true;
- res.addErrorFromFile(exception.getMessage(), exception.getLineNumber());
+ res.addErrorFromFile("io.xml.validator.error", exception.getLineNumber(), exception.getMessage());
}
public void fatalError(final SAXParseException exception) throws SAXException {
hasError = true;
- res.addErrorFromFile(exception.getMessage(), exception.getLineNumber());
+ res.addErrorFromFile("io.xml.validator.error", exception.getLineNumber(), exception.getMessage());
}
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPointFF.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPointFF.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPointFF.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -4,47 +4,23 @@
*/
package org.fudaa.dodico.crue.io.dao;
-import org.apache.commons.lang.StringUtils;
-import org.fudaa.ctulu.CtuluLibString;
-import org.fudaa.dodico.crue.io.common.AbstractSingleConverter;
import org.fudaa.dodico.crue.metier.emh.PtEvolutionFF;
-// TODO pour Fred : cette classe est similaire à SingleConverterPtProfil (seuls les objets métier utilisés sont différents). Ne pourrait-on pas mutualiser l'analyse et l'affichage du point FF ?
/**
* @author deniger
*/
-public class SingleConverterPointFF extends AbstractSingleConverter {
+public class SingleConverterPointFF extends AbstractSingleConverterPoint {
- public boolean canConvert(final Class type) {
- return PtEvolutionFF.class.equals(type);
+ /**
+ * Constructeur par défaut.
+ */
+ public SingleConverterPointFF() {
+ super(PtEvolutionFF.class);
}
- public Object fromString(final String str) {
- if (CtuluLibString.isEmpty(str)) { return null; }
- final String[] xy = StringUtils.split(str);
- if (xy == null || xy.length != 2) {
- if (analyse != null) {
- analyse.addError("io.convert.PtEvolutionFF.error", str);
- }
- return null;
- }
- final PtEvolutionFF res = new PtEvolutionFF();
- try {
- res.setX(Double.parseDouble(xy[0]));
- res.setY(Double.parseDouble(xy[1]));
- } catch (final NumberFormatException e) {
- if (analyse != null) {
- analyse.addError("io.convert.PtEvolutionFF.error", str);
- }
- return null;
- }
- return res;
+ @Override
+ protected Object createFor(double x, double y) {
+ return new PtEvolutionFF(x, y);
}
- public String toString(final Object obj) {
- if (obj == null) { return CtuluLibString.EMPTY_STRING; }
- final PtEvolutionFF in = (PtEvolutionFF) obj;
- return in.getX() + " " + in.getY();
- }
-
}
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPtProfil.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPtProfil.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/dao/SingleConverterPtProfil.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -4,64 +4,31 @@
*/
package org.fudaa.dodico.crue.io.dao;
-import org.apache.commons.lang.StringUtils;
-import org.fudaa.ctulu.CtuluAnalyze;
-import org.fudaa.ctulu.CtuluLibString;
import org.fudaa.dodico.crue.metier.emh.PtProfil;
-import com.thoughtworks.xstream.converters.SingleValueConverter;
-
/**
* @author deniger
*/
-public class SingleConverterPtProfil implements SingleValueConverter {
+public class SingleConverterPtProfil extends AbstractSingleConverterPoint {
- private CtuluAnalyze analyse;
+ /**
+ * Constructeur par defaut
+ */
+ public SingleConverterPtProfil() {
+ super(PtProfil.class);
+ }
+ @Override
public boolean canConvert(final Class type) {
return PtProfil.class.equals(type);
}
- public Object fromString(final String str) {
- if (CtuluLibString.isEmpty(str)) { return null; }
- final String[] xy = StringUtils.split(str);
- if (xy == null || xy.length != 2) {
- if (analyse != null) {
- analyse.addError("io.convert.PtEvolutionFF.error", str);
- }
- return null;
- }
+ @Override
+ protected Object createFor(final double x, final double y) {
final PtProfil res = new PtProfil();
- try {
- res.setYP(Double.parseDouble(xy[0]));
- res.setZ(Double.parseDouble(xy[1]));
- } catch (final NumberFormatException e) {
- if (analyse != null) {
- analyse.addError("io.convert.PtEvolutionFF.error", str);
- }
- return null;
- }
+ res.setYP(x);
+ res.setZ(y);
return res;
}
- /**
- * @return the analyse
- */
- public CtuluAnalyze getAnalyse() {
- return analyse;
- }
-
- /**
- * @param analyse the analyse to set
- */
- public void setAnalyse(final CtuluAnalyze analyse) {
- this.analyse = analyse;
- }
-
- public String toString(final Object obj) {
- if (obj == null) { return CtuluLibString.EMPTY_STRING; }
- final PtProfil in = (PtProfil) obj;
- return in.getYP() + " " + in.getZ();
- }
-
}
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBReader.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBReader.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBReader.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -1,5 +1,6 @@
package org.fudaa.dodico.crue.io.neuf;
+import gnu.trove.TDoubleArrayList;
import gnu.trove.TLongArrayList;
import java.io.IOException;
@@ -7,10 +8,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.fudaa.dodico.crue.io.neuf.FCBSequentialReader.StructBranche;
-import org.fudaa.dodico.crue.io.neuf.FCBSequentialReader.StructNoeud;
-import org.fudaa.dodico.crue.io.neuf.FCBSequentialReader.StructProfil;
-
/**
* Reader pour FCB.
*
@@ -46,6 +43,7 @@
analyze_.addFatalError("crue.io.fcb.notValid");
return null;
}
+ infos.setOrder(helper.getOrder());
// -- on lit les 10 premieres lignes de titre DC et DH dans le Buffer--//
final int nbCommentDc = 5;
@@ -60,8 +58,8 @@
commnentDc.add(helper.getStingFromBuffer(nbCaractereParLigne));
}
- infos.setCommentDc(commnentDc);
- infos.setCommentDh(commnentDh);
+ infos.commentDc = commnentDc;
+ infos.commentDh = commnentDh;
// on recupere la ligne write(ifi2) iprm,sngl(past),icodav,ibmax,nomdc,nomdh
helper.readData();
@@ -70,21 +68,21 @@
// iprm i4 : nombre de profils du modèle
// on lit la
// bf = helper.getBuffer();
- infos.nbProfils = bf.getInt();
+ final int nbProfils = bf.getInt();
// past r8 : pas de temps d'impression des résultats, en secondes.
- final double r8 = bf.getFloat();
+ /* final double r8 = */bf.getFloat();
// icodav i4 : présence (1) ou non (0) d'une régulation
// icodav==0 ou 2 pas de regulation
// icodav==1 ou 3 regulation
// icodav=2 ou 4 zfond_ssfente present
final int icodav = bf.getInt();
- infos.setSousFente(icodav >= 2);
- infos.setRegulationPresente(icodav == 1 || icodav == 3);
- infos.nbBranches = bf.getInt();
- final String nomDc = helper.getStingFromBuffer(60);
- final String nomDh = helper.getStingFromBuffer(60);
+ infos.sousFente = (icodav >= 2);
+ infos.regulation = (icodav == 1 || icodav == 3);
+ final int nbBranches = bf.getInt();
+ /* final String nomDc = */helper.getStingFromBuffer(60);
+ /* final String nomDh = */helper.getStingFromBuffer(60);
// -- on passe a la ligne contenant ibmax et iparam --//
// helper.skipRecord();
@@ -92,11 +90,11 @@
// on arrive a la ligne des profils --//
// write(ifi2) (tit(ipro),sngl(dist(ipro)),zfond(nuprfl(ipro)), ipro,ipro=1,iprm)
// on recupere l'indice du début des profils.
- readProfils(infos);
+ readProfils(infos, nbProfils);
// -- on passe la boucle de nbbranches lignes--//
- readBranches(infos);
+ readBranches(infos, nbBranches);
// -- ensuite on lit les points si ou ils sont affiches--//
readNodes(infos);
@@ -104,11 +102,12 @@
// TODO gere si oui ou non la ligne de write(9) npar,(nompar(i),tx(i),i=1,npar)
// es t ecrite, cf spec pour entete
if (infos.isRegulation()) {
- readRegulationParam(infos);
+ helper.readSequentialData();
+ // readRegulationParam(infos); pas pris en compte dans le lot0
}
// -- on arrive au CORPS, on repere les indice de chaque PDT --//
- // readPdt(infos);
+ readPdt(infos);
// --on passee les lignes de Crue--//
@@ -122,107 +121,76 @@
* @param infos
* @throws IOException
*/
+ // (ifi2) nbpoin,(nompoi(ip),nupro(ip),ip=1,nbpoin)
private void readNodes(final FCBSequentialReader infos) throws IOException {
- // (ifi2) nbpoin,(nompoi(ip),nupro(ip),ip=1,nbpoin)
// nbpoin i4 : nombre de noeuds
helper.readData();
final ByteBuffer bf = helper.getBuffer();
final int nbNd = bf.getInt();
- infos.nbNoeuds = nbNd;
- final List<StructNoeud> nds = new ArrayList<StructNoeud>(nbNd);
+ final List<FCBValueObject.EnteteNoeud> nds = new ArrayList<FCBValueObject.EnteteNoeud>(nbNd);
for (int i = 0; i < nbNd; i++) {
- final StructNoeud nd = new StructNoeud();
+ final FCBValueObject.EnteteNoeud nd = new FCBValueObject.EnteteNoeud();
nd.setNom(helper.getStingFromBuffer(16).trim());
nd.setNumProfil(bf.getInt() - 1);
nds.add(nd);
}
- infos.noeuds = nds;
+ infos.setNoeuds(nds);
}
/**
- * Lit les infos des regulations si elles existent.
- *
- * @param infos
- * @throws IOException
- */
- private void readRegulationParam(final FCBSequentialReader infos) throws IOException {
- // write(9) npar,(nompar(i),tx(i),i=1,npar)
-
- // TODO a verifier: l'objectif ici est de tenter de lire la ligne, si elle existe il y a des regulations,
- // WARNING sinon il n'y a pas de pas de temps regul.
-
- // npar i4 : nombre de paramètres de régulation
-
- helper.readAll(4);
- final ByteBuffer bf = helper.getBuffer();
- try {
- infos.nbParamsRegulation = bf.getInt();
- } catch (final Exception e) {
-
- return;
- }
- infos.hasRegulationRecords = true;
- infos.tableauNomsParamRegulations = new String[infos.nbParamsRegulation];
-
- for (int i = 0; i < infos.nbParamsRegulation; i++) {
- helper.readAll(8);
- final ByteBuffer buffer = helper.getBuffer();
-
- final char[] nomChar = new char[8];
- for (int j = 0; j < 8; j++) {
- nomChar[j] = buffer.getChar();
- }
- infos.tableauNomsParamRegulations[i] = new String(nomChar);
-
- }
-
- infos.indicePostionHelperForRegulations = helper.getCurrentPosition();
-
- }
-
- /**
* lit les pdt.
*
* @param infos
* @throws IOException
*/
public void readPdt(final FCBSequentialReader infos) throws IOException {
+ // les tabbleau enregistrant les pdt ( regu et normal), leur position et ruinou
+ final TLongArrayList posNormal = new TLongArrayList();
+ final TDoubleArrayList pdtNormal = new TDoubleArrayList();
+ final TDoubleArrayList ruinouNormal = new TDoubleArrayList();
+ final TLongArrayList posRegul = new TLongArrayList();
+ final TDoubleArrayList pdtRegul = new TDoubleArrayList();
- infos.tableauIndicesPdtCrue = new TLongArrayList();
- infos.tableauIndicesPdtRegul = new TLongArrayList();
+ while (helper.getAvailable() > 0) {
+ helper.readData();
+ // ici on a la ligne
+ // write(9) test,sngl(t) si regul
+ // (ifi2) test,sngl(t),sngl(ruinou) pour un pas de temps normal
- // -- on sort de la boucle au eof --//
- while (true) {
- // -- on lit les 2 param test et l'indice du pdt --//
- // write(9) test,sngl(t)
-
- helper.readAll(8);
- final ByteBuffer buffer = helper.getBuffer();
-
- final char[] nomChar = new char[8];
- for (int j = 0; j < 8; j++) {
- nomChar[j] = buffer.getChar();
+ // ces 2 tableaux enregistrent les données: si regu on les modifie
+ TLongArrayList posCurrent = posNormal;
+ TDoubleArrayList pdtCurrent = pdtNormal;
+ final String id = helper.getStingFromBuffer(4);
+ final boolean isRegu = "REGU".equals(id);
+ // si regu, on switche les tableaux qui vont recevoir les donnees.
+ if (isRegu) {
+ posCurrent = posRegul;
+ pdtCurrent = pdtRegul;
}
- final String type = new String(nomChar);
- infos.nbTimesSteps++;
- // test c4 : 'CRUE' ou 'REGU' suivant le cas
- if (type.equals("REGU")) {
- infos.nbTimesStepsRegulation++;
- infos.tableauIndicesPdtRegul.add(helper.getCurrentPosition());
- // pas de pdt pour crue
- infos.tableauIndicesPdtCrue.add(-1);
- } else {
- infos.nbTimesStepsCrue++;
- infos.tableauIndicesPdtCrue.add(helper.getCurrentPosition());
- // pas de pdt pour regul
- infos.tableauIndicesPdtRegul.add(-1);
+ // on enregistre le pas de temps
+ pdtCurrent.add(helper.getBuffer().getFloat());
+ // en mode normal, on enregistre ruinou
+ if (!isRegu) {
+ ruinouNormal.add(helper.getBuffer().getDouble());
}
-
+ // on enregistre la position intéressante: celle juste avant les donnéées
+ posCurrent.add(helper.getCurrentPosition());
+ // on saute la ligne profil ou regul
+ helper.skipRecord();
+ // si pas regu
+ if (!isRegu) {
+ // on saute la ligne branche
+ helper.skipRecord();
+ // on saute la ligne point
+ helper.skipRecord();
+ }
}
+ infos.pdt = new FCBSequentialReader.PasDeTempsContainerNormal(posNormal, pdtNormal, ruinouNormal);
+ infos.pdtRegulation = new FCBSequentialReader.PasDeTempsContainer(posRegul, pdtRegul);
}
@@ -232,17 +200,17 @@
* @param infos
* @throws IOException
*/
- private void readBranches(final FCBSequentialReader infos) throws IOException {
+ private void readBranches(final FCBSequentialReader infos, final int nbBranches) throws IOException {
// do 30 ib=1,ibmax
// write(ifi2) ntyp(ib),imax(ib),(n0pr(ip,ib),ip=1,imax(ib)),
// * nombr(ib),nupam(ib),nupav(ib)
// 30 continue
- final List<StructBranche> brs = new ArrayList<StructBranche>(infos.nbBranches);
+ final List<FCBValueObject.EnteteBranche> brs = new ArrayList<FCBValueObject.EnteteBranche>(nbBranches);
// infos.indicePostionHelperForBranches = helper.getCurrentPosition();
- for (int i = 0; i < infos.nbBranches; i++) {
+ for (int i = 0; i < nbBranches; i++) {
helper.readData();
final ByteBuffer buffer = helper.getBuffer();
- final StructBranche br = new StructBranche();
+ final FCBValueObject.EnteteBranche br = new FCBValueObject.EnteteBranche();
br.setTypeBranche(buffer.getInt());
final int nbProfil = buffer.getInt();
final int[] numeroAbsProfil = new int[nbProfil];
@@ -264,16 +232,16 @@
*
* @throws IOException
*/
- private void readProfils(final FCBSequentialReader infos) throws IOException {
+ private void readProfils(final FCBSequentialReader infos, final int nbProfils) throws IOException {
// on recupere l'indice du début des profils.
// infos.indicePostionHelperForProfil = helper.getCurrentPosition();
- final List<StructProfil> profils = new ArrayList<StructProfil>(infos.nbProfils);
+ final List<FCBValueObject.EnteteProfil> profils = new ArrayList<FCBValueObject.EnteteProfil>(nbProfils);
final boolean containsSsfente = infos.isSousFente();
// (tit(ipro),sngl(dist(ipro)),zfond(nuprfl(ipro))
helper.readData();
final ByteBuffer buffer = helper.getBuffer();
- for (int i = 0; i < infos.nbProfils; i++) {
- final StructProfil prof = new StructProfil();
+ for (int i = 0; i < nbProfils; i++) {
+ final FCBValueObject.EnteteProfil prof = new FCBValueObject.EnteteProfil();
prof.setNom(helper.getStingFromBuffer(16).trim());
prof.setDistance(buffer.getFloat());
Modified: trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBSequentialReader.java
===================================================================
--- trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBSequentialReader.java 2009-05-31 07:23:04 UTC (rev 4827)
+++ trunk/soft/fudaa-crue/dodico/src/main/java/org/fudaa/dodico/crue/io/neuf/FCBSequentialReader.java 2009-06-01 22:32:04 UTC (rev 4828)
@@ -1,14 +1,20 @@
package org.fudaa.dodico.crue.io.neuf;
+import gnu.trove.TDoubleArrayList;
import gnu.trove.TLongArrayList;
+import gnu.trove.TObjectIntHashMap;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
+import java.util.Collections;
import java.util.List;
+import org.apache.commons.lang.ArrayUtils;
+
/**
* Structure de données fcb construite à la volée avec les infos fcb qui vont bien. garde en memoire les indices des pas
* de temps, les noeuds utilises, les branches, l'indice de regulation, le nb de pas de temps crue et regulation.
@@ -17,229 +23,234 @@
*/
public class FCBSequentialReader {
+ private static final class DataContainerEmpty extends EnteteContainer {
+
+ public DataContainerEmpty() {
+ super(Collections.emptyList(), null);
+ }
+ }
+
/**
- * Structure qui correspond a un enregistrement d'une branche.
+ * Interface definissant un contrat permettant de construire un resultat
*
- * @author Adrien Hadoux
+ * @author denf01a
+ * @creation 27 mai 2009
+ * @version
+ * @param <T> le resultat voulu
*/
- public static class StructBranche {
- private String nom;
- private int profilAmont;
- private int profilAval;
- private int[] tableauIndiceProfils;
-
- private int typeBranche;
-
+ private interface ResBuilder<T extends FCBValueObject.AbstractRes> {
/**
- * @param idxLocal l'indice du profil dans la branche
- * @return l'indice global ( commence a 0!)
+ * @return le resultat instancie
*/
- public int getIndiceProfil(final int idxLocal) {
- return tableauIndiceProfils[idxLocal];
- }
+ T createRes();
/**
- * @return le nombre de profils dans cette branche
+ * @param idxEnr l'indice de l'enregistrement a lire
+ * @return le nombre de byte a sauter pour lire la bonne donnee
*/
- public int getNbProfils() {
- return tableauIndiceProfils == null ? 0 : tableauIndiceProfils.length;
- }
+ int getOffset(int idxEnr);
/**
- * @return the nom
+ * @return la longueur des donnees pour un resultat ( pour un profil,noeud ou branche).
*/
- public String getNom() {
- return nom;
+ int getTailleEnr();
+ }
+
+ private class ResBuilderBranche implements ResBuilder<FCBValueObject.ResBranche> {
+
+ public FCBValueObject.ResBranche createRes() {
+ return new FCBValueObject.ResBranche();
}
- /**
- * @return the profilAmont
- */
- public int getProfilAmont() {
- return profilAmont;
+ public int getOffset(final int idxEnr) {
+ return getTailleBlocProfil() + 4 + idxEnr * TAILLE_ENR_BRANCHE;
}
- /**
- * @return the profilAval
- */
- public int getProfilAval() {
- return profilAval;
+ public int getTailleEnr() {
+ return TAILLE_ENR_BRANCHE;
}
- /**
- * @return the typeBranche
- */
- public int getTypeBranche() {
- return typeBranche;
+ }
+
+ private class ResBuilderNoeud implements ResBuilder<FCBValueObject.ResNoeud> {
+
+ public FCBValueObject.ResNoeud createRes() {
+ return new FCBValueObject.ResNoeud();
}
- /**
- * @param nom the nom to set
- */
- protected void setNom(final String nom) {
- this.nom = nom;
+ public int getOffset(final int idxEnr) {
+ return getTailleBlocProfil() + getTailleBlocBranche() + 4 + idxEnr * TAILLE_ENR_NOEUD;
}
- /**
- * @param profilAmont the profilAmont to set
- */
- protected void setProfilAmont(final int profilAmont) {
- this.profilAmont = profilAmont;
+ public int getTailleEnr() {
+ return TAILLE_ENR_NOEUD;
}
- /**
- * @param profilAval the profilAval to set
- */
- protected void setProfilAval(final int profilAval) {
- this.profilAval = profilAval;
+ }
+
+ private class ResBuilderProfil implements ResBuilder<FCBValueObject.ResProfil> {
+
+ public FCBValueObject.ResProfil createRes() {
+ return new FCBValueObject.ResProfil();
}
- /**
- * @param tableauIndiceProfils the tableauIndiceProfils to set
- */
- protected void setTableauIndiceProfils(final int[] tableauIndiceProfils) {
- this.tableauIndiceProfils = tableauIndiceProfils;
+ public int getOffset(final int idxEnr) {
+ return 4 + idxEnr * TAILLE_ENR_PROFIL;
}
- /**
- * @param typeBranche the typeBranche to set
- */
- protected void setTypeBranche(final int typeBranche) {
- this.typeBranche = typeBranche;
+ public int getTailleEnr() {
+ return TAILLE_ENR_PROFIL;
}
+
}
/**
- * Structure qui correspond a un enregistrement d'une noeud.
- *
- * @author Adrien Hadoux
+ * indice des positions de chaque pdt de crue, longueur variable
*/
- public static class StructNoeud {
+ protected static class PasDeTempsContainer {
- private String nom;
- private int numProfil;
+ final protected long[] positions;
+ final protected double[] pdts;
- /**
- * @return the nom
- */
- public String getNom() {
- return nom;
+ protected PasDeTempsContainer() {
+ positions = ArrayUtils.EMPTY_LONG_ARRAY;
+ pdts = ArrayUtils.EMPTY_DOUBLE_ARRAY;
}
- /**
- * @param nom the nom to set
- */
- protected void setNom(String nom) {
- this.nom = nom;
+ protected PasDeTempsContainer(final TLongArrayList tableauIndicesPdtCrue, final TDoubleArrayList pdt) {
+ positions = tableauIndicesPdtCrue.toNativeArray();
+ pdts = pdt.toNativeArray();
}
+ public int getNbPdt() {
+ return pdts.length;
+ }
+
+ public double getPdt(final int idxPdt) {
+ return pdts[idxPdt];
+ }
+
+ public long getPosition(final int idxPdt) {
+ return positions[idxPdt];
+ }
+
+ }
+
+ protected static class PasDeTempsContainerNormal extends PasDeTempsContainer {
+
/**
- * @return the numPro
+ * coefficient de ruissellement
*/
- public int getNumProfil() {
- return numProfil;
+ private final double[] ruinou;
+
+ protected PasDeTempsContainerNormal() {
+ super();
+ ruinou = ArrayUtils.EMPTY_DOUBLE_ARRAY;
}
+ protected PasDeTempsContainerNormal(final TLongArrayList tableauIndicesPdtCrue, final TDoubleArrayList pdt,
+ final TDoubleArrayList ruinou) {
+ super(tableauIndicesPdtCrue, pdt);
+ this.ruinou = ruinou.toNativeArray();
+ }
+
/**
- * @param numPro the numPro to set
+ * @param idx le pas de temps demande.
+ * @return coefficient de ruissellement au pas de temps idx
*/
- protected void setNumProfil(int numPro) {
- this.numProfil = numPro;
+ public double getRuinou(final int idx) {
+ return ruinou[idx];
}
}
/**
- * Structure qui correspond a un enregistrement d'une profil.
- *
- * @author Adrien Hadoux
+ * @author denf01a
+ * @creation 27 mai 2009
+ * @version
+ * @param <T> l'entete
+ * @param <R> le resultat
*/
- public static class StructProfil {
+ public static class EnteteContainer<T extends FCBValueObject.AbstractEntete, R extends FCBValueObject.AbstractRes> {
+ private final List<T> listData;
+ private final ResBuilder<R> resBuilder;
+ private final TObjectIntHashMap namePos;
- private double distance;
- private String nom;
- private double zFond;
- private double zFondSsfente;
+ private final int nb;
- /**
- * @return the distance
- */
- public double getDistance() {
- return distance;
+ protected EnteteContainer(final List<T> struc, final ResBuilder<R> resBuilder) {
+ super();
+ this.listData = Collections.unmodifiableList(struc);
+ this.resBuilder = resBuilder;
+ namePos = new TObjectIntHashMap();
+ int idx = 0;
+ for (final T t : struc) {
+ namePos.put(t.getNom(), idx++);
+ }
+ nb = listData.size();
}
- /**
- * @return the nom
- */
- public String getNom() {
- return nom;
+ protected ResBuilder<R> getResBuilder() {
+ return resBuilder;
}
/**
- * @return the zfonds
+ * @param nom le nom
+ * @return la position de lecture. -1 si non present
*/
- public double getZfond() {
- return zFond;
+ public T getData(final String nom) {
+ final int i = getPosition(nom);
+ return i < 0 ? null : getListData().get(i);
}
/**
- * @return the zzfondSsfente
+ * @param idx l'indice
+ * @return le nom de la donnes
*/
- public double getZfondSsfente() {
- return zFondSsfente;
+ public String getDataName(final int idx) {
+ return listData.get(idx).getNom();
}
/**
- * @param distance the distance to set
+ * @return liste non modifiable des donnees.
*/
- protected void setDistance(final double distance) {
- this.distance = distance;
+ public List<T> getListData() {
+ return listData;
}
/**
- * @param nom the nom to set
+ * @return le nombre de données
*/
- protected void setNom(final String nom) {
- this.nom = nom;
+ public int getNbData() {
+ return nb;
}
/**
- * @param zfond the zfonds to set
+ * @param nom le nom
+ * @return la position de lecture. -1 si non present
*/
- protected void setZfond(final double zfond) {
- this.zFond = zfond;
+ public int getPosition(final String nom) {
+ if (namePos.contains(nom)) { return namePos.get(nom); }
+ return -1;
}
-
- /**
- * @param zFondSsfente the zzfondSsfente to set
- */
- protected void setZFondSsfente(final double zFondSsfente) {
- this.zFondSsfente = zFondSsfente;
- }
-
- @Override
- public String toString() {
- return nom + " dist=" + distance + ", zfond=" + zFond + ", sfondSsFente=" + zFondSsfente;
- }
-
}
- public static class StructRegulation {
+ private static final int TAILLE_ENR_PROFIL = 20;
+ private static final int TAILLE_ENR_BRANCHE = 16;
+ private static final int TAILLE_ENR_NOEUD = 12;
- double[] numPro;
+ private final static PasDeTempsContainer EMPTY_PDT = new PasDeTempsContainer();
- double pdt;
- }
+ private final static PasDeTempsContainerNormal EMPTY_PDT_NORMAL = new PasDeTempsContainerNormal();
+ private final static EnteteContainer EMPTY = new DataContainerEmpty();
- protected List<StructBranche> branches;
- protected List<StructNoeud> noeuds;
-
/**
* le channel.
*/
protected FileChannel channel;
protected List<String> commentDc;
+
protected List<String> commentDh;
/**
@@ -248,76 +259,23 @@
protected final File file;
/**
- * hasCrueRecords en principe toujours vrai. A confirmer.
- */
- protected boolean hasCrueRecords = true;
-
- protected boolean hasRegulationRecords = false;
-
- /**
- * indique la position du reader pour le debut de lecture des crue pas de temps.
- */
- protected long indicePostionHelperForCruePDT = 0;
-
- /**
- * indique la position du reader pour le debut de lecture des nregulation
- */
- protected long indicePostionHelperForRegulations = 0;
- /**
* true si le fichier contient une régulation
*/
- private boolean isRegulation;
- /**
- * nb de branches.
- */
- protected int nbBranches = 0;
- /**
- * nb de profils du modele.
- */
- protected int nbNoeuds = 0;
+ protected boolean regulation;
- /**
- * Nb de parametres de Regulation
- */
- protected int nbParamsRegulation = 0;
+ protected boolean sousFente;
- /**
- * nb de profils du modele.
- */
- protected int nbProfils;
- /**
- * le nb de timesteps total
- */
- protected int nbTimesSteps = 0;
+ protected PasDeTempsContainerNormal pdt = EMPTY_PDT_NORMAL;
+ protected PasDeTempsContainer pdtRegulation = EMPTY_PDT;
+ private EnteteContainer<FCBValueObject.EnteteProfil, FCBValueObject.ResProfil> containerProfils = EMPTY;
- /**
- * Nb de pas de temps Crue, different de Regulation
- */
- protected int nbTimesStepsCrue = 0;
- /**
- * Nb de pas de temps Regulation, different de crue
- */
- protected int nbTimesStepsRegulation = 0;
+ private EnteteContainer<FCBValueObject.EnteteBranche, FCBValueObject.ResBranche> containerBranches = EMPTY;
- protected List<StructProfil> profils;
- private boolean sousFente;
- /**
- * indice des positions de chaque pdt de crue, longueur variable
- */
+ private EnteteContainer<FCBValueObject.EnteteNoeud, FCBValueObject.ResNoeud> containerNoeuds = EMPTY;
- protected TLongArrayList tableauIndicesPdtCrue;
+ private ByteOrder order;
/**
- * indice des positions de chaque pdt de regulation
- */
- protected TLongArrayList tableauIndicesPdtRegul;
-
- /**
- * Noms des differents parametres intervenant dans la regul: longueur variable.
- */
- protected String[] tableauNomsParamRegulations;
-
- /**
* Constructeur de la structure d'accès rapide fcb.
*
* @param file
@@ -326,17 +284,50 @@
this.file = file;
}
- /**
- * @param capacity
- * @return
- */
- protected ByteBuffer createBuffer(final int capacity) {
+ private ByteBuffer createByteBuffer(final int taille) {
+ final ByteBuffer allocate = ByteBuffer.allocate(taille);
+ if (order != null) {
+ allocate.order(order);
+ }
+ return allocate;
+ }
- final ByteBuffer buffer = ByteBuffer.allocateDirect(capacity);
+ private <T extends FCBValueObject.AbstractEntete, R extends FCBValueObject.AbstractRes> R getResultat(
+ final int idxPdt, final String nomEMH, final R inout, final EnteteContainer<T, R> dataContainer)
+ throws IOException {
- return buffer;
+ final long positionTimeStep = pdt.getPosition(idxPdt);
+ if (positionTimeStep < 0) { throw new IOException("io.fcb.timeStep.notFound.error"); }
+ final int idxBranche = dataContainer.getPosition(nomEMH);
+ if (idxBranche < 0) { throw new IOException("io.fcb.emh.notFound.error"); }
+ final ResBuilder<R> resBuilder = dataContainer.getResBuilder();
+ if (resBuilder == null) { throw new IOException("io.fcb.emh.noBuilder.error"); }
+ // on se positionne au debut du profil
+ // +4 pour l'entier indiquant la longueur d'enregistrement du bloc.
+ // les donnees branches se trouvent apres les profils d'ou le + getTailleBlocProfil()
+ final long deb = positionTimeStep + resBuilder.getOffset(idxBranche);
+ final ByteBuffer bf = createByteBuffer(resBuilder.getTailleEnr());
+ channel.read(bf, deb);
+ bf.rewind();
+ R res = inout;
+ // si le parametre inout est null on le cree.
+ if (res == null) {
+ res = resBuilder.createRes();
+ }
+ res.read(bf);
+ return res;
+
}
+ private int getTailleBlocBranche() {
+ return 8 + getNbBranches() * TAILLE_ENR_BRANCHE;
+ }
+
+ private int getTailleBlocProfil() {
+ // 8 pour les 2 entiers englobantsl'enregistrement
+ return 8 + getNbProfils() * TAILLE_ENR_PROFIL;
+ }
+
/**
* Cree un chanel pour le placer sur l'indice de position voulu.
*
@@ -348,297 +339,162 @@
}
}
- /**
- * @return the commentDc
- */
- public List<String> getCommentDc() {
- return commentDc;
+ protected ByteOrder getOrder() {
+ return order;
}
/**
- * @return the commentDh
+ * @param branches the branches to set
*/
- public List<String> getCommentDh() {
- return commentDh;
+ protected void setBranches(final List<FCBValueObject.EnteteBranche> branches) {
+ this.containerBranches = new EnteteContainer<FCBValueObject.EnteteBranche, FCBValueObject.ResBranche>(branches,
+ new ResBuilderBranche());
}
- /**
- * @return the nbBranches
- */
- public int getNbBranches() {
- return nbBranches;
+ protected void setNoeuds(final List<FCBValueObject.EnteteNoeud> noeuds) {
+ this.containerNoeuds = new EnteteContainer<FCBValueObject.EnteteNoeud, FCBValueObject.ResNoeud>(noeuds,
+ new ResBuilderNoeud());
}
- /**
- * @return the nbProfils
- */
- public int getNbProfils() {
- return nbProfils;
+ protected void setOrder(final ByteOrder order) {
+ this.order = order;
}
- int getNbTimeStepCrue() {
- return nbTimesStepsCrue;
+ protected void setPdt(final PasDeTempsContainerNormal pdt) {
+ this.pdt = pdt.getNbPdt() == 0 ? EMPTY_PDT_NORMAL : pdt;
}
- int getNbTimeStepRegulation() {
- return nbTimesStepsRegulation;
+ protected void setPdtRegulation(final PasDeTempsContainer pdtRegulation) {
+ this.pdtRegulation = pdtRegulation.getNbPdt() == 0 ? EMPTY_PDT : pdtRegulation;
}
/**
- * Recupere la ligne correspondante a la branche indiceBranche
- *
- * @param indiceBranche
- * @return la branche demande
+ * @param profils the profils to set
*/
- public StructBranche getBranche(final int indiceBranche) {
- return branches.get(indiceBranche);
- // createChannel();
- // if (!channel.isOpen()) { return null; }
- //
- // final StructBranche structure = new StructBranche();
- //
- // // -- position de la position voulue --//
- // final long position = indicePostionHelperForBranches + indiceBranche;
- //
- // channel.position(position);
- //
- // // -- donnees de la forme --//
- // // write(ifi2) ntyp(ib),imax(ib),(n0pr(ip,ib),ip=1,imax(ib)),
- // // nombr(ib),nupam(ib),nupav(ib)
- //
- // // ntyp(NBR) i4 : type de la branche ib
- // ByteBuffer buffer = createBuffer(4);
- // channel.read(buffer);
- // structure.typeBranche = buffer.getInt();
- //
- // // imax(NBR) i4 : nombre de profil dans la branche ib
- // buffer = createBuffer(4);
- // channel.read(buffer);
- // final int nbProfils = buffer.getInt();
- // structure.tableauIndiceProfils = new int[nbProfils];
- //
- // // --n0pr(NPR,NBR) i2 : n° absolu du profil dont le n° est ip dans la branche ib --//
- // buffer = createBuffer(4 * nbProfils);
- // // -- on lit tous les num de profils d'un coup --//
- // channel.read(buffer);
- //
- // // -- on les copie dans un tableau d'indices --//
- // for (int i = 0; i < nbProfils; i++) {
- // TODO faux, il fallait faire un getShort !
- // structure.tableauIndiceProfils[i] = buffer.getInt();
- // }
- //
- // // nombr(NBR) c8 : nom de la branche n° ib
- // buffer = createBuffer(8);
- // channel.read(buffer);
- // final char[] nomChar = new char[8];
- // for (int i = 0; i < 8; i++) {
- // nomChar[i] = buffer.getChar();
- // }
- // structure.nom = new String(nomChar);
- //
- // // nupam(NBR) i4 : n° du profil amont de la branche ib
- // buffer = createBuffer(4 * 2);
- // channel.read(buffer);
- // structure.profilAmont = buffer.getInt();
- //
- // // nupav(NBR) i4 : n° du profil aval de la branche ib
- // structure.profilAval = buffer.getInt();
- //
- // return structure;
-
+ protected void setProfils(final List<FCBValueObject.EnteteProfil> profils) {
+ this.containerProfils = new EnteteContainer<FCBValueObject.EnteteProfil, FCBValueObject.ResProfil>(profils,
+ new ResBuilderProfil());
}
/**
- * @param pdt
- * @return
- * @throws IOException
+ * @return the commentDc
*/
- public synchronized double getValuesCRUE(final int pdt) throws IOException {
-
- createChannel();
- if (!channel.isOpen()) { return 0; }
- // on recupere la position de l'indice du pdt
-
- final long pos = tableauIndicesPdtCrue.get(pdt);
- if (pos == -1) { return 0; }
- channel.position(pos);
-
- // TODO Carole a terminer
-
- return 0;
+ public List<String> getCommentDc() {
+ return commentDc;
}
/**
- * Recupere la ligne correspondante a la noeuds indiceNoeud.
- *
- * @param idxNd indice demande
- * @return le noeud d'indice idxNd
+ * @return the commentDh
*/
- public synchronized StructNoeud getNoeud(final int idxNd) {
- return noeuds.get(idxNd);
+ public List<String> getCommentDh() {
+ return commentDh;
}
/**
- * Recupere la ligne correspondante a la profil indicePorfil. Attention longueur variable a cause des profils...
- *
- * @param indiceProfil
- * @return données concernant le ieme profile.
+ * @return le container des branches
*/
- public synchronized StructProfil getProfil(final int indiceProfil) {
- return profils.get(indiceProfil);
-
- // TODO vraiment n'importe quoi...
- // createChannel();
- // if (!channel.isOpen()) { return null; }
- //
- // StructProfil structure = new StructProfil();
- //
- // // -- position de la position voulue --//
- // long position = indicePostionHelperForProfil + indiceProfil;
- //
- // channel.position(position);
- //
- // // write(ifi2) (tit(ipro),sngl(dist(ipro)),zfond(nuprfl(ipro)), ipro,ipro=1,iprm)
- //
- // // tit(NBPRO) c8 : noms des profils
- // ByteBuffer buffer = createBuffer(8);
- // channel.read(buffer);
- // char[] nomChar = new char[8];
- // for (int i = 0; i < 8; i++) {
- // nomChar[i] = buffer.getChar();
- // }
- // structure.nom = new String(nomChar);
- //
- // // dist(NBPRO) r4 : distance entre les profils ipro-1 et ipro.
- // // attention sngl transforme en reel donc 4
- //
- // // zfond r4 : cote du fond du profil fluvial
- //
- // // on cree le buffer pour les zfond et dist pour iprm=nbProfils elements
- // buffer = createBuffer((4 + 4) * nbProfilsModele);
- //
- // structure.distance = new double[nbProfilsModele];
- // structure.zfonds = new double[nbProfilsModele];
- // // TODO tout faux
- // for (int i = 0; i < nbProfilsModele; i++) {
- // structure.distance[i] = buffer.getFloat();
- // structure.zfonds[i] = buffer.getFloat();
- // }
- // return structure;
+ public EnteteContainer<FCBValueObject.EnteteBranche, FCBValueObject.ResBranche> getContainerBranches() {
+ return containerBranches;
}
/**
- * @param pdt
- * @return
- * @throws IOException
+ * @return le container des noeuds.
*/
- public synchronized StructRegulation getValuesRegulation(final int pdt) throws IOException {
-
- createChannel();
- if (!channel.isOpen()) { return null; }
- // on recupere la position de l'indice du pdt
- final long pos = tableauIndicesPdtRegul.get(pdt);
- if (pos == -1) { return null; }
- final StructRegulation structure = new StructRegulation();
- channel.position(pos);
-
- // on est a la position du nom du pdt et les 2 valeurs en + a lire
- // write(9) test,sngl(t)
- // write(9) (para(i),i=1,npar)
-
- ByteBuffer buffer = createBuffer(4);
- channel.read(buffer);
- structure.pdt = buffer.getFloat();
-
- // para(npar) r4 : paramètres de régulation
- buffer = createBuffer(4 * nbParamsRegulation);
- structure.numPro = new double[nbParamsRegulatio...
[truncated message content] |