Fix potential NPE
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / matrix / MatrixRowComparator.java
index 124d3be2d641e556b79274687bf4c4494769303c..d9eab66b06af0751edc6b23a181ba0200b0b03df 100644 (file)
@@ -31,9 +31,9 @@ public class MatrixRowComparator implements Comparator<Object>{
     private Comparator<TaxonNode> comparator;
 
     public MatrixRowComparator() {
-        if (PreferencesUtil.getSortNodesNaturally()){
+        if (PreferencesUtil.isNodesSortedNaturally()){
             comparator = new TaxonNaturalComparator();
-        } else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){
+        } else if (PreferencesUtil.isNodesSortedByName()){
             comparator = new TaxonNodeByNameComparator();
         }else {
             comparator = new TaxonNodeByRankAndNameComparator();
@@ -42,12 +42,26 @@ public class MatrixRowComparator implements Comparator<Object>{
 
     @Override
     public int compare(Object o1, Object o2) {
+        if(o1 instanceof TaxonNode){
+            if(o2 instanceof RowWrapperDTO){
+                return 1;
+            }
+        }
+        else{
+            if(o2 instanceof TaxonNode){
+                return -1;
+            }
+        }
         if(o1 instanceof TaxonNode && o2 instanceof TaxonNode){
             return comparator.compare((TaxonNode)o1, (TaxonNode)o2);
         }
         if(o1 instanceof RowWrapperDTO && o2 instanceof RowWrapperDTO){
             RowWrapperDTO rowWrapper1 = (RowWrapperDTO)o1;
             RowWrapperDTO rowWrapper2 = (RowWrapperDTO)o2;
+            //check for equality
+            if(rowWrapper1.equals(rowWrapper2)){
+                return 0;
+            }
             TaxonNode node1 = rowWrapper1.getTaxonNode().getParent();
             TaxonNode node2 = rowWrapper2.getTaxonNode().getParent();
             if(node1!=null && node2!=null){