Project

General

Profile

Download (1.69 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.util.UUID;
12

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

    
15
/**
16
 * @author a.kohlbecker
17
 * @since Jun 12, 2017
18
 *
19
 */
20
public class TypedEntityReference<T> extends EntityReference {
21

    
22
    private static final long serialVersionUID = -4619590272174606288L;
23

    
24
    private Class<T> type;
25

    
26
    /**
27
     * @param uuid
28
     * @param label
29
     */
30
    public TypedEntityReference(Class<T> type, UUID uuid, String label) {
31
        super(uuid, label);
32
        this.type = type;
33
    }
34

    
35
    public TypedEntityReference(Class<T> type, UUID uuid) {
36
        super(uuid, null);
37
        this.type = type;
38
    }
39

    
40
    public Class<T> getType() {
41
        return type;
42
    }
43
    public void setType(Class<T> type) {
44
        this.type = type;
45
    }
46

    
47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    public int hashCode() {
52
        return new HashCodeBuilder(17, 31)
53
                .append(uuid)
54
                .appendSuper(type.hashCode())
55
                .hashCode();
56
    }
57

    
58
    /**
59
     * {@inheritDoc}
60
     */
61
    @SuppressWarnings("rawtypes")
62
    @Override
63
    public boolean equals(Object obj) {
64
        try {
65
            TypedEntityReference other = (TypedEntityReference) obj;
66
            return uuid.equals(other.uuid) && type.equals(other.type);
67

    
68
        } catch (Exception e) {
69
            return false;
70
        }
71
    }
72

    
73
    @Override
74
    public String toString(){
75
        return type.getSimpleName() + "#" + uuid;
76

    
77
    }
78

    
79
}
(2-2/2)