Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / dto / KnowledgeElementTypeDTO.java
1 package org.splat.service.dto;
2
3 /**
4  * Knowledge type DTO.
5  * 
6  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
7  */
8 public class KnowledgeElementTypeDTO {
9
10         /**
11          * Type name.
12          */
13         private String _name;
14         /**
15          * Persistent id of the type.
16          */
17         private long _index;
18
19         // ==============================================================================================================================
20         // Public member functions
21         // ==============================================================================================================================
22
23         /**
24          * {@inheritDoc}
25          * 
26          * @see java.lang.Object#equals(java.lang.Object)
27          */
28         @Override
29         public boolean equals(final Object entity) {
30                 boolean res = (entity != null);
31                 if (res) {
32                         if (entity instanceof String) {
33                                 res = this._name.equals(entity); // Names are unique
34                         } else if (entity instanceof KnowledgeElementTypeDTO) {
35                                 KnowledgeElementTypeDTO object = (KnowledgeElementTypeDTO) entity;
36                                 long he = object.getIndex();
37                                 long me = this.getIndex();
38                                 if (me * he == 0) {
39                                         res = this.getName().equals(object.getName());
40                                 } else {
41                                         res = (he == me);
42                                 }
43                         }
44                 }
45                 return res;
46         }
47
48         /** 
49          * {@inheritDoc}
50          * @see java.lang.Object#hashCode()
51          */
52         @Override
53         public int hashCode() {
54                 long oid = getIndex(); // getIndex() is supposed fetching the index if not yet done
55                 if (oid == 0) {
56                         oid = super.hashCode(); // WARNING: Must not call super.toString() as it goes back here (this.toString())
57                 }
58                 return new StringBuffer("object ").append(getClass().getName()).append(
59                                 "@").append(oid).toString().hashCode();
60         }
61         
62         /**
63          * Get the name of the knowledge type.
64          * 
65          * @return the type name
66          */
67         public String getName() {
68                 return _name;
69         }
70
71         /**
72          * Get the rid.
73          * 
74          * @return the rid
75          */
76         public long getIndex() {
77                 return _index;
78         }
79
80         /**
81          * Set the rid.
82          * 
83          * @param rid
84          *            the rid to set
85          */
86         public void setIndex(final long rid) {
87                 this._index = rid;
88         }
89
90         /**
91          * Set the name.
92          * @param name the name to set
93          */
94         public void setName(final String name) {
95                 this._name = name;
96         }
97 }