Project

General

Profile

Download (1.7 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.vaadin.model;
10

    
11
import org.apache.commons.lang.builder.HashCodeBuilder;
12

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

    
20
    /**
21
     * @param id
22
     * @param label
23
     */
24
    public TypedEntityReference(Class<T> type, int id, String label) {
25
        super(id, label);
26
        this.type = type;
27
    }
28

    
29
    public TypedEntityReference(Class<T> type, int id) {
30
        super(id, null);
31
        this.type = type;
32
    }
33

    
34
    /**
35
     * @return the type
36
     */
37
    public Class<T> getType() {
38
        return type;
39
    }
40

    
41
    /**
42
     * @param type the type to set
43
     */
44
    public void setType(Class<T> type) {
45
        this.type = type;
46
    }
47

    
48
    private Class<T> type;
49

    
50

    
51

    
52
    /**
53
     * {@inheritDoc}
54
     */
55
    @Override
56
    public int hashCode() {
57
        return new HashCodeBuilder(17, 31)
58
                .append(id)
59
                .appendSuper(type.hashCode())
60
                .hashCode();
61
    }
62

    
63
    /**
64
     * {@inheritDoc}
65
     */
66
    @SuppressWarnings("rawtypes")
67
    @Override
68
    public boolean equals(Object obj) {
69
        try {
70
            TypedEntityReference other = (TypedEntityReference) obj;
71
            return id == other.id && label.equals(other.label) && type.equals(other.type);
72

    
73
        } catch (Exception e) {
74
            return false;
75
        }
76
    }
77

    
78
    @Override
79
    public String toString(){
80
        return type.getSimpleName() + "#" + id;
81

    
82
    }
83

    
84
}
(6-6/7)