Project

General

Profile

Download (1.83 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.cdm.ref;
10

    
11
import java.io.Serializable;
12
import java.util.UUID;
13

    
14
import org.apache.commons.lang3.builder.HashCodeBuilder;
15

    
16
/**
17
 * @author a.kohlbecker
18
 */
19
public class EntityReference implements Serializable, Comparable<EntityReference> {
20

    
21
    private static final long serialVersionUID = -8173845668898512626L;
22

    
23
    protected UUID uuid;
24
    protected String label;
25

    
26
    public EntityReference() {
27

    
28
    }
29

    
30
    public EntityReference(UUID uuid, String label) {
31
        this.uuid = uuid;
32
        this.label = label;
33
    }
34

    
35
    public UUID getUuid() {
36
        return uuid;
37
    }
38

    
39
    public String getLabel() {
40
        return label;
41
    }
42

    
43
    @Override
44
    public int hashCode() {
45
        return new HashCodeBuilder(17, 31)
46
                .append(label)
47
                .append(uuid)
48
                .toHashCode();
49
    }
50

    
51
    @Override
52
    public boolean equals(Object obj) {
53
        try {
54
            EntityReference other = (EntityReference) obj;
55
            return uuid.equals(other.uuid) && label.equals(other.label);
56

    
57
        } catch (Exception e) {
58
            return false;
59
        }
60
    }
61

    
62
    @Override
63
    public int compareTo(EntityReference o2) {
64
        if(o2 == null){
65
            return -1;
66
        }
67
        if (this.label == null && o2.label != null){
68
            return -1;
69
        }else if (this.label != null && o2.label == null){
70
            return 1;
71
        }else if (this.label == null && o2.label == null){
72
            return this.uuid.compareTo(o2.uuid);  //TODO also test null?
73
        }else{
74
            return this.label.compareTo(o2.label);
75
        }
76
    }
77

    
78
}
(1-1/3)