KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > core > ValueContainer


1 package org.apache.ojb.broker.core;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import java.io.Serializable JavaDoc;
19
20 import org.apache.ojb.broker.metadata.JdbcType;
21 import org.apache.commons.lang.builder.EqualsBuilder;
22 import org.apache.commons.lang.builder.HashCodeBuilder;
23
24 public final class ValueContainer implements Serializable JavaDoc
25 {
26     private static final long serialVersionUID = 3689069556052340793L;
27   
28     private final JdbcType m_jdbcType;
29     private final Object JavaDoc m_value;
30     private int hc;
31
32     public ValueContainer(Object JavaDoc value, JdbcType jdbcType)
33     {
34         this.m_jdbcType = jdbcType;
35         this.m_value = value;
36     }
37
38     public JdbcType getJdbcType()
39     {
40         return m_jdbcType;
41     }
42
43     public Object JavaDoc getValue()
44     {
45         return m_value;
46     }
47
48     public boolean equals(Object JavaDoc obj)
49     {
50         if(obj == this) return true;
51         boolean result = false;
52         if(obj instanceof ValueContainer)
53         {
54             final ValueContainer container = (ValueContainer) obj;
55             // if jdbcType was null, we can't compare
56
result = this.m_jdbcType != null ? this.m_jdbcType.equals(container.getJdbcType()) : false;
57             if(result)
58             {
59                 result = new EqualsBuilder().append(this.m_value, container.getValue()).isEquals();
60             }
61         }
62         return result;
63     }
64
65     public int hashCode()
66     {
67 // int hash = m_value != null ? m_value.hashCode() : 0;
68
// hash += m_jdbcType != null ? m_jdbcType.hashCode() : 0;
69
// return hash;
70
if(hc == 0) hc = new HashCodeBuilder().append(m_jdbcType).append(m_value).toHashCode();
71         return hc;
72     }
73
74     public String JavaDoc toString()
75     {
76         return this.getClass().getName() + "[jdbcType: "
77         + m_jdbcType
78         + ", value: " + m_value + "]";
79     }
80
81 }
82
Popular Tags