93 lines
2.9 KiB
Java
93 lines
2.9 KiB
Java
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;
|
|
|
|
/**
|
|
* Hérite de Poisson.
|
|
* Ajoute les fonctions de Parsing liés aux données collectées sur le Mackerel.
|
|
*/
|
|
public class Mackerel extends Poisson implements DataParsing {
|
|
|
|
/**
|
|
* Constructeur de Mackerel
|
|
* @param length
|
|
* @param infestation
|
|
*/
|
|
public Mackerel(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 Mackerel.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("Sample_code"), "") ? temp.get("Sample_code") : null;
|
|
Double size = !Objects.equals(temp.get("StandardLength"), "") ? valueOf(temp.get("StandardLength")) : null;
|
|
Double infes = !Objects.equals(temp.get("NParasitesTotal"), "") ? valueOf(temp.get("NParasitesTotal")) : null;
|
|
|
|
Poisson newP = new Mackerel(id,size,infes);
|
|
newP.setFishParts( Mackerel.parsePartiePoisson(temp) );
|
|
fishSet.add(newP);
|
|
}
|
|
|
|
|
|
return fishSet;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param entry
|
|
* @return
|
|
*/
|
|
private static HashSet<PartiePoisson> parsePartiePoisson(HashMap<String,String> entry){
|
|
|
|
HashSet<PartiePoisson> response = new HashSet<>();
|
|
|
|
for( String k: entry.keySet() ){
|
|
if( k.contains( "Anisakis_" ) ){
|
|
String bodyPart = k.split( "Anisakis_" )[1];
|
|
Double value = !Objects.equals(entry.get(k), "") ? valueOf(entry.get(k)) : null;
|
|
PartiePoisson p = new PartiePoisson(bodyPart, value);
|
|
response.add(p);
|
|
}
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|