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

javolution.util.internal.map.MapEntryImpl Maven / Gradle / Ivy

/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.util.internal.map;

import java.util.Map;

/**
 * The hash map entry implementation (not serializable).
 */
final class MapEntryImpl implements Map.Entry {

    int hash;
    K key;
    MapEntryImpl next;
    MapEntryImpl previous;
    V value;

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return value;
    }

    @Override
    public V setValue(V value) {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    }
    
    @SuppressWarnings("rawtypes")
	@Override
    public boolean equals(Object obj) {
		// As per Map.Entry contract.
    	if (!(obj instanceof Map.Entry)) return false;
    	Map.Entry that = (Map.Entry) obj;
    	return (this.getKey()==null ?
    		      that.getKey()==null : this.getKey().equals(that.getKey()))  &&
    		      (this.getValue()==null ?
    		       that.getValue()==null : this.getValue().equals(that.getValue()));
    }

	@Override
    public int hashCode() {
		// As per Map.Entry contract.
    	return  (getKey()==null   ? 0 : getKey().hashCode()) ^
    		     (getValue()==null ? 0 : getValue().hashCode());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy