Author: chatellier Date: 2010-10-22 12:39:55 +0000 (Fri, 22 Oct 2010) New Revision: 88 Log: Modification du stockage m?\195?\169moire (String[] > String) Added: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/ trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryListStorage.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlDataTableModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java 2010-10-22 12:36:07 UTC (rev 87) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java 2010-10-22 12:39:55 UTC (rev 88) @@ -25,7 +25,7 @@ package fr.ifremer.coser.bean; -import java.util.List; +import fr.ifremer.coser.storage.DataStorage; /** * Project. @@ -52,18 +52,18 @@ protected String name; - protected List<String[]> dataCatch; + protected DataStorage dataCatch; - protected List<String[]> dataStrata; + protected DataStorage dataStrata; - protected List<String[]> dataHaul; + protected DataStorage dataHaul; - protected List<String[]> dataLength; + protected DataStorage dataLength; /** Reftax SIH. */ - protected List<String[]> refTaxSpecies; + protected DataStorage refTaxSpecies; - public List<String[]> getCatch() { + public DataStorage getCatch() { return dataCatch; } @@ -77,39 +77,39 @@ getPropertyChangeSupport().firePropertyChange("name", oldValue, name); } - public void setCatch(List<String[]> dataCatch) { + public void setCatch(DataStorage dataCatch) { this.dataCatch = dataCatch; } - public List<String[]> getStrata() { + public DataStorage getStrata() { return dataStrata; } - public void setStrata(List<String[]> dataStrata) { + public void setStrata(DataStorage dataStrata) { this.dataStrata = dataStrata; } - public List<String[]> getHaul() { + public DataStorage getHaul() { return dataHaul; } - public void setHaul(List<String[]> dataHaul) { + public void setHaul(DataStorage dataHaul) { this.dataHaul = dataHaul; } - public List<String[]> getLength() { + public DataStorage getLength() { return dataLength; } - public void setLength(List<String[]> dataLength) { + public void setLength(DataStorage dataLength) { this.dataLength = dataLength; } - public List<String[]> getRefTaxSpecies() { + public DataStorage getRefTaxSpecies() { return refTaxSpecies; } - public void setRefTaxSpecies(List<String[]> refTaxSpecies) { + public void setRefTaxSpecies(DataStorage refTaxSpecies) { this.refTaxSpecies = refTaxSpecies; } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2010-10-22 12:36:07 UTC (rev 87) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2010-10-22 12:39:55 UTC (rev 88) @@ -38,10 +38,8 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; -import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; -import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; @@ -57,6 +55,8 @@ import fr.ifremer.coser.bean.Length; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.bean.Strata; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.MemoryListStorage; /** * File import/export service. @@ -86,7 +86,7 @@ */ public Project loadCSVFile(Project project, Category category, File file) throws CoserBusinessException { - List<String[]> content = new ArrayList<String[]>(); + DataStorage content = new MemoryListStorage(); Reader reader = null; CSVReader csvReader = null; @@ -141,7 +141,7 @@ * @param content content to set */ protected void addProjectContent(Project project, Category category, - List<String[]> content) { + DataStorage content) { switch (category) { case CATCH: @@ -224,7 +224,7 @@ public void storeData(Project project, Category category, File file) throws CoserBusinessException { // get project category content - List<String[]> content = null; + DataStorage content = null; switch (category) { case CATCH: content = project.getCatch(); Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java 2010-10-22 12:36:07 UTC (rev 87) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java 2010-10-22 12:39:55 UTC (rev 88) @@ -56,6 +56,7 @@ import fr.ifremer.coser.bean.Strata; import fr.ifremer.coser.control.ProgressMonitor; import fr.ifremer.coser.control.ValidationError; +import fr.ifremer.coser.storage.DataStorage; /** * Validation service. @@ -162,7 +163,7 @@ Length beanLength = new Length(); Strata beanStrata = new Strata(); - List<String[]> dataToCheck = null; + DataStorage dataToCheck = null; switch (category) { case CATCH: dataToCheck = project.getCatch(); Added: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java 2010-10-22 12:39:55 UTC (rev 88) @@ -0,0 +1,64 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * 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>. + * #L% + */ + +package fr.ifremer.coser.storage; + +import java.util.List; + +/** + * Data storage utiliser pour manipuler dans l'application des + * tableau de String, mais les stocker en back différement. + * + * Cet interface respecte globalement l'interface d'une {@link List}. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface DataStorage extends Iterable<String[]> { + + /** + * Add new data into storage. + * + * @param data data to add + */ + void add(String[] data); + + /** + * Get data at specified index. + * + * @param index index + * @return data at index + */ + String[] get(int index); + + int size(); + + String[] set(int index, String[] data); + + String[] remove(int index); +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryListStorage.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryListStorage.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryListStorage.java 2010-10-22 12:39:55 UTC (rev 88) @@ -0,0 +1,167 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * 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>. + * #L% + */ + +package fr.ifremer.coser.storage; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import au.com.bytecode.opencsv.CSVReader; +import au.com.bytecode.opencsv.CSVWriter; + +/** + * Stockage mémoire des String[] sous forme de String simple. + * + * Beaucoup moins couteux en mémoire que les String[] sans pour antant + * que le temps de parcours soit augmenté. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MemoryListStorage implements DataStorage { + + public List<String> internalStorage; + + public MemoryListStorage() { + internalStorage = new ArrayList<String>(); + } + + public class StringListIterator implements Iterator<String[]> { + + protected Iterator<String> internalIterator; + + public StringListIterator(Iterator<String> internalIterator) { + this.internalIterator = internalIterator; + } + + /* + * @see java.util.Iterator#hasNext() + */ + @Override + public boolean hasNext() { + return internalIterator.hasNext(); + } + + /* + * @see java.util.Iterator#next() + */ + @Override + public String[] next() { + + String nextString = internalIterator.next(); + String[] nextArray = stringToArray(nextString); + + return nextArray; + } + + /* + * @see java.util.Iterator#remove() + */ + @Override + public void remove() { + internalIterator.remove(); + } + } + + /* + * @see java.lang.Iterable#iterator() + */ + @Override + public Iterator<String[]> iterator() { + return new StringListIterator(internalStorage.iterator()); + } + + /* + * @see fr.ifremer.coser.storage.DataStorage#addData(java.lang.String[]) + */ + @Override + public void add(String[] data) { + + String stringData = arrayToString(data); + internalStorage.add(stringData); + } + + protected String arrayToString(String[] data) { + StringWriter writer = new StringWriter(); + CSVWriter csvWriter = new CSVWriter(writer); + csvWriter.writeNext(data); + //TODO echatellier 20101022 replace with custom parsing code + try { + csvWriter.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return writer.toString(); + } + + protected String[] stringToArray(String data) { + StringReader reader = new StringReader(data); + CSVReader csvReader = new CSVReader(reader); + String[] dataArray = null; + //TODO echatellier 20101022 replace with custom parsing code + try { + dataArray = csvReader.readNext(); + csvReader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return dataArray; + } + + /* + * @see fr.ifremer.coser.storage.DataStorage#getData(int) + */ + @Override + public String[] get(int index) { + String stringData = internalStorage.get(index); + String[] dataArray = stringToArray(stringData); + return dataArray; + } + + public int size() { + return internalStorage.size(); + } + + public String[] set(int index, String[] element) { + String data = arrayToString(element); + String old = internalStorage.set(index, data); + String[] oldArray = stringToArray(old); + return oldArray; + } + + public String[] remove(int index) { + String old = internalStorage.remove(index); + String[] oldArray = stringToArray(old); + return oldArray; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryListStorage.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties 2010-10-22 12:36:07 UTC (rev 87) +++ trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties 2010-10-22 12:39:55 UTC (rev 88) @@ -3,10 +3,12 @@ Missing\ file\ %s= Project\ %s\ already\ exist= Project\ %s\ doesn't\ exists\ \!= +Wrong\ header\ detected\ in\ file.\ Find\ \:\ %s,\ expected\ %s= Wrong\ header\ detected\ in\ file.\ Find\ \:\ %s,\ expected\ %s\ or\ %s= coser.business.category.catch=Catch coser.business.category.haul=Haul coser.business.category.length=Length +coser.business.category.reftax.species= coser.business.category.strata=Stata coser.config.database.directory.description= coser.config.projects.directory.description= Modified: trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 2010-10-22 12:36:07 UTC (rev 87) +++ trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 2010-10-22 12:39:55 UTC (rev 88) @@ -1,12 +1,14 @@ Can't\ create\ project=Impossible de cr\u00E9er le projet Can't\ read\ file\ '%s'.\ Check\ CSV\ file\ separator\ (%c)=Impossible de lire le fichier '%s'.\nMerci de v\u00E9rifier le s\u00E9parateur utilis\u00E9 (%c). -Missing\ file\ %s= -Project\ %s\ already\ exist=Le project %s existe d\u00E9j\u00E0 \! -Project\ %s\ doesn't\ exists\ \!= +Missing\ file\ %s=Fichier manquant \: %s +Project\ %s\ already\ exist=Le projet %s existe d\u00E9j\u00E0 \! +Project\ %s\ doesn't\ exists\ \!=Le projet %s n'existe pas \! +Wrong\ header\ detected\ in\ file.\ Find\ \:\ %s,\ expected\ %s=auvais ent\u00EAte de fichier d\u00E9tect\u00E9.\nTrouv\u00E9\u2009\:\n\t%s\nAttendu\u2009\:\n\t%s. Wrong\ header\ detected\ in\ file.\ Find\ \:\ %s,\ expected\ %s\ or\ %s=Mauvais ent\u00EAte de fichier d\u00E9tect\u00E9.\nTrouv\u00E9\u2009\:\n\t%s\nAttendu\u2009\:\n\t%s\nou\u2009\:\n\t%s. coser.business.category.catch=Captures coser.business.category.haul=Traits coser.business.category.length=Tailles +coser.business.category.reftax.species=Reftax (esp\u00E8ce) coser.business.category.strata=Strates coser.config.database.directory.description=Emplacement de la base de campagnes de coser coser.config.projects.directory.description=Emplacement des projets Coser Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlDataTableModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlDataTableModel.java 2010-10-22 12:36:07 UTC (rev 87) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlDataTableModel.java 2010-10-22 12:39:55 UTC (rev 88) @@ -25,12 +25,11 @@ import static org.nuiton.i18n.I18n._; -import java.util.List; - import javax.swing.table.AbstractTableModel; import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.storage.DataStorage; /** * Species and comments check boxed table model. @@ -46,7 +45,7 @@ /** serialVersionUID. */ private static final long serialVersionUID = -1192463259386773117L; - protected List<String[]> data; + protected DataStorage data; protected String[] header; public ControlDataTableModel(ControlView controlView) {