2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.ref
;
11 import java
.util
.UUID
;
13 import org
.apache
.commons
.lang3
.builder
.HashCodeBuilder
;
15 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
16 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
19 * @author a.kohlbecker
23 public class TypedEntityReference
<T
extends CdmBase
> extends EntityReference
{
25 private static final long serialVersionUID
= -4619590272174606288L;
27 private Class
<T
> type
;
33 public TypedEntityReference(Class
<T
> type
, UUID uuid
, String label
) {
38 public TypedEntityReference(Class
<T
> type
, UUID uuid
) {
43 public static <T
extends CdmBase
> TypedEntityReference
<T
> fromEntity(T entity
) {
47 if(IdentifiableEntity
.class.isAssignableFrom(entity
.getClass())) {
48 return new TypedEntityReference
<T
>((Class
<T
>)entity
.getClass(), entity
.getUuid(), ((IdentifiableEntity
)entity
).getTitleCache());
50 return new TypedEntityReference
<T
>((Class
<T
>)entity
.getClass(), entity
.getUuid());
54 public Class
<T
> getType() {
57 public void setType(Class
<T
> type
) {
65 public int hashCode() {
66 return new HashCodeBuilder(17, 31)
68 .appendSuper(type
.hashCode())
75 @SuppressWarnings("rawtypes")
77 public boolean equals(Object obj
) {
79 TypedEntityReference other
= (TypedEntityReference
) obj
;
80 return uuid
.equals(other
.uuid
) && type
.equals(other
.type
);
82 } catch (Exception e
) {
88 public String
toString(){
89 return type
.getSimpleName() + "#" + uuid
;