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

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

Go to download

a-base is a library of basic (hence the name) classes, most notably immutable collection classes with copy-on-write operations

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

import com.ajjpj.abase.collection.APair;
import com.ajjpj.abase.function.AFunction1;

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


/**
 * @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 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 Set keys() {
        return inner.keys();
    }

    @Override
    public Collection 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