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

com.jparams.store.memory.MemoryStore Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
package com.jparams.store.memory;

import java.util.Collection;

import com.jparams.store.AbstractStore;
import com.jparams.store.Store;
import com.jparams.store.identity.DefaultIdentityProvider;
import com.jparams.store.index.IndexManager;
import com.jparams.store.index.ReferenceIndexManager;
import com.jparams.store.reference.DefaultReferenceManager;
import com.jparams.store.reference.ReferenceManager;

/**
 * In memory implementation of a {@link Store}
 *
 * @param  type of item referenced
 */
public class MemoryStore extends AbstractStore
{
    private MemoryStore(final ReferenceManager referenceManager, final IndexManager indexManager)
    {
        super(referenceManager, indexManager);
    }

    public MemoryStore()
    {
        this(new DefaultReferenceManager<>(new DefaultIdentityProvider(), new MemoryReferenceFactory<>()), new ReferenceIndexManager<>());
    }

    public MemoryStore(final Collection items)
    {
        this();
        addAll(items);
    }

    @SafeVarargs
    public MemoryStore(final V... items)
    {
        this();
        addAll(items);
    }

    @Override
    protected Store createCopy(final ReferenceManager referenceManager, final IndexManager indexManager)
    {
        return new MemoryStore<>(referenceManager.copy(), indexManager.copy());
    }

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

    public static  MemoryStoreBuilder newStore()
    {
        return new MemoryStoreBuilder<>();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy