jenkins merging release branch into master (strategy: theirs)
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / model / TypedEntityReference.java
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 /**
30 * @return the type
31 */
32 public Class<T> getType() {
33 return type;
34 }
35
36 /**
37 * @param type the type to set
38 */
39 public void setType(Class<T> type) {
40 this.type = type;
41 }
42
43 private Class<T> type;
44
45
46
47 /**
48 * {@inheritDoc}
49 */
50 @Override
51 public int hashCode() {
52 return new HashCodeBuilder(17, 31)
53 .appendSuper(super.hashCode())
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 id == other.id && label.equals(other.label) && type.equals(other.type);
67
68 } catch (Exception e) {
69 return false;
70 }
71 }
72
73 }