1
|
/**
|
2
|
* Copyright (C) 2007 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.model.name;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Collections;
|
14
|
import java.util.Comparator;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.taxon.HomotypicGroupTaxonComparator;
|
19
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonComparator;
|
21
|
|
22
|
public class HomotypicalGroupComparator implements
|
23
|
Comparator<HomotypicalGroup>, Serializable {
|
24
|
private static final long serialVersionUID = -676465815899137107L;
|
25
|
|
26
|
@Override
|
27
|
public int compare(HomotypicalGroup group1, HomotypicalGroup group2) {
|
28
|
TaxonBase<?> firstTypified1 = null;
|
29
|
TaxonBase<?> firstTypified2 = null;
|
30
|
if (group1.equals(group2)){
|
31
|
return 0;
|
32
|
}
|
33
|
TaxonComparator taxComparator = new HomotypicGroupTaxonComparator(null);
|
34
|
Set<TaxonName> typifiedNames1 = group1.getTypifiedNames();
|
35
|
List<TaxonBase> taxonBasesOfTypifiedNames = new ArrayList<>();
|
36
|
for (TaxonName typifiedName:typifiedNames1){
|
37
|
if (!typifiedName.getTaxonBases().isEmpty()){
|
38
|
taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
|
39
|
}
|
40
|
}
|
41
|
Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
|
42
|
firstTypified1 = taxonBasesOfTypifiedNames.get(0);
|
43
|
|
44
|
Set<TaxonName> typifiedNames2 = group2.getTypifiedNames();
|
45
|
taxonBasesOfTypifiedNames = new ArrayList<TaxonBase>();
|
46
|
for (TaxonName typifiedName:typifiedNames2){
|
47
|
if (!typifiedName.getTaxonBases().isEmpty()){
|
48
|
taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
|
49
|
}
|
50
|
}
|
51
|
Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
|
52
|
firstTypified2 = taxonBasesOfTypifiedNames.get(0);
|
53
|
return taxComparator.compare(firstTypified1, firstTypified2);
|
54
|
}
|
55
|
|
56
|
}
|