package org.xbib.datastructures.immutable;

import java.util.Map.Entry;

/**
 * {@code entrySet()} implementation for {@link ImmutableMap}.
 */
abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet.CachingAsList<Entry<K, V>> {

    ImmutableMapEntrySet() {
    }

    abstract ImmutableMap<K, V> map();

    @Override
    public int size() {
        return map().size();
    }

    @Override
    public boolean contains(Object object) {
        if (object instanceof Entry<?, ?> entry) {
            V value = map().get(entry.getKey());
            return value != null && value.equals(entry.getValue());
        }
        return false;
    }

    @Override
    boolean isPartialView() {
        return map().isPartialView();
    }

    @Override
    boolean isHashCodeFast() {
        return map().isHashCodeFast();
    }

    @Override
    public int hashCode() {
        return map().hashCode();
    }
}
