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.navigation.navigator;
|
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
|
/**
|
38
|
* <p>Constructor for IterableSynonymyList.</p>
|
39
|
*
|
40
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
41
|
*/
|
42
|
public IterableSynonymyList(Taxon taxon) {
|
43
|
this.taxon = taxon;
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* <p>iterator</p>
|
48
|
*
|
49
|
* @return a {@link java.util.Iterator} object.
|
50
|
*/
|
51
|
public Iterator<TaxonBase> iterator() {
|
52
|
return new TaxonIterator(taxon);
|
53
|
}
|
54
|
|
55
|
class TaxonIterator implements Iterator<TaxonBase> {
|
56
|
|
57
|
List<TaxonBase> synonymyList;
|
58
|
int index = 0;
|
59
|
|
60
|
public TaxonIterator(Taxon taxon) {
|
61
|
synonymyList = new ArrayList<TaxonBase>();
|
62
|
HomotypicalGroup homotypicGroup = taxon.getHomotypicGroup();
|
63
|
|
64
|
if (homotypicGroup != null) {
|
65
|
List<Synonym> homotypicSynonyms = taxon.getSynonymsInGroup(homotypicGroup);
|
66
|
for (Synonym synonym : homotypicSynonyms) {
|
67
|
|
68
|
// Make sure synonym belongs to the taxon
|
69
|
if (synonym.getAcceptedTaxa().contains(taxon)) {
|
70
|
synonymyList.add(synonym);
|
71
|
}
|
72
|
}
|
73
|
}
|
74
|
|
75
|
List<HomotypicalGroup> heterotypicGroups = taxon.getHeterotypicSynonymyGroups();
|
76
|
for (HomotypicalGroup heterotypicGroup : heterotypicGroups) {
|
77
|
|
78
|
// Make sure this is not the taxon's homotypic group
|
79
|
if (!heterotypicGroup.equals(homotypicGroup)) {
|
80
|
|
81
|
List<Synonym> heterotypicSynonyms = taxon.getSynonymsInGroup(heterotypicGroup);
|
82
|
for (Synonym synonym : heterotypicSynonyms) {
|
83
|
|
84
|
// Make sure synonym belongs to the taxon
|
85
|
if (synonym.getAcceptedTaxa().contains(taxon)) {
|
86
|
synonymyList.add(synonym);
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
|
92
|
Set<Taxon> misappliedNames = taxon.getMisappliedNames();
|
93
|
for (Taxon misappliedName : misappliedNames) {
|
94
|
synonymyList.add(misappliedName);
|
95
|
}
|
96
|
|
97
|
}
|
98
|
|
99
|
public boolean hasNext() {
|
100
|
if (synonymyList.size() == index) {
|
101
|
return false;
|
102
|
}
|
103
|
return true;
|
104
|
}
|
105
|
|
106
|
public TaxonBase next() {
|
107
|
TaxonBase next = synonymyList.get(index);
|
108
|
index++;
|
109
|
return next;
|
110
|
}
|
111
|
|
112
|
public void remove() {}
|
113
|
}
|
114
|
}
|