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.taxeditor.store.model;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Iterator;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
18
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
21
|
|
22
|
/**
|
23
|
* Retrieves the elements of a <code>Taxon</code>'s synonymy list, including misapplied names,
|
24
|
* using an iterator.
|
25
|
* <p>
|
26
|
* Note: does not return an entry for the <code>Taxon</code> itself.
|
27
|
* </p>
|
28
|
*
|
29
|
* @author p.ciardelli
|
30
|
* @created 09.05.2008
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class IterableSynonymyList implements Iterable<TaxonBase> {
|
34
|
|
35
|
private Taxon taxon;
|
36
|
|
37
|
public IterableSynonymyList(Taxon taxon) {
|
38
|
this.taxon = taxon;
|
39
|
}
|
40
|
|
41
|
public Iterator<TaxonBase> iterator() {
|
42
|
return new TaxonIterator(taxon);
|
43
|
}
|
44
|
|
45
|
class TaxonIterator implements Iterator<TaxonBase> {
|
46
|
|
47
|
List<TaxonBase> synonymyList;
|
48
|
int index = 0;
|
49
|
|
50
|
public TaxonIterator(Taxon taxon) {
|
51
|
synonymyList = new ArrayList<TaxonBase>();
|
52
|
HomotypicalGroup homotypicGroup = taxon.getHomotypicGroup();
|
53
|
|
54
|
if (homotypicGroup != null) {
|
55
|
List<Synonym> homotypicSynonyms = homotypicGroup.getSynonymsInGroup(taxon.getSec());
|
56
|
for (Synonym synonym : homotypicSynonyms) {
|
57
|
|
58
|
// Make sure synonym belongs to the taxon
|
59
|
if (synonym.getAcceptedTaxa().contains(taxon)) {
|
60
|
synonymyList.add(synonym);
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
|
65
|
List<HomotypicalGroup> heterotypicGroups = taxon.getHeterotypicSynonymyGroups();
|
66
|
for (HomotypicalGroup heterotypicGroup : heterotypicGroups) {
|
67
|
|
68
|
// Make sure this is not the taxon's homotypic group
|
69
|
if (!heterotypicGroup.equals(homotypicGroup)) {
|
70
|
|
71
|
List<Synonym> heterotypicSynonyms = heterotypicGroup.
|
72
|
getSynonymsInGroup(taxon.getSec());
|
73
|
for (Synonym synonym : heterotypicSynonyms) {
|
74
|
|
75
|
// Make sure synonym belongs to the taxon
|
76
|
if (synonym.getAcceptedTaxa().contains(taxon)) {
|
77
|
synonymyList.add(synonym);
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
|
83
|
Set<Taxon> misappliedNames = taxon.getMisappliedNames();
|
84
|
for (Taxon misappliedName : misappliedNames) {
|
85
|
synonymyList.add(misappliedName);
|
86
|
}
|
87
|
|
88
|
}
|
89
|
|
90
|
public boolean hasNext() {
|
91
|
if (synonymyList.size() == index) {
|
92
|
return false;
|
93
|
}
|
94
|
return true;
|
95
|
}
|
96
|
|
97
|
public TaxonBase next() {
|
98
|
TaxonBase next = synonymyList.get(index);
|
99
|
index++;
|
100
|
return next;
|
101
|
}
|
102
|
|
103
|
public void remove() {}
|
104
|
}
|
105
|
}
|