Project

General

Profile

Download (2.82 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2018 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10

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

    
15
import eu.etaxonomy.cdm.model.description.CategoricalData;
16
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
17
import eu.etaxonomy.cdm.model.description.QuantitativeData;
18

    
19
/**
20
 * @author pplitzner
21
 * @since Jan 18, 2018
22
 *
23
 */
24
public class DescriptionElementCompareWrapper {
25

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

    
31
    public DescriptionElementCompareWrapper(DescriptionElementBase element) {
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
        }
42
    }
43

    
44
    public DescriptionElementBase unwrap() {
45
        return element;
46
    }
47

    
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;
68
        }
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) {
78
                return false;
79
            }
80
        } else if (!max.equals(other.max)) {
81
            return false;
82
        }
83
        if (min == null) {
84
            if (other.min != null) {
85
                return false;
86
            }
87
        } else if (!min.equals(other.min)) {
88
            return false;
89
        }
90
        if (stateUuids == null) {
91
            if (other.stateUuids != null) {
92
                return false;
93
            }
94
        } else if (!stateUuids.equals(other.stateUuids)) {
95
            return false;
96
        }
97
        return true;
98
    }
99

    
100
}
101

    
(4-4/10)