Revision 96c10a88
fix #5957 fix IndexOutOfBound exception and some other improvements for groupByHigherTaxon
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/ITaxonNodeDao.java | ||
---|---|---|
75 | 75 |
long countTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid, UUID relTypeUuid); |
76 | 76 |
|
77 | 77 |
/** |
78 |
* @param treeIndexClosure |
|
79 |
* @param minRankOrderIndex |
|
80 |
* @param maxRankOrderIndex |
|
78 |
* Computes a map treeIndex->rank(sortIndex) for each given taxon node treeIndex. Required by #5957. |
|
79 |
* If the taxon represented by the treeindex is not in the given rank range no record is returned for the given |
|
80 |
* treeindex. |
|
81 |
* |
|
82 |
* @param treeIndex the list of treeIndexes |
|
83 |
* @param minRankOrderIndex min rank |
|
84 |
* @param maxRankOrderIndex max rank |
|
81 | 85 |
* @return |
82 | 86 |
*/ |
83 |
Map<String, Integer> rankOrderIndexForTreeIndex(List<String> treeIndexClosure, Integer minRankOrderIndex,
|
|
87 |
Map<String, Integer> rankOrderIndexForTreeIndex(List<String> treeIndex, Integer minRankOrderIndex, |
|
84 | 88 |
Integer maxRankOrderIndex); |
85 | 89 |
|
86 | 90 |
/** |
87 |
* @param keySet |
|
88 |
* @return |
|
91 |
* For a given set of taxon node tree indexes the uuid and title cache of the taxon represented |
|
92 |
* by this treeindex is returned. |
|
93 |
* @param treeIndexSet set of taxon node tree indexes |
|
94 |
* @return map with treeindex and uuidAndTitleCache of the represented taxon |
|
89 | 95 |
*/ |
90 |
Map<String, UuidAndTitleCache<?>> taxonUuidsForTreeIndexes(Set<String> keySet);
|
|
96 |
Map<String, UuidAndTitleCache<?>> taxonUuidsForTreeIndexes(Set<String> treeIndexSet);
|
|
91 | 97 |
|
92 | 98 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java | ||
---|---|---|
625 | 625 |
//get treeindex for each taxonUUID |
626 | 626 |
Map<UUID, String> taxonIdTreeIndexMap = dao.treeIndexForTaxonUuids(classificationUuid, originalTaxonUuids); |
627 | 627 |
|
628 |
//build treeindex tree or list
|
|
628 |
//build treeindex list (or tree)
|
|
629 | 629 |
List<String> treeIndexClosure = new ArrayList<>(); |
630 | 630 |
for (String treeIndex : taxonIdTreeIndexMap.values()){ |
631 | 631 |
String[] splits = treeIndex.substring(1).split(ITreeNode.separator); |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TreeIndexComparator.java | ||
---|---|---|
17 | 17 |
* @author a.mueller |
18 | 18 |
* @date 05.07.2016 |
19 | 19 |
* |
20 |
* Comparator for treeindexes. |
|
21 |
* Compares the tree indexes node by node, sorted by node number. |
|
22 |
* If one index is shorter than the other one but |
|
20 | 23 |
*/ |
21 | 24 |
public class TreeIndexComparator implements Comparator<String>{ |
22 | 25 |
|
... | ... | |
29 | 32 |
}else if (treeIndex2 == null){ |
30 | 33 |
return 1; |
31 | 34 |
} |
35 |
if (treeIndex1.equals(treeIndex2)){ |
|
36 |
return 0; |
|
37 |
} |
|
38 |
|
|
32 | 39 |
String[] splits1 = treeIndex1.split(ITreeNode.separator); |
33 | 40 |
String[] splits2 = treeIndex2.split(ITreeNode.separator); |
34 | 41 |
|
35 | 42 |
|
36 |
for (int i=0; i<splits1.length; i++){
|
|
37 |
if (splits2.length < i){ |
|
43 |
for (int i=0; i < splits1.length; i++){
|
|
44 |
if (splits2.length <= i){
|
|
38 | 45 |
return 1; |
39 | 46 |
} |
40 | 47 |
int c = splits1[i].compareTo(splits2[i]); |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/GroupedTaxonDTO.java | ||
---|---|---|
65 | 65 |
public void setGroupTaxonName(String groupTaxonName) { |
66 | 66 |
this.groupTaxonName = groupTaxonName; |
67 | 67 |
} |
68 |
|
|
69 |
//*********************** toString() ***************************/ |
|
70 |
@Override |
|
71 |
public String toString() { |
|
72 |
String result = "taxon:" + (taxonUuid == null? "-":taxonUuid.toString()) |
|
73 |
+ "; group:" + (groupTaxonUuid == null? "-":groupTaxonUuid.toString()) |
|
74 |
+ "; group name:" + (groupTaxonName == null? "-":groupTaxonName.toString()); |
|
75 |
return result; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
68 | 79 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TreeIndexComparatorTest.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.cdm.api.service; |
|
11 |
|
|
12 |
import org.junit.Assert; |
|
13 |
import org.junit.Test; |
|
14 |
|
|
15 |
|
|
16 |
/** |
|
17 |
* @author a.mueller |
|
18 |
* @date 12.09.2016 |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class TreeIndexComparatorTest { |
|
22 |
|
|
23 |
@Test |
|
24 |
public void test() { |
|
25 |
TreeIndexComparator comparator = new TreeIndexComparator(); |
|
26 |
|
|
27 |
//both null |
|
28 |
Assert.assertTrue(0 == comparator.compare(null, null)); |
|
29 |
//one null |
|
30 |
Assert.assertTrue(0 > comparator.compare(null, "#t10#10#")); |
|
31 |
Assert.assertTrue(0 < comparator.compare("#t10#10#", null)); |
|
32 |
//equal |
|
33 |
Assert.assertTrue(0 == comparator.compare("#t10#10#", "#t10#10#")); |
|
34 |
|
|
35 |
//same start |
|
36 |
Assert.assertTrue(0 > comparator.compare("#t10#10#", "#t10#10#20#")); |
|
37 |
Assert.assertTrue(0 < comparator.compare("#t10#10#20#", "#t10#10#")); |
|
38 |
|
|
39 |
//different ends |
|
40 |
Assert.assertTrue(0 > comparator.compare("#t10#10#20#", "#t10#10#30#")); |
|
41 |
Assert.assertTrue(0 < comparator.compare("#t10#10#30#", "#t10#10#20#")); |
|
42 |
|
|
43 |
//different ends |
|
44 |
Assert.assertTrue(0 > comparator.compare("#t10#10#20#", "#t10#10#30#")); |
|
45 |
Assert.assertTrue(0 > comparator.compare("#t10#10#20#", "#t10#10#30#11")); |
|
46 |
|
|
47 |
Assert.assertTrue(0 < comparator.compare("#t10#10#30#", "#t10#10#20#")); |
|
48 |
Assert.assertTrue(0 < comparator.compare("#t10#10#30#11", "#t10#10#20#")); |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
} |
Also available in: Unified diff