01: package org.apache.ojb.broker.core;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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;
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 {
25: private static final long serialVersionUID = 3689069556052340793L;
26:
27: private final JdbcType m_jdbcType;
28: private final Object m_value;
29: private int hc;
30:
31: public ValueContainer(Object value, JdbcType jdbcType) {
32: this .m_jdbcType = jdbcType;
33: this .m_value = value;
34: }
35:
36: public JdbcType getJdbcType() {
37: return m_jdbcType;
38: }
39:
40: public Object getValue() {
41: return m_value;
42: }
43:
44: public boolean equals(Object obj) {
45: if (obj == this )
46: return true;
47: boolean result = false;
48: if (obj instanceof ValueContainer) {
49: final ValueContainer container = (ValueContainer) obj;
50: // if jdbcType was null, we can't compare
51: result = this .m_jdbcType != null ? this .m_jdbcType
52: .equals(container.getJdbcType()) : false;
53: if (result) {
54: result = new EqualsBuilder().append(this .m_value,
55: container.getValue()).isEquals();
56: }
57: }
58: return result;
59: }
60:
61: public int hashCode() {
62: // int hash = m_value != null ? m_value.hashCode() : 0;
63: // hash += m_jdbcType != null ? m_jdbcType.hashCode() : 0;
64: // return hash;
65: if (hc == 0)
66: hc = new HashCodeBuilder().append(m_jdbcType).append(
67: m_value).toHashCode();
68: return hc;
69: }
70:
71: public String toString() {
72: return this .getClass().getName() + "[jdbcType: " + m_jdbcType
73: + ", value: " + m_value + "]";
74: }
75:
76: }
|