+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
package eu.etaxonomy.cdm.api.service;\r
\r
import java.util.ArrayList;\r
NamedArea area = new NamedArea();\r
Distribution data = Distribution.NewInstance();\r
data.setArea(area);\r
- data.addModifyingText("test", Language.ENGLISH());\r
+ data.putModifyingText(Language.ENGLISH(), "test");\r
TreeNode<Distribution> rootElement = new TreeNode<Distribution>();\r
List<TreeNode<Distribution>> children = new ArrayList<TreeNode<Distribution>>();\r
\r
return result;\r
}\r
\r
+ private List<Distribution> orderDistributionsByLevel(List<Distribution> distList){\r
+ boolean flag = true;\r
+ int length = distList.size()-1;\r
+ Distribution dist;\r
+ List<Distribution> orderedList = new ArrayList<Distribution>(length);\r
+ orderedList.addAll(distList);\r
+ \r
+ for (int i = 0; i < length && flag; i++) {\r
+ flag = false;\r
+ for (int j = 0; j < length-1; j++) {\r
+ String level1 = orderedList.get(j).getArea().getLevel().toString();\r
+ String level2 = orderedList.get(j+1).getArea().getLevel().toString();\r
+ //if level from j+1 is greater than level from j\r
+ if (level2.compareTo(\r
+ level1) < 0) {\r
+ dist = orderedList.get(j);\r
+ orderedList.set(j, orderedList.get(j+1));\r
+ orderedList.set(j+1, dist);\r
+ flag = true; \r
+ }\r
+ }\r
+ }\r
+ return orderedList;\r
+ }\r
+ \r
public void merge(List<Distribution> distList, Set<NamedAreaLevel> omitLevels){\r
- for (Distribution distribution : distList) {\r
+ List<Distribution> orderedDistList = orderDistributionsByLevel(distList);\r
+ \r
+ for (Distribution distribution : orderedDistList) {\r
List<NamedArea> levelList = \r
this.getAreaLevelPathList(distribution.getArea(), omitLevels);\r
mergeAux(distribution, distribution.getArea().getLevel(), levelList, this.getRootElement());\r
TreeNode<Distribution> root){\r
TreeNode<Distribution> highestDistNode;\r
TreeNode<Distribution> child;// the new child to add or the child to follow through the tree\r
+ \r
//if the list to merge is empty finish the execution\r
if (areaHierarchieList.isEmpty()) {\r
return;\r
highestDistNode = new TreeNode<Distribution>(data);\r
}\r
if(highestDistNode.data.getModifyingText().isEmpty()){\r
- highestDistNode.data.addModifyingText("test", Language.ENGLISH());\r
+ highestDistNode.data.putModifyingText(Language.ENGLISH(), "test");\r
}\r
\r
if (root.getChildren().isEmpty() || !containsChild(root, highestDistNode)) {\r