Project

General

Profile

Revision 7f1d6816

ID7f1d68168f78f3208ee0e5837ed777118175a570
Parent 65611564
Child 4ca3e4f3

Added by Patrick Plitzner almost 4 years ago

ref #7095 Optimize aggregation and display of description elements

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/AggregationConfiguration.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11
import java.util.HashSet;
12
import java.util.Set;
13

  
14
import org.apache.commons.lang.StringUtils;
11 15
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
12 16
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
13 17
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
......
20 24
import eu.etaxonomy.cdm.model.description.CategoricalData;
21 25
import eu.etaxonomy.cdm.model.description.Feature;
22 26
import eu.etaxonomy.cdm.model.description.QuantitativeData;
23
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
27
import eu.etaxonomy.cdm.model.description.State;
24 28

  
25 29
/**
26 30
 * @author pplitzner
......
79 83
                    }
80 84
                }
81 85
            }
82
            String summaryString = "";
83
            if(minTotal!=null){
84
                summaryString += "from "+minTotal;
85
            }
86
            if(maxTotal!=null){
87
                summaryString += " up to "+maxTotal;
88
            }
86
            String summaryString = (minTotal==null?"?":minTotal.toString())
87
                    +" - "
88
                    +(maxTotal==null?"?":maxTotal.toString());
89 89
            return summaryString;
90 90
        }
91 91
    }
......
93 93
    private class CategoricalSummaryProvider implements ISummaryProvider {
94 94
        @Override
95 95
        public Object summarize(int columnIndex) {
96
            String summaryString = "";
97
            String separator = ", ";
98 96
            int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
97
            Set<State> states = new HashSet<>();
99 98
            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
100 99
                Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
101 100
                        rowIndex);
102 101
                if(dataValue instanceof CategoricalData){
103 102
                    CategoricalData categoricalData = (CategoricalData)dataValue;
104
                    summaryString += DescriptionHelper.getLabel(categoricalData)+separator;
103
                    states.addAll(categoricalData.getStatesOnly());
105 104
                }
106 105
            }
107
            if(summaryString.length()>separator.length()){
108
                summaryString = summaryString.substring(0, summaryString.length()-separator.length());
109
            }
110
            return summaryString;
106
            return StringUtils.join(states, ", ");
111 107
        }
112 108
    }
113

  
114 109
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11
import java.util.HashSet;
12
import java.util.Set;
13
import java.util.UUID;
14

  
11 15
import eu.etaxonomy.cdm.model.description.CategoricalData;
12 16
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
13 17
import eu.etaxonomy.cdm.model.description.QuantitativeData;
......
20 24
public class DescriptionElementCompareWrapper {
21 25

  
22 26
    private DescriptionElementBase element;
27
    private Set<UUID> stateUuids = new HashSet<>();
28
    private Float min = null;
29
    private Float max = null;
23 30

  
24 31
    public DescriptionElementCompareWrapper(DescriptionElementBase element) {
25 32
        this.element = element;
33
        if(element.isInstanceOf(CategoricalData.class)){
34
            CategoricalData elementData = (CategoricalData)element;
35
            elementData.getStatesOnly().forEach(state->stateUuids.add(state.getUuid()));
36
        }
37
        else if(element.isInstanceOf(QuantitativeData.class)){
38
            QuantitativeData elementData = (QuantitativeData)element;
39
            min = elementData.getMin();
40
            max = elementData.getMax();
41
        }
26 42
    }
27 43

  
28 44
    public DescriptionElementBase unwrap() {
29 45
        return element;
30 46
    }
31 47

  
32
    public boolean equals(DescriptionElementCompareWrapper other) {
33
        DescriptionElementBase otherElement = other.unwrap();
34
        //TODO: Implement more elaborate equals() method
35
        if(element.isInstanceOf(CategoricalData.class) && otherElement instanceof CategoricalData){
36
            boolean equal = true;
37
            CategoricalData otherData = (CategoricalData)otherElement;
38
            CategoricalData elementData = (CategoricalData)element;
39
            equal &= elementData.getStatesOnly().equals(otherData.getStatesOnly());
40
            return equal;
48
    /**
49
     * {@inheritDoc}
50
     */
51
    @Override
52
    public int hashCode() {
53
        final int prime = 31;
54
        int result = 1;
55
        result = prime * result + ((max == null) ? 0 : max.hashCode());
56
        result = prime * result + ((min == null) ? 0 : min.hashCode());
57
        result = prime * result + ((stateUuids == null) ? 0 : stateUuids.hashCode());
58
        return result;
59
    }
60

  
61
    /**
62
     * {@inheritDoc}
63
     */
64
    @Override
65
    public boolean equals(Object obj) {
66
        if (this == obj) {
67
            return true;
41 68
        }
42
        if(element.isInstanceOf(QuantitativeData.class) && otherElement instanceof QuantitativeData){
43
            boolean equal = true;
44
            QuantitativeData otherData = (QuantitativeData)otherElement;
45
            QuantitativeData elementData = (QuantitativeData)element;
46
            if(elementData.getMin()!=null && otherData.getMin()==null){
47
                return false;
48
            }
49
            if(elementData.getMin()==null && otherData.getMin()!=null){
69
        if (obj == null) {
70
            return false;
71
        }
72
        if (getClass() != obj.getClass()) {
73
            return false;
74
        }
75
        DescriptionElementCompareWrapper other = (DescriptionElementCompareWrapper) obj;
76
        if (max == null) {
77
            if (other.max != null) {
50 78
                return false;
51 79
            }
52
            if(elementData.getMax()==null && otherData.getMax()!=null){
80
        } else if (!max.equals(other.max)) {
81
            return false;
82
        }
83
        if (min == null) {
84
            if (other.min != null) {
53 85
                return false;
54 86
            }
55
            if(elementData.getMax()!=null && otherData.getMax()==null){
87
        } else if (!min.equals(other.min)) {
88
            return false;
89
        }
90
        if (stateUuids == null) {
91
            if (other.stateUuids != null) {
56 92
                return false;
57 93
            }
58
            if(elementData.getMin()!=null && otherData.getMin()!=null){
59
                equal &= elementData.getMin().equals(otherData.getMin());
60
            }
61
            if(elementData.getMax()!=null && otherData.getMax()!=null){
62
                equal &= elementData.getMax().equals(otherData.getMax());
63
            }
64
            return equal;
94
        } else if (!stateUuids.equals(other.stateUuids)) {
95
            return false;
65 96
        }
66
        return false;
97
        return true;
67 98
    }
68 99

  
69 100
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)