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

com.github.grzesiek_galezowski.collections.readonly.implementation.ReadOnlyMapWrapper Maven / Gradle / Ivy

The newest version!
package com.github.grzesiek_galezowski.collections.readonly.implementation;

import com.github.grzesiek_galezowski.collections.readonly.interfaces.ReadOnlyCollection;
import com.github.grzesiek_galezowski.collections.readonly.interfaces.ReadOnlyMap;
import com.github.grzesiek_galezowski.collections.readonly.interfaces.ReadOnlySet;

import java.io.Serializable;
import java.util.Map;
import java.util.function.BiConsumer;

public class ReadOnlyMapWrapper implements ReadOnlyMap, Serializable {

    private final Map original;

    public ReadOnlyMapWrapper(final Map original) {
        this.original = original;
    }

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

    @Override
    public boolean isEmpty() {
        return original.isEmpty();
    }

    @Override
    public boolean containsKey(final Object key) {
        return original.containsKey(key);
    }

    @Override
    public boolean containsValue(final Object value) {
        return original.containsValue(value);
    }

    @Override
    public V get(final Object key) {
        return original.get(key);
    }

    @Override
    public ReadOnlySet keySet() {
        return new ReadOnlySetWrapper<>(original.keySet());
    }

    @Override
    public ReadOnlyCollection values() {
        return new ReadOnlyCollectionWrapper<>(original.values());
    }

    @Override
    public ReadOnlySet> entrySet() {
        return new ReadOnlySetWrapper<>(original.entrySet());
    }

    @Override
    public V getOrDefault(final Object key, final V defaultValue) {
        return original.getOrDefault(key, defaultValue);
    }

    @Override
    public void forEach(final BiConsumer action) {
        original.forEach(action);
    }

    @Override
    @SuppressWarnings("checkstyle:all")
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        ReadOnlyMapWrapper that = (ReadOnlyMapWrapper) o;

        return original != null ? original.equals(that.original) : that.original == null;
    }

    @Override
    @SuppressWarnings("checkstyle:all")
    public int hashCode() {
        return original != null ? original.hashCode() : 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy