Project

General

Profile

Revision 26cb375c

ID26cb375c0c55740e18aae8b64b6e77f0a248225b
Parent 69e05485
Child 04406518

Added by Andreas Kohlbecker over 8 years ago

deprecating obsoltete classes

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/NamedAreaNodeComparator.java
5 5
import eu.etaxonomy.cdm.common.TreeNode;
6 6
import eu.etaxonomy.cdm.model.location.NamedArea;
7 7

  
8
/**
9
 * @Deprecated unused class, remove?
10
 */
11
@Deprecated
8 12
public class NamedAreaNodeComparator implements Comparator<TreeNode<NamedArea>>{
9 13

  
10
	public int compare(TreeNode<NamedArea> arg0, TreeNode<NamedArea> arg1) {
11
		return arg0.data.getLabel().compareTo(arg1.data.getLabel());
12
	}
14
    @Override
15
    public int compare(TreeNode<NamedArea> arg0, TreeNode<NamedArea> arg1) {
16
        return arg0.data.getLabel().compareTo(arg1.data.getLabel());
17
    }
13 18
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/NamedAreaTree.java
14 14
 * @author f.revilla
15 15
 * @version 1.0
16 16
 * @created 10.06.2010
17
 *
18
 * @Deprecated unused class, remove?
17 19
 */
20
@Deprecated
18 21
public class NamedAreaTree extends Tree<NamedArea>{
19
	
20
	public NamedAreaTree() {
21
		NamedArea data = new NamedArea();
22
		TreeNode<NamedArea> rootElement = new TreeNode<NamedArea>();
23
		List<TreeNode<NamedArea>> children = new ArrayList<TreeNode<NamedArea>>();
24
		
25
		rootElement.setData(data);
26
		rootElement.setChildren(children);
27
		setRootElement(rootElement);
22

  
23
    public NamedAreaTree() {
24
        NamedArea data = new NamedArea();
25
        TreeNode<NamedArea> rootElement = new TreeNode<NamedArea>();
26
        List<TreeNode<NamedArea>> children = new ArrayList<TreeNode<NamedArea>>();
27

  
28
        rootElement.setData(data);
29
        rootElement.setChildren(children);
30
        setRootElement(rootElement);
28 31
    }
29
/*	
32
/*
30 33
    public NamedAreaTree getHiearchieTree(List<NamedArea> areaList) {
31
    	NamedAreaTree result = new NamedAreaTree();
32
    	for (NamedArea area : areaList) {
33
			List<NamedArea> levelList = area.getAreaLevelPathList(area);
34
			result.merge(levelList);
35
		}	    	
36
    	return result;
34
        NamedAreaTree result = new NamedAreaTree();
35
        for (NamedArea area : areaList) {
36
            List<NamedArea> levelList = area.getAreaLevelPathList(area);
37
            result.merge(levelList);
38
        }
39
        return result;
40
    }
41
*/
42
    public void merge(List<NamedArea> areaList, Set<NamedAreaLevel> omitLevels){
43
        for (NamedArea area : areaList) {
44
            List<NamedArea> levelList = this.getAreaLevelPathList(area, omitLevels);
45
            mergeAux(levelList, this.getRootElement());
46
        }
47
    }
48

  
49
    public void sortChildren(){
50
        sortChildrenAux(this.getRootElement());
51
    }
52

  
53
    private void sortChildrenAux(TreeNode<NamedArea> treeNode){
54
        NamedAreaNodeComparator comp = new NamedAreaNodeComparator();
55
        if (treeNode.children == null){
56
            //nothing => stop condition
57
            return;
58
        }else{
59
            Collections.sort(treeNode.children, comp);
60
            for (TreeNode<NamedArea> child : treeNode.children) {
61
                sortChildrenAux(child);
62
            }
63
        }
64
    }
65

  
66
    private void mergeAux(List<NamedArea> areaHierarchieList, TreeNode<NamedArea> root) {
67
        TreeNode<NamedArea> child; // the new child to add or the child to follow through the tree
68
        //if the list to merge is empty finish the execution
69
        if (areaHierarchieList.isEmpty()){
70
            return;
71
        }
72
        //getting the highest area and inserting it into the tree
73
        NamedArea highestArea = areaHierarchieList.get(0);
74
        TreeNode<NamedArea> highestAreaNode = new TreeNode<NamedArea>(highestArea);
75
        //NamedAreaLevel level = highestArea.getLevel();
76
        //List<TreeNode<NamedArea>> children = root.getChildren();
77

  
78
        //if(children == null || !children.contains(highestAreaNode)){
79
        if (root.getChildren().isEmpty() || !root.containsChild(highestAreaNode)){
80
            //if the highest level is not on the depth-1 of the tree we add it.
81
            child = new TreeNode<NamedArea>(highestArea);
82
            root.addChild(child);
83
            //children.add(child);
84
        }else{
85
            //if the deepth-1 of the tree contains the highest area level
86
            //get the subtree or create it in order to continuing merging
87
            child = root.getChild(highestAreaNode);
88
        }
89
        //continue merging with the next highest area of the list.
90
        List<NamedArea> newList = areaHierarchieList.subList(1, areaHierarchieList.size());
91
        mergeAux(newList, child);
92
    }
93

  
94
    private List<NamedArea> getAreaLevelPathList(NamedArea area, Set<NamedAreaLevel> omitLevels){
95
        List<NamedArea> result = new ArrayList<NamedArea>();
96
        if (!omitLevels.contains(area.getLevel())){
97
            result.add(area);
98
        }
99
        while (area.getPartOf() != null) {
100
            area = area.getPartOf();
101
            if (!omitLevels.contains(area.getLevel())){
102
                result.add(0, area);
103
            }
104
        }
105
        return result;
37 106
    }
38
*/	
39
	public void merge(List<NamedArea> areaList, Set<NamedAreaLevel> omitLevels){
40
		for (NamedArea area : areaList) {
41
			List<NamedArea> levelList = this.getAreaLevelPathList(area, omitLevels);
42
			mergeAux(levelList, this.getRootElement());
43
		}
44
	}
45
	
46
	public void sortChildren(){
47
		sortChildrenAux(this.getRootElement());
48
	}	
49
	
50
	private void sortChildrenAux(TreeNode<NamedArea> treeNode){
51
		NamedAreaNodeComparator comp = new NamedAreaNodeComparator();
52
		if (treeNode.children == null){
53
			//nothing => stop condition
54
			return;
55
		}else{
56
			Collections.sort(treeNode.children, comp);
57
			for (TreeNode<NamedArea> child : treeNode.children) {
58
				sortChildrenAux(child);
59
			}
60
		}
61
	}
62
	
63
	private void mergeAux(List<NamedArea> areaHierarchieList, TreeNode<NamedArea> root) {
64
		TreeNode<NamedArea> child; // the new child to add or the child to follow through the tree
65
		//if the list to merge is empty finish the execution
66
		if (areaHierarchieList.isEmpty()){
67
			return;
68
		}
69
		//getting the highest area and inserting it into the tree
70
		NamedArea highestArea = areaHierarchieList.get(0);
71
		TreeNode<NamedArea> highestAreaNode = new TreeNode<NamedArea>(highestArea);
72
		//NamedAreaLevel level = highestArea.getLevel();
73
		//List<TreeNode<NamedArea>> children = root.getChildren();
74
		
75
		//if(children == null || !children.contains(highestAreaNode)){
76
		if (root.getChildren().isEmpty() || !root.containsChild(highestAreaNode)){
77
			//if the highest level is not on the depth-1 of the tree we add it. 
78
			child = new TreeNode<NamedArea>(highestArea);
79
			root.addChild(child);
80
			//children.add(child);
81
		}else{
82
			//if the deepth-1 of the tree contains the highest area level
83
			//get the subtree or create it in order to continuing merging
84
			child = root.getChild(highestAreaNode);				
85
		}
86
		//continue merging with the next highest area of the list.
87
		List<NamedArea> newList = areaHierarchieList.subList(1, areaHierarchieList.size());
88
		mergeAux(newList, child);
89
	}
90
	
91
	private List<NamedArea> getAreaLevelPathList(NamedArea area, Set<NamedAreaLevel> omitLevels){
92
		List<NamedArea> result = new ArrayList<NamedArea>();
93
		if (!omitLevels.contains(area.getLevel())){
94
			result.add(area);		
95
		}
96
		while (area.getPartOf() != null) {
97
			area = area.getPartOf();
98
			if (!omitLevels.contains(area.getLevel())){
99
				result.add(0, area);
100
			}
101
		}
102
		return result;
103
	}
104 107
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)