001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.common.parsers.core; 015 016import java.util.Objects; 017 018import org.apache.commons.lang3.builder.EqualsBuilder; 019import org.apache.commons.lang3.builder.ToStringBuilder; 020import org.apache.commons.lang3.builder.ToStringStyle; 021 022/** 023 * Simple container object. 024 */ 025public class KeyValue<K, V> { 026 027 private final K key; 028 private final V value; 029 030 public KeyValue(K key, V value) { 031 this.key = key; 032 this.value = value; 033 } 034 035 public K getKey() { 036 return key; 037 } 038 039 public V getValue() { 040 return value; 041 } 042 043 @SuppressWarnings("unchecked") 044 @Override 045 public boolean equals(Object obj) { 046 if (obj instanceof KeyValue) { 047 KeyValue t = (KeyValue) obj; 048 return new EqualsBuilder().append(key, t.getKey()).append(value, t.getValue()).isEquals(); 049 } 050 return false; 051 } 052 053 @Override 054 public int hashCode() { 055 return Objects.hash(key, value); 056 } 057 058 @Override 059 public String toString() { 060 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(key).append(value).toString(); 061 } 062 063 064}