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

com.zipwhip.util.GenericDirectory Maven / Gradle / Ivy

package com.zipwhip.util;

import com.zipwhip.lifecycle.DestroyableBase;

import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: Michael
 * Date: 11/1/11
 * Time: 6:46 PM
 *
 * A base template for all directories
 */
public abstract class GenericDirectory extends DestroyableBase implements Directory {

    @Override
    public void add(TKey key, TValue value) {
        Collection collection = getOrCreateCollection(key);

        collection.add(value);
    }

    @Override
    public void remove(TKey key, TValue value) {
        Collection collection = get(key);
        if (collection == null){
            return;
        }

        collection.remove(value);

        if (collection.isEmpty()){
            removeFromStore(key);
        }

    }

    protected abstract void removeFromStore(TKey key);

    protected abstract Collection getOrCreateCollection(TKey key);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy