001/*
002 * $Id$
003 */
004
005package edu.jas.util;
006
007
008import java.util.Map;
009
010/**
011 * MapEntry helper class implements Map.Entry.
012 * Required until JDK 1.6 becomes every where available.
013 * @see java.util.AbstractMap.SimpleImmutableEntry in JDK 1.6.
014 * @author Heinz Kredel
015 */
016
017public final class MapEntry<K,V> implements Map.Entry<K,V> {
018
019
020    final K key;
021
022
023    final V value;
024
025
026    /**
027     * Constructor.
028     */
029    public MapEntry(K k, V v) {
030        key = k;
031        value = v;
032    }
033
034
035    /**
036     * Get the key.
037     * @see java.util.Map.Entry#getKey()
038     */
039    public K getKey() {
040        return key;
041    }
042
043
044    /**
045     * Get the value.
046     * @see java.util.Map.Entry#getValue()
047     */
048    public V getValue() {
049        return value;
050    }
051
052
053    /**
054     * Set the value.
055     * Is not implemented.
056     * @see java.util.Map.Entry
057     */
058    public V setValue(V value) {
059        throw new UnsupportedOperationException("not implemented");
060    }
061
062
063    /**
064     * Comparison with any other object.
065     * @see java.lang.Object#equals(java.lang.Object)
066     */
067    @Override
068    @SuppressWarnings("unchecked")
069    public boolean equals(Object b) {
070        if (!(b instanceof Map.Entry)) {
071            return false;
072        }
073        Map.Entry<K,V> me = (Map.Entry<K,V>) b;
074        return key.equals(me.getKey()) && value.equals(me.getValue());
075    }
076
077
078    /**
079     * Hash code for this MapEntry.
080     * @see java.lang.Object#hashCode()
081     */
082    @Override
083    public int hashCode() {
084        return key.hashCode() * 37 + value.hashCode();
085    }
086 
087}