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

cz.mmsparams.api.lists.HistorizedList Maven / Gradle / Ivy

package cz.mmsparams.api.lists;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import cz.mmsparams.api.utils.Preconditions;

public class HistorizedList implements Iterable
{
    private final List list;
    private final List historized;
    private final HistorizedListConverter converter;

    public HistorizedList(HistorizedListConverter converter)
    {
        Preconditions.checkNotNull(converter, "converter");
        this.converter = converter;
        this.list = new ArrayList<>();
        this.historized = new ArrayList<>();
    }

    public List getAll()
    {
        return this.list;
    }

    public void add(T obj)
    {
        this.list.add(obj);
        this.historized.add(this.converter.convert(obj));
    }

    public int size()
    {
        return this.list.size();
    }

    public void remove(int index)
    {
        this.list.remove(index);
    }

    @Override
    public Iterator iterator()
    {
        return this.list.iterator();
    }

    public T get(int index)
    {
        return this.list.get(index);
    }

    public void addAll(List list)
    {
        this.list.addAll(list);
        this.historized.addAll(converter.convert(list));
    }

    public List getHistorizedAll()
    {
        return this.historized;
    }


    public void clear()
    {
        this.list.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy