Revision 363387d2
Added by Andreas Müller almost 8 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DistributionTree.java | ||
---|---|---|
13 | 13 |
import java.util.ArrayList; |
14 | 14 |
import java.util.Collection; |
15 | 15 |
import java.util.Collections; |
16 |
import java.util.Comparator; |
|
16 | 17 |
import java.util.HashSet; |
17 | 18 |
import java.util.List; |
18 | 19 |
import java.util.Set; |
... | ... | |
21 | 22 |
import org.hibernate.proxy.HibernateProxy; |
22 | 23 |
|
23 | 24 |
import eu.etaxonomy.cdm.api.utility.DescriptionUtility; |
25 |
import eu.etaxonomy.cdm.api.utility.DistributionOrder; |
|
24 | 26 |
import eu.etaxonomy.cdm.common.Tree; |
25 | 27 |
import eu.etaxonomy.cdm.common.TreeNode; |
26 | 28 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
... | ... | |
60 | 62 |
} |
61 | 63 |
|
62 | 64 |
/** |
65 |
* Returns the (first) child node (of type TreeNode) with the given nodeID. |
|
63 | 66 |
* @param parentNode |
64 | 67 |
* @param nodeToFind |
65 | 68 |
* @return the found node or null |
... | ... | |
82 | 85 |
* @param omitLevels |
83 | 86 |
* @param hiddenAreaMarkerTypes |
84 | 87 |
* Areas not associated to a Distribution in the {@code distList} are detected as fall back area |
85 |
* if they are having a {@link Marker} with one of the specified {@link MarkerType}s. Areas identified as such
|
|
86 |
* are omitted from the hierarchy and the sub areas are moving one level up. |
|
88 |
* if they are having a {@link Marker} with one of the specified {@link MarkerType}s. Areas identified |
|
89 |
* as such are omitted from the hierarchy and the sub areas are moving one level up.
|
|
87 | 90 |
* For more details on fall back areas see <b>Marked area filter</b> of |
88 | 91 |
* {@link DescriptionUtility#filterDistributions(Collection, Set, boolean, boolean, boolean)}. |
89 | 92 |
*/ |
90 |
public void orderAsTree(Collection<Distribution> distList, Set<NamedAreaLevel> omitLevels, Set<MarkerType> hiddenAreaMarkerTypes){ |
|
93 |
public void orderAsTree(Collection<Distribution> distList, |
|
94 |
Set<NamedAreaLevel> omitLevels, |
|
95 |
Set<MarkerType> hiddenAreaMarkerTypes){ |
|
91 | 96 |
|
92 | 97 |
Set<NamedArea> areas = new HashSet<NamedArea>(distList.size()); |
93 | 98 |
for (Distribution distribution : distList) { |
... | ... | |
130 | 135 |
|
131 | 136 |
} |
132 | 137 |
|
133 |
public void recursiveSortChildrenByLabel(){ |
|
134 |
_recursiveSortChildrenByLabel(this.getRootElement()); |
|
138 |
public void recursiveSortChildren(DistributionOrder distributionOrder){ |
|
139 |
if (distributionOrder == null){ |
|
140 |
distributionOrder = DistributionOrder.getDefault(); |
|
141 |
} |
|
142 |
_recursiveSortChildren(this.getRootElement(), distributionOrder.getComparator()); |
|
135 | 143 |
} |
136 | 144 |
|
137 |
private void _recursiveSortChildrenByLabel(TreeNode<Set<Distribution>, NamedArea> treeNode){
|
|
138 |
DistributionNodeByAreaLabelComparator comp = new DistributionNodeByAreaLabelComparator();
|
|
145 |
private void _recursiveSortChildren(TreeNode<Set<Distribution>, NamedArea> treeNode,
|
|
146 |
Comparator<TreeNode<Set<Distribution>, NamedArea>> comparator){
|
|
139 | 147 |
if (treeNode.children == null) { |
140 | 148 |
//nothing => stop condition |
141 | 149 |
return; |
142 | 150 |
}else { |
143 |
Collections.sort(treeNode.children, comp); |
|
151 |
Collections.sort(treeNode.children, comparator);
|
|
144 | 152 |
for (TreeNode<Set<Distribution>, NamedArea> child : treeNode.children) { |
145 |
_recursiveSortChildrenByLabel(child);
|
|
153 |
_recursiveSortChildren(child, comparator);
|
|
146 | 154 |
} |
147 | 155 |
} |
148 | 156 |
} |
... | ... | |
163 | 171 |
* root element of the sub tree to which the |
164 | 172 |
* <code>distributionElement</code> is to be added |
165 | 173 |
*/ |
166 |
private void addDistributionToSubTree(Distribution distribution, List<NamedArea> namedAreaPath, TreeNode<Set<Distribution>, NamedArea> root){ |
|
174 |
private void addDistributionToSubTree(Distribution distribution, |
|
175 |
List<NamedArea> namedAreaPath, |
|
176 |
TreeNode<Set<Distribution>, NamedArea> root){ |
|
167 | 177 |
|
168 | 178 |
|
169 | 179 |
//if the list to merge is empty finish the execution |
Also available in: Unified diff
Implement natural ordering for distributions in data portal #5677