Project

General

Profile

Download (1.79 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(UUID uuid, String label) {
27
        this.uuid = uuid;
28
        this.label = label;
29
    }
30

    
31
    public UUID getUuid() {
32
        return uuid;
33
    }
34

    
35
    public String getLabel() {
36
        return label;
37
    }
38

    
39
    @Override
40
    public int hashCode() {
41
        return new HashCodeBuilder(17, 31)
42
                .append(label)
43
                .append(uuid)
44
                .toHashCode();
45
    }
46

    
47
    @Override
48
    public boolean equals(Object obj) {
49
        try {
50
            EntityReference other = (EntityReference) obj;
51
            return uuid.equals(other.uuid) && label.equals(other.label);
52

    
53
        } catch (Exception e) {
54
            return false;
55
        }
56
    }
57

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

    
74
}
(1-1/3)