1
|
/**
|
2
|
* Copyright (C) 2015 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.cache;
|
10
|
|
11
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
12
|
|
13
|
public class CdmEntityCacheKey<T extends CdmBase> {
|
14
|
|
15
|
private Class<T> persistenceClass;
|
16
|
private int persistenceId; //see #7709 for why we use id, not uuid
|
17
|
|
18
|
public CdmEntityCacheKey(T cdmBase) {
|
19
|
this.persistenceClass = (Class<T>)cdmBase.getClass();
|
20
|
this.persistenceId = cdmBase.getId();
|
21
|
}
|
22
|
|
23
|
public CdmEntityCacheKey(Class<T> clazz, int id) {
|
24
|
this.persistenceClass = clazz;
|
25
|
this.persistenceId = id;
|
26
|
}
|
27
|
|
28
|
public Class<? extends T> getPersistenceClass() {
|
29
|
return persistenceClass;
|
30
|
}
|
31
|
|
32
|
public int getPersistenceId() {
|
33
|
return persistenceId;
|
34
|
}
|
35
|
|
36
|
@Override
|
37
|
public boolean equals(Object obj) {
|
38
|
if(obj == null || !(obj instanceof CdmEntityCacheKey)) {
|
39
|
return false;
|
40
|
}
|
41
|
if(this == obj) {
|
42
|
return true;
|
43
|
}
|
44
|
CdmEntityCacheKey<?> that = (CdmEntityCacheKey<?>) obj;
|
45
|
if(this.persistenceClass.equals(that.persistenceClass)
|
46
|
&& this.persistenceId == that.persistenceId) {
|
47
|
return true;
|
48
|
}
|
49
|
return false;
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public int hashCode() {
|
54
|
return (this.persistenceClass.getName() + String.valueOf(this.persistenceId)).hashCode();
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public String toString() {
|
59
|
return this.persistenceClass.getName() +":" + String.valueOf(this.persistenceId);
|
60
|
}
|
61
|
|
62
|
}
|