package org.keyscience.SingletonPattern;

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


public class ListSingleton<T> {
    private final static int EVENTS_LIST = 0;
    private final static int NEWS_LIST = 1;

    private List<T> list;
    private static ListSingleton EventsInstance = null;
    private static ListSingleton NewsInstance = null;

    private ListSingleton() {
        list = new ArrayList<>();
    }


    public static ListSingleton getListInstance(int listType) {
        switch (listType) {
            case EVENTS_LIST:
                if (EventsInstance == null) {
                    EventsInstance = new ListSingleton();
                }
                return EventsInstance;
            case NEWS_LIST:
                if (NewsInstance == null) {
                    NewsInstance = new ListSingleton();
                }
                return NewsInstance;
        }
        return null;
    }

    public void add(Object model) {
        list.add((T) model);

    }

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

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

    public List getList() {
        return list;
    }
}
