Project

General

Profile

Revision ef195399

IDef19539965272c4eda60b3aea34ae9a653676fab
Parent 6c1d8f53
Child 732ecf64

Added by Andreas Müller almost 3 years ago

try to fix NPE in TaxonNodeByRankAndNameComparator

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNodeByRankAndNameComparator.java
10 10

  
11 11
import java.io.Serializable;
12 12
import java.util.Comparator;
13
import java.util.UUID;
13 14

  
14 15
import eu.etaxonomy.cdm.model.name.Rank;
15 16
import eu.etaxonomy.cdm.model.name.TaxonName;
......
32 33
		TaxonBase<?> taxon1 = node1.getTaxon();
33 34
		TaxonBase<?> taxon2 = node2.getTaxon();
34 35

  
35
		TaxonName name1 = taxon1.getName();
36
		TaxonName name2 = taxon2.getName();
36
		TaxonName name1 = (taxon1 == null) ? null : taxon1.getName();
37
		TaxonName name2 = (taxon2 == null) ? null : taxon2.getName();
37 38

  
38 39
		Rank rankTax1 = (name1 == null) ? null : name1.getRank();
39 40
		Rank rankTax2 = (name2 == null) ? null : name2.getRank();
......
50 51
				//same rank, order by name
51 52
				int result = name1.compareToName(name2);
52 53
				if (result == 0){
53
					return taxon1.getUuid().compareTo(taxon2.getUuid());
54
					return getTaxonUuid(taxon1, node1).compareTo(getTaxonUuid(taxon2, node2));
54 55
				}else{
55 56
					return result;
56 57
				}
57 58
			}else {
58 59
				//this is maybe not 100% correct, we need to compare name cases, but it is a very rare case
59
				return taxon1.getTitleCache().compareTo(taxon2.getTitleCache());
60
				return getTaxonTitle(taxon1, node1).compareTo(getTaxonTitle(taxon2, node2));
60 61
			}
61 62
		}else{
62 63
			//rankTax2.isHigher(rankTax1)
......
64 65
		}
65 66
	}
66 67

  
68
    /**
69
     * @param taxon1
70
     * @return
71
     */
72
    public String getTaxonTitle(TaxonBase<?> taxon, TaxonNode node) {
73
        return (taxon == null) ? node.getUuid().toString(): taxon.getTitleCache();
74
    }
75

  
76
    /**
77
     * @param taxon
78
     * @param node
79
     * @return
80
     */
81
    private UUID getTaxonUuid(TaxonBase<?> taxon, TaxonNode node) {
82
        return (taxon == null) ? node.getUuid(): taxon.getUuid();
83
    }
84

  
67 85

  
68 86

  
69 87
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)