ref #7854: adapt DTOs and merge Method for Distributions
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / dto / CdmEntityIdentifier.java
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.api.service.dto;
10
11 import java.io.Serializable;
12
13 import eu.etaxonomy.cdm.model.common.CdmBase;
14
15 /**
16 * @author cmathew
17 * @since 24 Jun 2015
18 *
19 */
20 public class CdmEntityIdentifier implements Serializable {
21
22
23 private static final long serialVersionUID = 1479948194282284147L;
24
25
26 private final int id;
27 private final Class<? extends CdmBase> cdmClass;
28
29 public CdmEntityIdentifier(int id, Class cdmClass) {
30 this.id = id;
31 this.cdmClass = cdmClass;
32 }
33
34
35 public int getId() {
36 return id;
37 }
38
39 public Class getCdmClass() {
40 return cdmClass;
41 }
42
43 @Override
44 public boolean equals(Object obj) {
45 if(obj == null || !(obj instanceof CdmEntityIdentifier)) {
46 return false;
47 }
48
49 if(this == obj) {
50 return true;
51 }
52 CdmEntityIdentifier that = (CdmEntityIdentifier) obj;
53 if(this.cdmClass.equals(that.cdmClass) && this.id == that.id) {
54 return true;
55 }
56
57 return false;
58 }
59
60 @Override
61 public int hashCode() {
62 return (this.cdmClass.getName() + String.valueOf(this.id)).hashCode();
63 }
64
65 @Override
66 public String toString() {
67 return this.cdmClass.getName() + String.valueOf(this.id);
68 }
69 }