package br.ufrgs.inf.prosoft.tigris.monitoring.storage.providers;

import br.ufrgs.inf.prosoft.tigris.exceptions.StorageException;
import br.ufrgs.inf.prosoft.tigris.monitoring.storage.Repository;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The type Memory repository.
 *
 * @param <T> the type parameter
 */
public class MemoryRepository<T> implements Repository<T> {

    /**
     * The Logs.
     */
    List<T> logs;

    /**
     * Instantiates a new Memory repository.
     */
    public MemoryRepository() {
        logs = Collections.synchronizedList(new ArrayList<>());
    }

    @Override
    public void save(T t) throws StorageException {
        logs.add(t);
    }

    @Override
    public List<T> findAll() {
        return new ArrayList<T>(logs);
    }

    @Override
    public void removeAll() {
        logs.clear();
    }

    @Override
    public void saveAll(List<T> toSave) {
        logs.addAll(toSave);
    }
}
