Project

General

Profile

Download (2.95 KB) Statistics
| Branch: | Tag: | Revision:
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
	@Override
52
    public Iterator<TaxonBase> iterator() {
53
		return new TaxonIterator(taxon);
54
	}
55

    
56
	class TaxonIterator implements Iterator<TaxonBase> {
57

    
58
		List<TaxonBase> synonymyList;
59
		int index = 0;
60

    
61
		public TaxonIterator(Taxon taxon) {
62
			synonymyList = new ArrayList<TaxonBase>();
63
			HomotypicalGroup homotypicGroup = taxon.getHomotypicGroup();
64

    
65
			if (homotypicGroup != null) {
66
				List<Synonym> homotypicSynonyms = taxon.getSynonymsInGroup(homotypicGroup);
67
				for (Synonym synonym : homotypicSynonyms) {
68

    
69
					// Make sure synonym belongs to the taxon
70
					if (synonym.getAcceptedTaxon() != null && synonym.getAcceptedTaxon().equals(taxon)) {
71
						synonymyList.add(synonym);
72
					}
73
				}
74
			}
75

    
76
			List<HomotypicalGroup> heterotypicGroups = taxon.getHeterotypicSynonymyGroups();
77
			for (HomotypicalGroup heterotypicGroup : heterotypicGroups) {
78

    
79
				// Make sure this is not the taxon's homotypic group
80
				if (!heterotypicGroup.equals(homotypicGroup)) {
81

    
82
					List<Synonym> heterotypicSynonyms = taxon.getSynonymsInGroup(heterotypicGroup);
83
					for (Synonym synonym : heterotypicSynonyms) {
84

    
85
						// Make sure synonym belongs to the taxon
86
						if (synonym.getAcceptedTaxon() != null && synonym.getAcceptedTaxon().equals(taxon)) {
87
							synonymyList.add(synonym);
88
						}
89
					}
90
				}
91
			}
92

    
93
			Set<Taxon> misappliedNames = taxon.getMisappliedNames(true);
94
			for (Taxon misappliedName : misappliedNames) {
95
				synonymyList.add(misappliedName);
96
			}
97

    
98
		}
99

    
100
		@Override
101
        public boolean hasNext() {
102
			if (synonymyList.size() == index) {
103
				return false;
104
			}
105
			return true;
106
		}
107

    
108
		@Override
109
        public TaxonBase next() {
110
			TaxonBase next = synonymyList.get(index);
111
			index++;
112
			return next;
113
		}
114

    
115
		@Override
116
        public void remove() {}
117
	}
118
}
(4-4/19)