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
|
|
10
|
package eu.etaxonomy.cdm.model.taxon;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Calendar;
|
14
|
import java.util.Collections;
|
15
|
import java.util.List;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.After;
|
19
|
import org.junit.AfterClass;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.BeforeClass;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
25
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
27
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
28
|
//import eu.etaxonomy.cdm.model.reference.Book;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
30
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @created 11.06.2008
|
35
|
* @version 1.0
|
36
|
*/
|
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
|
}
|
67
|
|
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
|
ReferenceBase sec = refFactory.newBook();
|
79
|
|
80
|
ReferenceBase ref1 = refFactory.newBook();
|
81
|
ReferenceBase ref2 = refFactory.newBook();
|
82
|
ReferenceBase 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));
|
91
|
// 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
|
}
|
134
|
}
|