Revision 8de80607
Added by Andreas Kohlbecker over 12 years ago
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/taxon/TaxonComparatorTest.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
35 | 35 |
* @version 1.0 |
36 | 36 |
*/ |
37 | 37 |
public class TaxonComparatorTest { |
38 |
private static final Logger logger = Logger.getLogger(TaxonComparatorTest.class);
|
|
39 |
|
|
40 |
/**
|
|
41 |
* @throws java.lang.Exception
|
|
42 |
*/
|
|
43 |
@BeforeClass
|
|
44 |
public static void setUpBeforeClass() throws Exception {
|
|
45 |
}
|
|
46 |
|
|
47 |
/**
|
|
48 |
* @throws java.lang.Exception
|
|
49 |
*/
|
|
50 |
@AfterClass
|
|
51 |
public static void tearDownAfterClass() throws Exception {
|
|
52 |
}
|
|
53 |
|
|
54 |
/**
|
|
55 |
* @throws java.lang.Exception
|
|
56 |
*/
|
|
57 |
@Before
|
|
58 |
public void setUp() throws Exception {
|
|
59 |
}
|
|
60 |
|
|
61 |
/**
|
|
62 |
* @throws java.lang.Exception
|
|
63 |
*/
|
|
64 |
@After
|
|
65 |
public void tearDown() throws Exception {
|
|
66 |
}
|
|
38 |
private static final Logger logger = Logger.getLogger(TaxonComparatorTest.class);
|
|
39 |
|
|
40 |
/**
|
|
41 |
* @throws java.lang.Exception
|
|
42 |
*/
|
|
43 |
@BeforeClass
|
|
44 |
public static void setUpBeforeClass() throws Exception {
|
|
45 |
}
|
|
46 |
|
|
47 |
/**
|
|
48 |
* @throws java.lang.Exception
|
|
49 |
*/
|
|
50 |
@AfterClass
|
|
51 |
public static void tearDownAfterClass() throws Exception {
|
|
52 |
}
|
|
53 |
|
|
54 |
/**
|
|
55 |
* @throws java.lang.Exception
|
|
56 |
*/
|
|
57 |
@Before
|
|
58 |
public void setUp() throws Exception {
|
|
59 |
}
|
|
60 |
|
|
61 |
/**
|
|
62 |
* @throws java.lang.Exception
|
|
63 |
*/
|
|
64 |
@After
|
|
65 |
public void tearDown() throws Exception {
|
|
66 |
}
|
|
67 | 67 |
|
68 | 68 |
/******************** TESTS *****************************************************/ |
69 |
|
|
70 |
/** |
|
71 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonComparator#compare(eu.etaxonomy.cdm.model.taxon.TaxonBase, eu.etaxonomy.cdm.model.taxon.TaxonBase)}. |
|
72 |
*/ |
|
73 |
@Test |
|
74 |
public void testCompare() { |
|
75 |
logger.debug("start testCompare"); |
|
76 |
ReferenceFactory refFactory = ReferenceFactory.newInstance(); |
|
77 |
|
|
78 |
Reference sec = refFactory.newBook(); |
|
79 |
|
|
80 |
Reference ref1 = refFactory.newBook(); |
|
81 |
Reference ref2 = refFactory.newBook(); |
|
82 |
Reference ref3 = refFactory.newBook(); |
|
83 |
Calendar cal1 = Calendar.getInstance(); |
|
84 |
Calendar cal2 = Calendar.getInstance(); |
|
85 |
Calendar cal3 = Calendar.getInstance(); |
|
86 |
cal1.set(1945, 3, 2); |
|
87 |
cal2.set(1856, 3, 2); |
|
88 |
cal3.set(1943, 3, 2); |
|
89 |
|
|
90 |
ref1.setDatePublished(TimePeriod.NewInstance(cal1)); |
|
69 |
|
|
70 |
/** |
|
71 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonComparator#compare(eu.etaxonomy.cdm.model.taxon.TaxonBase, eu.etaxonomy.cdm.model.taxon.TaxonBase)}. |
|
72 |
*/ |
|
73 |
@Test |
|
74 |
public void testCompare() { |
|
75 |
logger.debug("start testCompare"); |
|
76 |
|
|
77 |
Reference sec = ReferenceFactory.newBook(); |
|
78 |
|
|
79 |
Reference ref1 = ReferenceFactory.newBook(); |
|
80 |
Reference ref2 = ReferenceFactory.newBook(); |
|
81 |
Reference ref3 = ReferenceFactory.newBook(); |
|
82 |
Calendar cal1 = Calendar.getInstance(); |
|
83 |
Calendar cal2 = Calendar.getInstance(); |
|
84 |
Calendar cal3 = Calendar.getInstance(); |
|
85 |
cal1.set(1945, 3, 2); |
|
86 |
cal2.set(1856, 3, 2); |
|
87 |
cal3.set(1943, 3, 2); |
|
88 |
|
|
89 |
ref1.setDatePublished(TimePeriod.NewInstance(cal1)); |
|
91 | 90 |
// ref2.setDatePublished(TimePeriod.NewInstance(cal2)); |
92 |
ref3.setDatePublished(TimePeriod.NewInstance(cal3));
|
|
93 |
|
|
94 |
BotanicalName botName1 = BotanicalName.NewInstance(null);
|
|
95 |
BotanicalName botName2 = BotanicalName.NewInstance(null);
|
|
96 |
BotanicalName botName3 = BotanicalName.NewInstance(null);
|
|
97 |
ZoologicalName zooName1 = ZoologicalName.NewInstance(null);
|
|
98 |
|
|
99 |
botName1.setNomenclaturalReference(ref1);
|
|
100 |
botName2.setNomenclaturalReference(ref2);
|
|
101 |
botName3.setNomenclaturalReference(ref3);
|
|
102 |
zooName1.setPublicationYear(1823);
|
|
103 |
|
|
104 |
List<TaxonBase> list = new ArrayList<TaxonBase>();
|
|
105 |
|
|
106 |
Taxon taxon1 = Taxon.NewInstance(botName1, sec);
|
|
107 |
Taxon taxon2 = Taxon.NewInstance(botName2, sec);
|
|
108 |
Taxon taxon3 = Taxon.NewInstance(botName3, sec);
|
|
109 |
Taxon zooTaxon4 = Taxon.NewInstance(zooName1, sec);
|
|
110 |
|
|
111 |
taxon1.setId(1);
|
|
112 |
taxon2.setId(2);
|
|
113 |
taxon3.setId(3);
|
|
114 |
zooTaxon4.setId(4);
|
|
115 |
|
|
116 |
|
|
117 |
list.add(taxon3);
|
|
118 |
list.add(taxon2);
|
|
119 |
list.add(taxon1);
|
|
120 |
list.add(zooTaxon4);
|
|
121 |
Collections.sort(list, new TaxonComparator());
|
|
122 |
|
|
123 |
for (TaxonBase taxon : list){
|
|
124 |
String year = "";
|
|
125 |
TaxonNameBase<?,?> tnb = taxon.getName();
|
|
126 |
if (tnb instanceof ZoologicalName){
|
|
127 |
year = String.valueOf(((ZoologicalName)tnb).getPublicationYear());
|
|
128 |
}else{
|
|
129 |
year = tnb.getNomenclaturalReference().getYear();
|
|
130 |
}
|
|
131 |
System.out.println(taxon.getId() + ": " + year);
|
|
132 |
}
|
|
133 |
}
|
|
91 |
ref3.setDatePublished(TimePeriod.NewInstance(cal3));
|
|
92 |
|
|
93 |
BotanicalName botName1 = BotanicalName.NewInstance(null);
|
|
94 |
BotanicalName botName2 = BotanicalName.NewInstance(null);
|
|
95 |
BotanicalName botName3 = BotanicalName.NewInstance(null);
|
|
96 |
ZoologicalName zooName1 = ZoologicalName.NewInstance(null);
|
|
97 |
|
|
98 |
botName1.setNomenclaturalReference(ref1);
|
|
99 |
botName2.setNomenclaturalReference(ref2);
|
|
100 |
botName3.setNomenclaturalReference(ref3);
|
|
101 |
zooName1.setPublicationYear(1823);
|
|
102 |
|
|
103 |
List<TaxonBase> list = new ArrayList<TaxonBase>();
|
|
104 |
|
|
105 |
Taxon taxon1 = Taxon.NewInstance(botName1, sec);
|
|
106 |
Taxon taxon2 = Taxon.NewInstance(botName2, sec);
|
|
107 |
Taxon taxon3 = Taxon.NewInstance(botName3, sec);
|
|
108 |
Taxon zooTaxon4 = Taxon.NewInstance(zooName1, sec);
|
|
109 |
|
|
110 |
taxon1.setId(1);
|
|
111 |
taxon2.setId(2);
|
|
112 |
taxon3.setId(3);
|
|
113 |
zooTaxon4.setId(4);
|
|
114 |
|
|
115 |
|
|
116 |
list.add(taxon3);
|
|
117 |
list.add(taxon2);
|
|
118 |
list.add(taxon1);
|
|
119 |
list.add(zooTaxon4);
|
|
120 |
Collections.sort(list, new TaxonComparator());
|
|
121 |
|
|
122 |
for (TaxonBase taxon : list){
|
|
123 |
String year = "";
|
|
124 |
TaxonNameBase<?,?> tnb = taxon.getName();
|
|
125 |
if (tnb instanceof ZoologicalName){
|
|
126 |
year = String.valueOf(((ZoologicalName)tnb).getPublicationYear());
|
|
127 |
}else{
|
|
128 |
year = tnb.getNomenclaturalReference().getYear();
|
|
129 |
}
|
|
130 |
System.out.println(taxon.getId() + ": " + year);
|
|
131 |
}
|
|
132 |
}
|
|
134 | 133 |
} |
Also available in: Unified diff
fixing #1925 (CICHORIEAE taxon tree order of taxa and bastards)
and also moving ITaxonNodeComparator into model