/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira.drafts
 */
package net.ranides.assira.collections.map.impl;

import java.util.Collection;
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Function;
import net.ranides.assira.collections.map.IndexMap;
import net.ranides.assira.collections.map.IndexQuery;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public abstract class AIndexMap<V> implements IndexMap<V> {

    @Override
    public abstract AIndexQuery<V> find();
    
    @Override
    public final IndexQuery<V> find(Comparator<V> index, V value) {
        return find().eq(index, value);
    }

    @Override
    public <T> IndexQuery<V> find(Function<V, T> index, T value) {
        return find().eq(index, value);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public final IndexQuery<V> find(String index, Object value) {
        return find().eq(index, value);
    }
    
    @Override
    public final void put(Collection<? extends V> values) {
        for(V value : values) {
            put(value);
        }
    }
    
    @Override
    public final void remove(Comparator<V> index, V value) {
        find().eq(index, value).remove();
    }

    @Override
    public <T> void remove(Function<V, T> index, T value) {
        find().eq(index, value).remove();
    }
    
    @Override
    public final void remove(String index, Object value) {
        find().eq(index, value).remove();
    }

    @Override
    public void removeAll(Collection<V> values) {
        for(V item : values) {
            remove(item);
        }
    }
    
    @Override
    public void update(V value, Consumer<? super V> consumer) {
        remove(value);
        consumer.accept(value);
        put(value);
    }
    
    protected abstract <T> Function<V,T> mindex(String name);
    
    protected abstract Comparator<V> sindex(String name);
    
}
