Revision 7af46cd8
Added by Andreas Müller almost 2 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetComparator.java | ||
---|---|---|
34 | 34 |
public class TypeDesignationSetComparator implements Comparator<TypeDesignationSet> { |
35 | 35 |
|
36 | 36 |
//not yet used |
37 |
enum ORDER_BY{ |
|
37 |
public enum ORDER_BY{
|
|
38 | 38 |
TYPE_STATUS, |
39 | 39 |
BASE_ENTITY; |
40 | 40 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetContainer.java | ||
---|---|---|
22 | 22 |
import java.util.UUID; |
23 | 23 |
|
24 | 24 |
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException; |
25 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetComparator.ORDER_BY; |
|
25 | 26 |
import eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator; |
26 | 27 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
27 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
... | ... | |
90 | 91 |
public static TypeDesignationSetContainer NewInstance(@SuppressWarnings("rawtypes") Collection<TypeDesignationBase> typeDesignations, |
91 | 92 |
TypeDesignationSetComparator.ORDER_BY orderBy) |
92 | 93 |
throws TypeDesignationSetException{ |
93 |
TypeDesignationSetContainer result = new TypeDesignationSetContainer(typeDesignations); |
|
94 |
result.typeDesignationSetComparator = new TypeDesignationSetComparator(orderBy); |
|
94 |
TypeDesignationSetContainer result = new TypeDesignationSetContainer(typeDesignations, null, orderBy); |
|
95 | 95 |
return result; |
96 | 96 |
} |
97 | 97 |
|
... | ... | |
99 | 99 |
|
100 | 100 |
private TypeDesignationSetContainer(@SuppressWarnings("rawtypes") Collection<TypeDesignationBase> typeDesignations) |
101 | 101 |
throws TypeDesignationSetException{ |
102 |
this(typeDesignations, null); |
|
102 |
this(typeDesignations, null, null);
|
|
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
public TypeDesignationSetContainer(@SuppressWarnings("rawtypes") Collection<TypeDesignationBase> typeDesignations, |
106 |
TaxonName typifiedName) |
|
106 |
TaxonName typifiedName, ORDER_BY orderBy)
|
|
107 | 107 |
throws TypeDesignationSetException { |
108 |
|
|
109 |
if (orderBy != null) { |
|
110 |
typeDesignationSetComparator = new TypeDesignationSetComparator(orderBy); |
|
111 |
} |
|
108 | 112 |
for (TypeDesignationBase<?> typeDes:typeDesignations){ |
109 | 113 |
this.typeDesignations.put(typeDes.getUuid(), typeDes); |
110 | 114 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetContainerTest.java | ||
---|---|---|
181 | 181 |
} |
182 | 182 |
|
183 | 183 |
@Test |
184 |
public void test1() throws TypeDesignationSetException{
|
|
184 |
public void testOrder() throws TypeDesignationSetException{
|
|
185 | 185 |
|
186 | 186 |
@SuppressWarnings("rawtypes") |
187 | 187 |
List<TypeDesignationBase> tds = new ArrayList<>(); |
... | ... | |
200 | 200 |
typifiedName.addTypeDesignation(std_IT_2, false); |
201 | 201 |
typifiedName.addTypeDesignation(std_IT_3, false); |
202 | 202 |
|
203 |
TypeDesignationSetContainer typeDesignationManager = TypeDesignationSetContainer.NewDefaultInstance(tds); |
|
203 |
//order by base entity |
|
204 |
TypeDesignationSetComparator.ORDER_BY orderByBaseEntity = TypeDesignationSetComparator.ORDER_BY.BASE_ENTITY; |
|
205 |
TypeDesignationSetContainer typeDesignationManager = TypeDesignationSetContainer.NewInstance(tds, orderByBaseEntity); |
|
204 | 206 |
String result = typeDesignationManager.print(WITH_CITATION, WITH_TYPE_LABEL, WITH_NAME); |
205 | 207 |
|
206 | 208 |
assertNotNull(result); |
... | ... | |
219 | 221 |
assertEquals("isotype", keyIt_1.next().getLabel()); |
220 | 222 |
assertEquals("holotype", keyIt_2.next().getLabel()); |
221 | 223 |
assertEquals("isotype", keyIt_2.next().getLabel()); |
224 |
|
|
225 |
//order by type status |
|
226 |
TypeDesignationSetComparator.ORDER_BY orderByTypeStatus = TypeDesignationSetComparator.ORDER_BY.TYPE_STATUS; |
|
227 |
typeDesignationManager = TypeDesignationSetContainer.NewInstance(tds, orderByTypeStatus); |
|
228 |
result = typeDesignationManager.print(WITH_CITATION, WITH_TYPE_LABEL, WITH_NAME); |
|
229 |
|
|
230 |
assertNotNull(result); |
|
231 |
assertEquals( |
|
232 |
"Prionus L.\u202F\u2013\u202FTypes: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: OHA; isotypes: BER, KEW);" |
|
233 |
+ " Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 (isotype: M);" |
|
234 |
+ " nametype: Prionus coriatius L." |
|
235 |
, result |
|
236 |
); |
|
237 |
|
|
238 |
orderedTypeDesignations = typeDesignationManager.getOrderedTypeDesignationSets(); |
|
239 |
byStatusMapIterator = orderedTypeDesignations.values().iterator(); |
|
240 |
keyIt_1 = byStatusMapIterator.next().keySet().iterator(); |
|
241 |
keyIt_2 = byStatusMapIterator.next().keySet().iterator(); |
|
242 |
assertEquals("holotype", keyIt_1.next().getLabel()); |
|
243 |
assertEquals("isotype", keyIt_1.next().getLabel()); |
|
244 |
assertEquals("isotype", keyIt_2.next().getLabel()); |
|
222 | 245 |
} |
223 | 246 |
|
224 | 247 |
@Test |
Also available in: Unified diff
fix #10089 final fixes for TypeDesignationSet formatting ordered by type status