Revision d014205f
Added by Andreas Müller about 6 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/SpecimenTypeDesignation.java | ||
---|---|---|
56 | 56 |
}) |
57 | 57 |
@Entity |
58 | 58 |
@Audited |
59 |
public class SpecimenTypeDesignation extends TypeDesignationBase<SpecimenTypeDesignationStatus> implements ITypeDesignation, Cloneable { |
|
59 |
public class SpecimenTypeDesignation |
|
60 |
extends TypeDesignationBase<SpecimenTypeDesignationStatus> |
|
61 |
implements ITypeDesignation, Cloneable { |
|
60 | 62 |
private static final long serialVersionUID = 6481627446997275007L; |
61 | 63 |
private static final Logger logger = Logger.getLogger(SpecimenTypeDesignation.class); |
62 | 64 |
|
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TypeDesignationBase.java | ||
---|---|---|
244 | 244 |
* Clones <i>this</i> type designation. This is a shortcut that enables to create |
245 | 245 |
* a new instance that differs only slightly from <i>this</i> type designation by |
246 | 246 |
* modifying only some of the attributes.<BR> |
247 |
* CAUTION: the typifiedNames set is not cloned but empty after cloning as the typified |
|
247 |
* CAUTION: the typifiedNames set is also cloned by adding the new type designation |
|
248 |
* to the typifiedNames of the original type designation. If this is unwanted |
|
249 |
* th |
|
250 |
* |
|
251 |
* not cloned but empty after cloning as the typified |
|
248 | 252 |
* names is considered to be the not owning part of a bidirectional relationship. |
249 | 253 |
* This may be changed in future. |
250 | 254 |
* |
... | ... | |
255 | 259 |
*/ |
256 | 260 |
@Override |
257 | 261 |
public Object clone() throws CloneNotSupportedException { |
258 |
TypeDesignationBase result = (TypeDesignationBase)super.clone();
|
|
262 |
TypeDesignationBase<?> result = (TypeDesignationBase<?>)super.clone();
|
|
259 | 263 |
|
264 |
//typified names |
|
260 | 265 |
result.typifiedNames = new HashSet<>(); |
261 |
// for (TaxonName taxonName : getTypifiedNames()){ |
|
262 |
// result.typifiedNames.add(taxonName); |
|
263 |
// } |
|
264 |
|
|
266 |
for (TaxonName taxonName : getTypifiedNames()){ |
|
267 |
taxonName.addTypeDesignation(result, false); |
|
268 |
} |
|
269 |
//registrations |
|
270 |
result.registrations = new HashSet<>(); |
|
271 |
for (Registration registration : registrations){ |
|
272 |
registration.addTypeDesignation(result); |
|
273 |
} |
|
265 | 274 |
|
266 | 275 |
//no changes to: notDesignated, typeStatus, homotypicalGroup |
267 | 276 |
return result; |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/name/NameTypeDesignationStatusTest.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
/** |
24 | 24 |
* @author a.babadshanjan |
25 |
* @created 24.03.2009
|
|
25 |
* @since 24.03.2009
|
|
26 | 26 |
*/ |
27 | 27 |
public class NameTypeDesignationStatusTest extends EntityTestBase { |
28 | 28 |
@SuppressWarnings("unused") |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/name/TypeDesignationBaseTest.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.model.name; |
|
10 |
|
|
11 |
import org.junit.Assert; |
|
12 |
import org.junit.Before; |
|
13 |
import org.junit.Test; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer; |
|
16 |
import eu.etaxonomy.cdm.model.common.Language; |
|
17 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
18 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
19 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
20 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author a.mueller |
|
24 |
* @since 18.04.2018 |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class TypeDesignationBaseTest { |
|
28 |
|
|
29 |
/** |
|
30 |
* @throws java.lang.Exception |
|
31 |
*/ |
|
32 |
@Before |
|
33 |
public void setUp() throws Exception { |
|
34 |
if (Language.DEFAULT() == null){ |
|
35 |
new DefaultTermInitializer().initialize(); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* Test method for {@link TypeDesignationStatusBase#clone()}. |
|
41 |
*/ |
|
42 |
@SuppressWarnings("cast") |
|
43 |
@Test |
|
44 |
public void testClone(){ |
|
45 |
DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen); |
|
46 |
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
47 |
SpecimenTypeDesignationStatus status = SpecimenTypeDesignationStatus.HOLOTYPE(); |
|
48 |
Reference citation = ReferenceFactory.newBook(); |
|
49 |
String microCitation = "p. 123"; |
|
50 |
String originalNameString = "orig. name"; |
|
51 |
boolean isNotDesignated = true; |
|
52 |
SpecimenTypeDesignation originalDesignation = name1.addSpecimenTypeDesignation(specimen, status, |
|
53 |
citation, microCitation, originalNameString, isNotDesignated, false); |
|
54 |
Registration registration1 = Registration.NewInstance(); |
|
55 |
registration1.addTypeDesignation(originalDesignation); |
|
56 |
|
|
57 |
//pre assert |
|
58 |
Assert.assertTrue(originalDesignation instanceof TypeDesignationBase); |
|
59 |
Assert.assertEquals(1, name1.getTypeDesignations().size()); |
|
60 |
Assert.assertTrue(name1.getTypeDesignations().contains(originalDesignation)); |
|
61 |
Assert.assertTrue(originalDesignation.getRegistrations().contains(registration1)); |
|
62 |
Assert.assertNotNull(status); |
|
63 |
|
|
64 |
//clone |
|
65 |
SpecimenTypeDesignation clonedDesignation = (SpecimenTypeDesignation)originalDesignation.clone(); |
|
66 |
|
|
67 |
//post assert |
|
68 |
Assert.assertEquals(2, name1.getTypeDesignations().size()); |
|
69 |
Assert.assertTrue(name1.getTypeDesignations().contains(clonedDesignation)); |
|
70 |
Assert.assertTrue(clonedDesignation.getTypifiedNames().contains(name1)); |
|
71 |
Assert.assertEquals(2, registration1.getTypeDesignations().size()); |
|
72 |
Assert.assertTrue(registration1.getTypeDesignations().contains(clonedDesignation)); |
|
73 |
Assert.assertTrue(clonedDesignation.getRegistrations().contains(registration1)); |
|
74 |
|
|
75 |
Assert.assertSame(citation, clonedDesignation.getCitation()); |
|
76 |
Assert.assertSame(status, clonedDesignation.getTypeStatus()); |
|
77 |
|
|
78 |
} |
|
79 |
} |
Also available in: Unified diff
ref #7357 implement clone correctly for TypeDesignationBase