ref #7095 Optimize aggregation and display of description elements
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Jan 2018 12:48:08 +0000 (13:48 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Jan 2018 12:48:08 +0000 (13:48 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/AggregationConfiguration.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java

index 79a3cbf74481546f1c8548ad5fc4ce66d1d6437b..053af4ecf9d88387fca6bf693419034c52c8f32c 100644 (file)
@@ -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, ", ");
         }
     }
-
 }
index e2d5049b9e11f5ce42f31350abb7e27f92f1faa3..13f3eb2767cb30c99a91a516db0ae729adc65194 100644 (file)
@@ -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;
     }
 
 }