1 package eu
.etaxonomy
.cdm
.api
.service
;
5 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
6 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
7 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
8 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
9 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
12 * Abstract class that defines the basic element for constructing natural language descriptions.
17 public abstract class DescriptionBuilder
<T
extends DescriptionElementBase
> {
19 protected String separator
= ",";// the basic separator, used for example to separate states when building a description
20 // of a CategoricalData
21 private int option
= 0; // option used to return either the text, the label or the abbreviation of a Representation.
22 // By default a builder returns the label
26 * Sets the builder to return the abbreviation contained in the Representation element of an object
28 public void returnAbbreviatedLabels() {
33 * Sets the builder to return the text contained in the Representation element of an object
35 public void returnTexts() {
40 * Sets the builder to return the label contained in the Representation element of an object
42 public void returnLabels() {
46 public void setSeparator(String newSeparator
) {
47 separator
= newSeparator
;
50 public String
getSeparator() {
55 * Returns the TextData element with the description of the according DescriptionElement
57 * @param descriptionElement
61 public abstract TextData
build(T descriptionElement
, List
<Language
> languages
);
64 * Returns either the text, label or abbreviation of a Representation
65 * @param representation
68 protected String
getRightText(Representation representation
){
71 result
= representation
.getAbbreviatedLabel();
72 if (result
!= null) return result
;
75 result
= representation
.getText();
76 if (result
!= null) return result
;
78 return representation
.getLabel();
83 * Returns a TextData with the name of the feature.
89 public TextData
buildTextDataFeature(Feature feature
, List
<Language
> languages
){
90 return TextData
.NewInstance(getRightText(feature
.getPreferredRepresentation(languages
)),languages
.get(0),null);