2026-04-08 10:42:58 +02:00
|
|
|
package ecoparasite.poisson;
|
|
|
|
|
|
|
|
|
|
import ecoparasite.input.DataParsing;
|
|
|
|
|
import ecoparasite.input.InvalidParsingException;
|
|
|
|
|
import ecoparasite.input.RawData;
|
|
|
|
|
import ecoparasite.input.RawDataOverflow;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import static java.lang.Double.valueOf;
|
|
|
|
|
|
2026-04-08 11:29:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Classe MackerelSerra créer pour le fichier test2.csv
|
|
|
|
|
* cette classe existe principalement pour l'évaluation
|
|
|
|
|
*/
|
2026-04-08 10:42:58 +02:00
|
|
|
public class MackerelSerra extends Poisson implements DataParsing {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructeur de MackerelSerra
|
|
|
|
|
* @param length
|
|
|
|
|
* @param infestation
|
|
|
|
|
*/
|
|
|
|
|
public MackerelSerra(String id, Double length, Double infestation) {
|
|
|
|
|
super(id, length, null, infestation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implémentation de la fonction parse de DataParsing.
|
|
|
|
|
* Renvoie un tableau de poissons à partir d'un RawData.
|
|
|
|
|
*
|
|
|
|
|
* @param data Notre RawData
|
|
|
|
|
* @param parseTypeId L'ID du type de parsing, ignoré ici.
|
|
|
|
|
* @return Le tableau de poissons.
|
|
|
|
|
* @throws RawDataOverflow Si on a un dépassement de données dans notre RawData.
|
|
|
|
|
* @throws InvalidParsingException
|
|
|
|
|
*/
|
|
|
|
|
public static HashSet<Poisson> parse(RawData data, int parseTypeId) throws RawDataOverflow, InvalidParsingException {
|
|
|
|
|
return MackerelSerra.parse(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implémentation de la fonction parse de Dataparsing
|
|
|
|
|
* @param data Notre RawData.
|
|
|
|
|
* @return tableau des poissons
|
|
|
|
|
* @throws RawDataOverflow Si on a un dépassement de données dans notre RawDataOverflow.
|
|
|
|
|
*/
|
|
|
|
|
public static HashSet<Poisson> parse(RawData data) throws RawDataOverflow {
|
|
|
|
|
|
|
|
|
|
HashMap<String,String> temp = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
HashSet<Poisson> fishSet;
|
|
|
|
|
fishSet = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < data.getData().getFirst().size(); i++) {
|
|
|
|
|
|
|
|
|
|
temp = data.getEntry(i);
|
|
|
|
|
|
|
|
|
|
String id = !Objects.equals(temp.get("id"), "") ? (temp.get("id")) : null;
|
|
|
|
|
Double size = !Objects.equals(temp.get("LT"), "") ? valueOf(temp.get("LT")) : null;
|
|
|
|
|
Double infes = !Objects.equals(temp.get("Total"), "") ? valueOf(temp.get("Total")) : null;
|
|
|
|
|
|
|
|
|
|
Poisson newP = new MackerelSerra(id,size,infes);
|
|
|
|
|
newP.setFishParts( MackerelSerra.parsePartiePoisson(temp) );
|
|
|
|
|
fishSet.add(newP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fishSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-08 11:29:35 +02:00
|
|
|
* Implementation de parsePartiePoisson de l'interface DataParsing
|
|
|
|
|
* @param entry correspond à notre liste temporaire lu dans parse pour chacun des poissons
|
|
|
|
|
* @return envoie un tableau de partie de Poisson à ajouter à notre poisson
|
2026-04-08 10:42:58 +02:00
|
|
|
*/
|
|
|
|
|
private static HashSet<PartiePoisson> parsePartiePoisson(HashMap<String,String> entry){
|
|
|
|
|
|
|
|
|
|
HashSet<PartiePoisson> response = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( String k: entry.keySet() ){
|
|
|
|
|
if( k.contains("Foie") || k.contains("Abdomen") || k.contains("Visceres") || k.contains("Autres")){
|
|
|
|
|
String bodyPart = k;
|
|
|
|
|
Double value = !Objects.equals(entry.get(k), "") ? valueOf(entry.get(k)) : null;
|
|
|
|
|
PartiePoisson p = new PartiePoisson(bodyPart, value);
|
|
|
|
|
response.add(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|