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.api.service.dto;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.apache.commons.lang.builder.HashCodeBuilder;
|
14
|
|
15
|
/**
|
16
|
* @author a.kohlbecker
|
17
|
* @since Jun 12, 2017
|
18
|
*
|
19
|
*/
|
20
|
public class TypedEntityReference<T> extends EntityReference {
|
21
|
|
22
|
/**
|
23
|
* @param uuid
|
24
|
* @param label
|
25
|
*/
|
26
|
public TypedEntityReference(Class<T> type, UUID uuid, String label) {
|
27
|
super(uuid, label);
|
28
|
this.type = type;
|
29
|
}
|
30
|
|
31
|
public TypedEntityReference(Class<T> type, UUID uuid) {
|
32
|
super(uuid, null);
|
33
|
this.type = type;
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* @return the type
|
38
|
*/
|
39
|
public Class<T> getType() {
|
40
|
return type;
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* @param type the type to set
|
45
|
*/
|
46
|
public void setType(Class<T> type) {
|
47
|
this.type = type;
|
48
|
}
|
49
|
|
50
|
private Class<T> type;
|
51
|
|
52
|
|
53
|
|
54
|
/**
|
55
|
* {@inheritDoc}
|
56
|
*/
|
57
|
@Override
|
58
|
public int hashCode() {
|
59
|
return new HashCodeBuilder(17, 31)
|
60
|
.append(uuid)
|
61
|
.appendSuper(type.hashCode())
|
62
|
.hashCode();
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* {@inheritDoc}
|
67
|
*/
|
68
|
@SuppressWarnings("rawtypes")
|
69
|
@Override
|
70
|
public boolean equals(Object obj) {
|
71
|
try {
|
72
|
TypedEntityReference other = (TypedEntityReference) obj;
|
73
|
return uuid.equals(other.uuid) && type.equals(other.type);
|
74
|
|
75
|
} catch (Exception e) {
|
76
|
return false;
|
77
|
}
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public String toString(){
|
82
|
return type.getSimpleName() + "#" + uuid;
|
83
|
|
84
|
}
|
85
|
|
86
|
}
|