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

com.ajjpj.afoundation.collection.immutable.AWrappedMap Maven / Gradle / Ivy

The newest version!
package com.ajjpj.afoundation.collection.immutable;

import com.ajjpj.afoundation.collection.AEquality;
import com.ajjpj.afoundation.function.AFunction1;

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


/**
 * @author arno
 */
abstract class AWrappedMap implements AMap, Serializable {
    private final AMap inner;

    AWrappedMap(AMap inner) {
        this.inner = inner;
    }

    abstract AMap wrap(AMap inner);
    abstract V defaultValue(K key);

    @Override public AEquality keyEquality () {
        return inner.keyEquality ();
    }

    @Override public AMap clear () {
        return wrap (inner.clear ());
    }

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

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

    @Override public boolean nonEmpty() {
        return inner.nonEmpty();
    }

    @Override public boolean containsKey(K key) {
        return inner.containsKey(key);
    }

    @Override public boolean containsValue(V value) {
        return inner.containsValue(value);
    }

    @Override public AOption get(K key) {
        final AOption innerResult = inner.get(key);
        if(innerResult == AOption.none()) {
            return AOption.some(defaultValue(key));
        }
        return innerResult;
    }

    @Override public V getRequired(K key) {
        return get(key).get();
    }

    @Override public AMap updated(K key, V value) {
        return wrap(inner.updated(key, value));
    }

    @Override public AMap removed(K key) {
        return wrap(inner.removed(key));
    }

    @Override public Iterator> iterator() {
        return inner.iterator();
    }

    @Override public Map asJavaUtilMap() {
        return inner.asJavaUtilMap();
    }

    @Override public AMap withDefaultValue(V defaultValue) {
        return inner.withDefaultValue(defaultValue);
    }

    @Override public AMap withDefault(AFunction1 function) {
        return inner.withDefault(function);
    }

    @Override public ASet keys() {
        return inner.keys();
    }

    @Override public ACollection values() {
        return inner.values();
    }

    @Override public String toString() {
        return inner.toString();
    }

    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
    @Override public boolean equals(Object obj) {
        return inner.equals(obj);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy