61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
|
|
package ecoparasite.population;
|
||
|
|
|
||
|
|
public class PopulationArgInterval {
|
||
|
|
|
||
|
|
private Double min;
|
||
|
|
private Double max;
|
||
|
|
|
||
|
|
private Double mean;
|
||
|
|
|
||
|
|
public PopulationArgInterval(Double min, Double max, Double mean) {
|
||
|
|
this.min = min;
|
||
|
|
this.max = max;
|
||
|
|
this.mean = mean;
|
||
|
|
}
|
||
|
|
public PopulationArgInterval(Double min, Double max) {
|
||
|
|
this.min = min;
|
||
|
|
this.max = max;
|
||
|
|
this.mean = ( this.max + this.min ) / 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Double getMin() {
|
||
|
|
return this.min;
|
||
|
|
}
|
||
|
|
public Double getMax() {
|
||
|
|
return this.max;
|
||
|
|
}
|
||
|
|
public Double getMean() {
|
||
|
|
return this.mean;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Double transformToDouble(){
|
||
|
|
if( this.min == this.max )
|
||
|
|
return this.min;
|
||
|
|
return this.mean;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static PopulationArgInterval fromString( String rawValue ){
|
||
|
|
|
||
|
|
if( rawValue.contains( "±" ) ){ // Plus ou moins.
|
||
|
|
|
||
|
|
String[] numbers = rawValue.split("±");
|
||
|
|
Double mean = Double.parseDouble(numbers[0].trim());
|
||
|
|
Double interval = Double.parseDouble(numbers[1].trim());
|
||
|
|
return new PopulationArgInterval(mean - interval, mean + interval, mean);
|
||
|
|
|
||
|
|
} else if( rawValue.contains( "-" ) ){ // Entre.
|
||
|
|
|
||
|
|
String[] numbers = rawValue.split("-");
|
||
|
|
Double min = Double.parseDouble(numbers[0].trim());
|
||
|
|
Double max = Double.parseDouble(numbers[1].trim());
|
||
|
|
return new PopulationArgInterval(min, max);
|
||
|
|
|
||
|
|
} else {
|
||
|
|
Double number = Double.parseDouble(rawValue);
|
||
|
|
return new PopulationArgInterval(number, number);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|