001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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 */
017package org.apache.camel.util;
018
019/**
020 * Holder object for a given value.
021 */
022public class ValueHolder<V> {
023    private V value;
024
025    /**
026     * @deprecated should be immutable, will be removed in Camel 3.0
027     */
028    @Deprecated
029    public ValueHolder() {
030    }
031
032    public ValueHolder(V val) {
033        value = val;
034    }
035
036    public V get() {
037        return value;
038    }
039
040    /**
041     * @deprecated should be immutable, will be removed in Camel 3.0
042     */
043    @Deprecated
044    public void set(V val) {
045        value = val;
046    }
047
048    @Override
049    public boolean equals(Object o) {
050        if (this == o) {
051            return true;
052        }
053        if (o == null || getClass() != o.getClass()) {
054            return false;
055        }
056
057        ValueHolder<?> that = (ValueHolder<?>) o;
058
059        if (value != null ? !value.equals(that.value) : that.value != null) {
060            return false;
061        }
062
063        return true;
064    }
065
066    @Override
067    public int hashCode() {
068        return value != null ? value.hashCode() : 0;
069    }
070}