commit 7f1d68168f78f3208ee0e5837ed777118175a570
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Tue Jan 23 13:48:08 2018 +0100

    ref #7095 Optimize aggregation and display of description elements

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/AggregationConfiguration.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/AggregationConfiguration.java
index 79a3cbf74..053af4ecf 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/AggregationConfiguration.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/AggregationConfiguration.java
@@ -8,6 +8,10 @@
  */
 package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
@@ -20,7 +24,7 @@ import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
-import eu.etaxonomy.taxeditor.model.DescriptionHelper;
+import eu.etaxonomy.cdm.model.description.State;
 
 /**
  * @author pplitzner
@@ -79,13 +83,9 @@ public class AggregationConfiguration extends DefaultSummaryRowConfiguration {
                     }
                 }
             }
-            String summaryString = "";
-            if(minTotal!=null){
-                summaryString += "from "+minTotal;
-            }
-            if(maxTotal!=null){
-                summaryString += " up to "+maxTotal;
-            }
+            String summaryString = (minTotal==null?"?":minTotal.toString())
+                    +" - "
+                    +(maxTotal==null?"?":maxTotal.toString());
             return summaryString;
         }
     }
@@ -93,22 +93,17 @@ public class AggregationConfiguration extends DefaultSummaryRowConfiguration {
     private class CategoricalSummaryProvider implements ISummaryProvider {
         @Override
         public Object summarize(int columnIndex) {
-            String summaryString = "";
-            String separator = ", ";
             int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
+            Set<State> states = new HashSet<>();
             for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
                 Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
                         rowIndex);
                 if(dataValue instanceof CategoricalData){
                     CategoricalData categoricalData = (CategoricalData)dataValue;
-                    summaryString += DescriptionHelper.getLabel(categoricalData)+separator;
+                    states.addAll(categoricalData.getStatesOnly());
                 }
             }
-            if(summaryString.length()>separator.length()){
-                summaryString = summaryString.substring(0, summaryString.length()-separator.length());
-            }
-            return summaryString;
+            return StringUtils.join(states, ", ");
         }
     }
-
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java
index e2d5049b9..13f3eb276 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java
@@ -8,6 +8,10 @@
  */
 package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
 
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
@@ -20,50 +24,77 @@ import eu.etaxonomy.cdm.model.description.QuantitativeData;
 public class DescriptionElementCompareWrapper {
 
     private DescriptionElementBase element;
+    private Set<UUID> stateUuids = new HashSet<>();
+    private Float min = null;
+    private Float max = null;
 
     public DescriptionElementCompareWrapper(DescriptionElementBase element) {
         this.element = element;
+        if(element.isInstanceOf(CategoricalData.class)){
+            CategoricalData elementData = (CategoricalData)element;
+            elementData.getStatesOnly().forEach(state->stateUuids.add(state.getUuid()));
+        }
+        else if(element.isInstanceOf(QuantitativeData.class)){
+            QuantitativeData elementData = (QuantitativeData)element;
+            min = elementData.getMin();
+            max = elementData.getMax();
+        }
     }
 
     public DescriptionElementBase unwrap() {
         return element;
     }
 
-    public boolean equals(DescriptionElementCompareWrapper other) {
-        DescriptionElementBase otherElement = other.unwrap();
-        //TODO: Implement more elaborate equals() method
-        if(element.isInstanceOf(CategoricalData.class) && otherElement instanceof CategoricalData){
-            boolean equal = true;
-            CategoricalData otherData = (CategoricalData)otherElement;
-            CategoricalData elementData = (CategoricalData)element;
-            equal &= elementData.getStatesOnly().equals(otherData.getStatesOnly());
-            return equal;
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((max == null) ? 0 : max.hashCode());
+        result = prime * result + ((min == null) ? 0 : min.hashCode());
+        result = prime * result + ((stateUuids == null) ? 0 : stateUuids.hashCode());
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
         }
-        if(element.isInstanceOf(QuantitativeData.class) && otherElement instanceof QuantitativeData){
-            boolean equal = true;
-            QuantitativeData otherData = (QuantitativeData)otherElement;
-            QuantitativeData elementData = (QuantitativeData)element;
-            if(elementData.getMin()!=null && otherData.getMin()==null){
-                return false;
-            }
-            if(elementData.getMin()==null && otherData.getMin()!=null){
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        DescriptionElementCompareWrapper other = (DescriptionElementCompareWrapper) obj;
+        if (max == null) {
+            if (other.max != null) {
                 return false;
             }
-            if(elementData.getMax()==null && otherData.getMax()!=null){
+        } else if (!max.equals(other.max)) {
+            return false;
+        }
+        if (min == null) {
+            if (other.min != null) {
                 return false;
             }
-            if(elementData.getMax()!=null && otherData.getMax()==null){
+        } else if (!min.equals(other.min)) {
+            return false;
+        }
+        if (stateUuids == null) {
+            if (other.stateUuids != null) {
                 return false;
             }
-            if(elementData.getMin()!=null && otherData.getMin()!=null){
-                equal &= elementData.getMin().equals(otherData.getMin());
-            }
-            if(elementData.getMax()!=null && otherData.getMax()!=null){
-                equal &= elementData.getMax().equals(otherData.getMax());
-            }
-            return equal;
+        } else if (!stateUuids.equals(other.stateUuids)) {
+            return false;
         }
-        return false;
+        return true;
     }
 
 }
