Revision a120b5f6
Added by Patrick Plitzner almost 6 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationComparator.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.api.service.name; |
|
10 |
|
|
11 |
import java.util.Comparator; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author pplitzner |
|
17 |
* @since May 3, 2018 |
|
18 |
* |
|
19 |
*/ |
|
20 |
public class TypeDesignationComparator implements Comparator<TypeDesignationBase> { |
|
21 |
|
|
22 |
private TypeDesignationStatusComparator statusComparator = new TypeDesignationStatusComparator(); |
|
23 |
|
|
24 |
@SuppressWarnings("unchecked") |
|
25 |
@Override |
|
26 |
public int compare(TypeDesignationBase o1, TypeDesignationBase o2) { |
|
27 |
if(o1==null){ |
|
28 |
return 1; |
|
29 |
} |
|
30 |
if(o2==null){ |
|
31 |
return -1; |
|
32 |
} |
|
33 |
if(o1.getTypeStatus()==null){ |
|
34 |
return 1; |
|
35 |
} |
|
36 |
if(o2.getTypeStatus()==null){ |
|
37 |
return-1; |
|
38 |
} |
|
39 |
return statusComparator.compare(o1.getTypeStatus(), o2.getTypeStatus()) ; |
|
40 |
} |
|
41 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java | ||
---|---|---|
258 | 258 |
TypeDesignationWorkingSet typeDesignationWorkingSet = stringsByTypeByBaseEntity.get(baseEntityRef); |
259 | 259 |
// order the TypeDesignationStatusBase keys |
260 | 260 |
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationWorkingSet.keySet()); |
261 |
Collections.sort(keyList, new Comparator<TypeDesignationStatusBase>() { |
|
262 |
@SuppressWarnings("unchecked") |
|
263 |
@Override |
|
264 |
public int compare(TypeDesignationStatusBase o1, TypeDesignationStatusBase o2) { |
|
265 |
// fix inverted order of cdm terms by -1* |
|
266 |
if(o1 == null && o2 == null || o1 instanceof NullTypeDesignationStatus && o2 instanceof NullTypeDesignationStatus){ |
|
267 |
return 0; |
|
268 |
} |
|
269 |
if(o1 == null || o1 instanceof NullTypeDesignationStatus){ |
|
270 |
return -1; |
|
271 |
} |
|
272 |
|
|
273 |
if(o2 == null || o2 instanceof NullTypeDesignationStatus){ |
|
274 |
return 1; |
|
275 |
} |
|
276 |
return -1 * o1.compareTo(o2); |
|
277 |
} |
|
278 |
}); |
|
261 |
Collections.sort(keyList, new TypeDesignationStatusComparator()); |
|
279 | 262 |
// new LinkedHashMap for the ordered TypeDesignationStatusBase keys |
280 | 263 |
TypeDesignationWorkingSet orderedStringsByOrderedTypes = new TypeDesignationWorkingSet( |
281 | 264 |
typeDesignationWorkingSet.getBaseEntity(), |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationStatusComparator.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.api.service.name; |
|
10 |
|
|
11 |
import java.util.Comparator; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager.NullTypeDesignationStatus; |
|
14 |
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; |
|
15 |
|
|
16 |
/** |
|
17 |
* @author pplitzner |
|
18 |
* @since May 3, 2018 |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class TypeDesignationStatusComparator implements Comparator<TypeDesignationStatusBase> { |
|
22 |
@SuppressWarnings("unchecked") |
|
23 |
@Override |
|
24 |
public int compare(TypeDesignationStatusBase o1, TypeDesignationStatusBase o2) { |
|
25 |
// fix inverted order of cdm terms by -1* |
|
26 |
if(o1 == null && o2 == null || o1 instanceof NullTypeDesignationStatus && o2 instanceof NullTypeDesignationStatus){ |
|
27 |
return 0; |
|
28 |
} |
|
29 |
if(o1 == null || o1 instanceof NullTypeDesignationStatus){ |
|
30 |
return -1; |
|
31 |
} |
|
32 |
|
|
33 |
if(o2 == null || o2 instanceof NullTypeDesignationStatus){ |
|
34 |
return 1; |
|
35 |
} |
|
36 |
return -1 * o1.compareTo(o2); |
|
37 |
} |
|
38 |
} |
Also available in: Unified diff
ref #6526 extract comparator and add another for TypeDesignationBase