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

org.datacleaner.util.ImmutableEntry Maven / Gradle / Ivy

/**
 * DataCleaner (community edition)
 * Copyright (C) 2014 Free Software Foundation, Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.datacleaner.util;

import java.io.Serializable;
import java.util.Map.Entry;

/**
 * An immutable entry implementation
 *
 * @param 
 * @param 
 */
public final class ImmutableEntry implements Entry, Serializable {

    private static final long serialVersionUID = 1L;

    private final K _key;
    private final V _value;

    public ImmutableEntry(final K key, final V value) {
        super();
        _key = key;
        _value = value;
    }

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

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

    @Override
    public V setValue(final V value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((_key == null) ? 0 : _key.hashCode());
        result = prime * result + ((_value == null) ? 0 : _value.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        @SuppressWarnings("rawtypes") final ImmutableEntry other = (ImmutableEntry) obj;
        if (_key == null) {
            if (other._key != null) {
                return false;
            }
        } else if (!_key.equals(other._key)) {
            return false;
        }
        if (_value == null) {
            if (other._value != null) {
                return false;
            }
        } else if (!_value.equals(other._value)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ImmutableEntry[" + _key + "," + _value + "]";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy