KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > bean > Bean


1 package org.jahia.clipbuilder.html.bean;
2
3 import org.jahia.clipbuilder.html.util.*;
4
5 /**
6  * Description of the Interface
7  *
8  *@author Tlili Khaled
9  */

10 public abstract class Bean {
11     private Long JavaDoc id;
12     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Bean.class);
13
14
15     /**
16      * Sets the Id attribute of the Bean object
17      *
18      *@param id The new Id value
19      */

20     public void setId(Long JavaDoc id) {
21         this.id = id;
22     }
23
24
25     /**
26      * Gets the Id attribute of the Bean object
27      *
28      *@return The Id value
29      */

30     public Long JavaDoc getId() {
31         return id;
32     }
33
34
35     /**
36      * Compares this to the parameter.
37      *
38      *@param other the reference object with which to compare.
39      *@return <tt>true</tt> if this object is the same as the obj
40      * argument; <tt>false</tt> otherwise.
41      */

42     public boolean equals(Object JavaDoc other) {
43         // default equal
44
if (super.equals(other)) {
45                   logger.debug("[ equal true ]");
46             return true;
47         }
48                 // the current object is not null
49
if (other == null) {
50                         logger.debug("[ equal false ]");
51                         return false;
52                 }
53
54
55         // same instance
56
if (this == other) {
57             logger.debug("[ equal true ]");
58             return true;
59         }
60
61         // same class
62
if (!getClass().equals(other.getClass())) {
63             logger.debug("[ equal false ]");
64             return false;
65         }
66
67         // compare id (id could be null if the bean has been loaded from an xml template)
68
final Bean bean = (Bean) other;
69         if (getId()!= null && getId().equals(bean.getId())) {
70             logger.debug("[ equal true ]");
71             return true;
72         }
73         else {
74             logger.debug("[ equal false ]");
75             return false;
76         }
77
78     }
79
80
81     /**
82      * Computes a hash value for this object.
83      *
84      *@return The hash value for this object.
85      */

86     public int hashCode() {
87            // logger.debug(" [ Compute hash code ] ");
88
if (getId() == null) {
89             return super.hashCode();
90         }
91         return getId().hashCode();
92     }
93
94 }
95
Popular Tags