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 */ 017 package org.apache.camel.util; 018 019 /** 020 * Holder for a key and value. 021 * 022 * @version 023 */ 024 public class KeyValueHolder<K, V> { 025 026 private K key; 027 private V value; 028 029 public KeyValueHolder(K key, V value) { 030 this.key = key; 031 this.value = value; 032 } 033 034 public K getKey() { 035 return key; 036 } 037 038 public V getValue() { 039 return value; 040 } 041 042 @SuppressWarnings("unchecked") 043 @Override 044 public boolean equals(Object o) { 045 if (this == o) { 046 return true; 047 } 048 if (o == null || getClass() != o.getClass()) { 049 return false; 050 } 051 052 KeyValueHolder<K, V> that = (KeyValueHolder<K, V>) o; 053 054 if (key != null ? !key.equals(that.key) : that.key != null) { 055 return false; 056 } 057 058 return true; 059 } 060 061 @Override 062 public int hashCode() { 063 int result = key != null ? key.hashCode() : 0; 064 result = 31 * result + (value != null ? value.hashCode() : 0); 065 return result; 066 } 067 068 @Override 069 public String toString() { 070 return key + " -> " + value; 071 } 072 }