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

com.github.simonharmonicminor.juu.collection.immutable.PairImpl Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package com.github.simonharmonicminor.juu.collection.immutable;

import java.io.Serializable;
import java.util.Objects;

import static com.github.simonharmonicminor.juu.collection.immutable.ImmutableCollectionUtils.pairEquals;

/**
 * Simple implementation of {@link Pair}
 *
 * @param  the type of the key
 * @param  the type of the value
 * @see Serializable
 * @since 1.0
 */
class PairImpl implements Pair, Serializable {
    private final K key;
    private final V value;

    PairImpl(K key, V value) {
        this.key = key;
        this.value = value;
    }

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

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

    @Override
    public boolean equals(Object o) {
        return pairEquals(this, o);
    }

    @Override
    public int hashCode() {
        return Objects.hash(key, value);
    }

    @Override
    public String toString() {
        return String.format("(key=%s; value=%s)", key, value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy