001 package org.apache.ojb.broker.core;
002
003 /* Copyright 2003-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import java.io.Serializable;
019
020 import org.apache.ojb.broker.metadata.JdbcType;
021 import org.apache.commons.lang.builder.EqualsBuilder;
022 import org.apache.commons.lang.builder.HashCodeBuilder;
023
024 public final class ValueContainer implements Serializable
025 {
026 private static final long serialVersionUID = 3689069556052340793L;
027
028 private final JdbcType m_jdbcType;
029 private final Object m_value;
030 private int hc;
031
032 public ValueContainer(Object value, JdbcType jdbcType)
033 {
034 this.m_jdbcType = jdbcType;
035 this.m_value = value;
036 }
037
038 public JdbcType getJdbcType()
039 {
040 return m_jdbcType;
041 }
042
043 public Object getValue()
044 {
045 return m_value;
046 }
047
048 public boolean equals(Object obj)
049 {
050 if(obj == this) return true;
051 boolean result = false;
052 if(obj instanceof ValueContainer)
053 {
054 final ValueContainer container = (ValueContainer) obj;
055 // if jdbcType was null, we can't compare
056 result = this.m_jdbcType != null ? this.m_jdbcType.equals(container.getJdbcType()) : false;
057 if(result)
058 {
059 result = new EqualsBuilder().append(this.m_value, container.getValue()).isEquals();
060 }
061 }
062 return result;
063 }
064
065 public int hashCode()
066 {
067 // int hash = m_value != null ? m_value.hashCode() : 0;
068 // hash += m_jdbcType != null ? m_jdbcType.hashCode() : 0;
069 // return hash;
070 if(hc == 0) hc = new HashCodeBuilder().append(m_jdbcType).append(m_value).toHashCode();
071 return hc;
072 }
073
074 public String toString()
075 {
076 return this.getClass().getName() + "[jdbcType: "
077 + m_jdbcType
078 + ", value: " + m_value + "]";
079 }
080
081 }