Project

General

Profile

« Previous | Next » 

Revision 444b9ebc

Added by Patrick Plitzner about 5 years ago

minor

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptionBuilder.java
10 10

  
11 11
/**
12 12
 * Abstract class that defines the basic element for constructing natural language descriptions.
13
 * 
13
 *
14 14
 * @author m.venin
15 15
 *
16 16
 */
17 17
public abstract class DescriptionBuilder<T extends DescriptionElementBase> {
18
	
18

  
19 19
	protected String separator = ",";// the basic separator, used for example to separate states when building a description
20 20
	// of a CategoricalData
21 21
	private int option = 0; // option used to return either the text, the label or the abbreviation of a Representation.
22 22
	// By default a builder returns the label
23
	
24
	
23

  
24

  
25 25
	/**
26 26
	 * Sets the builder to return the abbreviation contained in the Representation element of an object
27 27
	 */
28 28
	public void returnAbbreviatedLabels() {
29 29
		option=1;
30 30
	}
31
	
31

  
32 32
	/**
33 33
	 * Sets the builder to return the text contained in the Representation element of an object
34 34
	 */
35 35
	public void returnTexts() {
36 36
		option=2;
37 37
	}
38
	
38

  
39 39
	/**
40 40
	 * Sets the builder to return the label contained in the Representation element of an object
41 41
	 */
42 42
	public void returnLabels() {
43 43
		option=0;
44 44
	}
45
	
45

  
46 46
	public void setSeparator(String newSeparator) {
47 47
		separator = newSeparator;
48 48
	}
49
	
49

  
50 50
	public String getSeparator() {
51 51
		return separator;
52 52
	}
53
	
53

  
54 54
	/**
55 55
	 * Returns the TextData element with the description of the according DescriptionElement
56
	 * 
56
	 *
57 57
	 * @param descriptionElement
58 58
	 * @param languages
59 59
	 * @return
60 60
	 */
61 61
	public abstract TextData build(T descriptionElement, List<Language> languages);
62
	
62

  
63 63
	/**
64 64
	 * Returns either the text, label or abbreviation of a Representation
65 65
	 * @param representation
......
69 69
		String result;
70 70
		if (option==1){
71 71
			result = representation.getAbbreviatedLabel();
72
			if (result != null) return result;
72
			if (result != null) {
73
                return result;
74
            }
73 75
		}
74 76
		else if (option==2){
75 77
			result = representation.getText();
76
			if (result != null) return result;
78
			if (result != null) {
79
                return result;
80
            }
77 81
		}
78 82
		return representation.getLabel();
79 83
	}
80
	
81
	
84

  
85

  
82 86
	/**
83 87
	 * Returns a TextData with the name of the feature.
84
	 * 
88
	 *
85 89
	 * @param feature
86 90
	 * @param languages
87 91
	 * @return
......
89 93
	public TextData buildTextDataFeature(Feature feature, List<Language> languages){
90 94
		return TextData.NewInstance(getRightText(feature.getPreferredRepresentation(languages)),languages.get(0),null);
91 95
	}
92
	
96

  
93 97
}

Also available in: Unified diff