All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.jas.util.MapEntry Maven / Gradle / Ivy

The newest version!
/*
 * $Id: MapEntry.java 3652 2011-06-02 18:17:04Z kredel $
 */

package edu.jas.util;


import java.util.Map;

/**
 * MapEntry helper class implements Map.Entry.
 * Required until JDK 1.6 becomes every where available.
 * @see java.util.AbstractMap.SimpleImmutableEntry in JDK 1.6.
 * @author Heinz Kredel.
 */

public class MapEntry implements Map.Entry {


    final K key;


    final V value;


    /**
     * Constructor.
     */
    public MapEntry(K k, V v) {
        key = k;
        value = v;
    }


    /**
     * Get the key.
     * @see java.util.Map.Entry#getKey()
     */
    public K getKey() {
        return key;
    }


    /**
     * Get the value.
     * @see java.util.Map.Entry#getValue()
     */
    public V getValue() {
        return value;
    }


    /**
     * Set the value.
     * Is not implemented.
     * @see java.util.Map.Entry
     */
    public V setValue(V value) {
        throw new UnsupportedOperationException("not implemented");
    }


    /**
     * Comparison with any other object.
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    @SuppressWarnings("unchecked")
    public boolean equals(Object b) {
        if (!(b instanceof Map.Entry)) {
            return false;
        }
        Map.Entry me = (Map.Entry) b;
        return key.equals(me.getKey()) && value.equals(me.getValue());
    }


    /**
     * Hash code for this MapEntry.
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return key.hashCode() * 37 + value.hashCode();
    }
 
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy