Project

General

Profile

Download (2.88 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.descriptiveDataSet.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
 * Wrapper class for comparing description elements
21
 * @author pplitzner
22
 * @since Jan 18, 2018
23
 *
24
 */
25
public class DescriptionElementCompareWrapper {
26

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

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

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

    
49
    /**
50
     * {@inheritDoc}
51
     */
52
    @Override
53
    public int hashCode() {
54
        final int prime = 31;
55
        int result = 1;
56
        result = prime * result + ((max == null) ? 0 : max.hashCode());
57
        result = prime * result + ((min == null) ? 0 : min.hashCode());
58
        result = prime * result + ((stateUuids == null) ? 0 : stateUuids.hashCode());
59
        return result;
60
    }
61

    
62
    /**
63
     * {@inheritDoc}
64
     */
65
    @Override
66
    public boolean equals(Object obj) {
67
        if (this == obj) {
68
            return true;
69
        }
70
        if (obj == null) {
71
            return false;
72
        }
73
        if (getClass() != obj.getClass()) {
74
            return false;
75
        }
76
        DescriptionElementCompareWrapper other = (DescriptionElementCompareWrapper) obj;
77
        if (max == null) {
78
            if (other.max != null) {
79
                return false;
80
            }
81
        } else if (!max.equals(other.max)) {
82
            return false;
83
        }
84
        if (min == null) {
85
            if (other.min != null) {
86
                return false;
87
            }
88
        } else if (!min.equals(other.min)) {
89
            return false;
90
        }
91
        if (stateUuids == null) {
92
            if (other.stateUuids != null) {
93
                return false;
94
            }
95
        } else if (!stateUuids.equals(other.stateUuids)) {
96
            return false;
97
        }
98
        return true;
99
    }
100

    
101
}
102

    
(4-4/9)