1 package eu
.etaxonomy
.cdm
.api
.service
;
3 import java
.util
.Iterator
;
7 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
8 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
9 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
10 import eu
.etaxonomy
.cdm
.model
.description
.NaturalLanguageTerm
;
11 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
12 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
13 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
14 import eu
.etaxonomy
.cdm
.model
.description
.TextFormat
;
16 public class DefaultQuantitativeDescriptionBuilder
extends AbstractQuantitativeDescriptionBuilder
{
19 protected TextData
doBuild(Map
<StatisticalMeasure
,Float
> measures
, MeasurementUnit mUnit
){
20 StringBuilder QuantitativeDescription
= new StringBuilder();
21 TextData textData
= TextData
.NewInstance();
22 Language language
= Language
.DEFAULT();
24 boolean average
= false;
25 float averagevalue
= new Float(0);
27 float sdvalue
= new Float(0);
29 float minvalue
= new Float(0);
31 float maxvalue
= new Float(0);
32 boolean lowerb
= false;
33 float lowerbvalue
= new Float(0);
34 boolean upperb
= false;
35 float upperbvalue
= new Float(0);
37 String unit
= mUnit
.getLabel();
39 NaturalLanguageTerm nltFrom
= NaturalLanguageTerm
.FROM();
40 String from
= nltFrom
.getPreferredRepresentation(language
).getLabel();
41 NaturalLanguageTerm nltTo
= NaturalLanguageTerm
.TO();
42 String to
= nltTo
.getPreferredRepresentation(language
).getLabel();
43 NaturalLanguageTerm nltUp_To
= NaturalLanguageTerm
.UP_TO();
44 String up_To
= nltUp_To
.getPreferredRepresentation(language
).getLabel();
45 NaturalLanguageTerm nltMost_Frequently
= NaturalLanguageTerm
.MOST_FREQUENTLY();
46 String most_Frequently
= nltMost_Frequently
.getPreferredRepresentation(language
).getLabel();
47 NaturalLanguageTerm nltOn_Average
= NaturalLanguageTerm
.ON_AVERAGE();
48 String on_Average
= nltOn_Average
.getPreferredRepresentation(language
).getLabel();
49 NaturalLanguageTerm nltMore_Or_Less
= NaturalLanguageTerm
.MORE_OR_LESS();
50 String more_Or_Less
= nltMore_Or_Less
.getPreferredRepresentation(language
).getLabel();
53 if (measures
.containsKey(StatisticalMeasure
.AVERAGE())) {
55 averagevalue
= measures
.get(StatisticalMeasure
.AVERAGE());
56 } else if(measures
.containsKey(StatisticalMeasure
.STANDARD_DEVIATION())) {
58 sdvalue
= measures
.get(StatisticalMeasure
.STANDARD_DEVIATION());
59 } else if (measures
.containsKey(StatisticalMeasure
.MIN())) {
61 minvalue
= measures
.get(StatisticalMeasure
.MIN());
62 } else if (measures
.containsKey(StatisticalMeasure
.MAX())) {
64 maxvalue
= measures
.get(StatisticalMeasure
.MAX());
65 } else if (measures
.containsKey(StatisticalMeasure
.TYPICAL_LOWER_BOUNDARY())) {
67 lowerbvalue
= measures
.get(StatisticalMeasure
.TYPICAL_LOWER_BOUNDARY());
68 } else if (measures
.containsKey(StatisticalMeasure
.TYPICAL_UPPER_BOUNDARY())) {
70 upperbvalue
= measures
.get(StatisticalMeasure
.TYPICAL_UPPER_BOUNDARY());
74 QuantitativeDescription
.append(space
+ from
+ space
+ minvalue
+ space
+ to
+ space
+ maxvalue
+ space
+ unit
);
77 QuantitativeDescription
.append(space
+ from
+ space
+ minvalue
+ space
+ unit
);
80 QuantitativeDescription
.append(space
+ up_To
+ space
+ maxvalue
+ space
+ unit
);
82 if ((max
||min
)&&(lowerb
||upperb
)) {
83 QuantitativeDescription
.append(","); // fusion avec dessous ?
85 if ((lowerb
||upperb
)&&(min
||max
)) {
86 QuantitativeDescription
.append(space
+ most_Frequently
+ space
);
88 if (upperb
&& lowerb
) {
89 QuantitativeDescription
.append(space
+ from
+ space
+ lowerbvalue
+ space
+ to
+ space
+ upperbvalue
+ space
+ unit
);
92 QuantitativeDescription
.append(space
+ from
+ lowerbvalue
+ space
+ unit
);
95 QuantitativeDescription
.append(space
+ up_To
+ space
+ upperbvalue
+ space
+ unit
);
97 if (((max
||min
)&&(average
))||((lowerb
||upperb
)&&(average
))) {
98 QuantitativeDescription
.append(",");
101 QuantitativeDescription
.append(space
+ averagevalue
+ space
+ unit
+ space
+ on_Average
);
103 QuantitativeDescription
.append("("+ more_Or_Less
+ space
+ sdvalue
+ ")");
106 textData
.putText(QuantitativeDescription
.toString(), language
);
107 textData
.setFormat(TextFormat
.NewInstance(null, "HTML",null ));