package uebung09.collection;

import java.util.Iterator;
import java.util.NoSuchElementException;

class EmptySet<T> implements Set<T> {

    private static EmptySet<?> INSTANCE;

    private EmptySet() {}

    @SuppressWarnings("unchecked")
    public static <T> EmptySet<T> getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new EmptySet<>();
        }
        return (EmptySet<T>) INSTANCE;
    }

    @Override
    public Iterator<T> iterator() {
        return new Iterator<T>() {
            
            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public T next() {
                throw new NoSuchElementException();
            }
        };
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean isEmpty() {
        return true;
    }

    @Override
    public boolean contains(Object el) {
        return false;
    }

    @Override
    public Set<T> union(Set<T> other) {
        return other;
    }

    @Override
    public Set<T> add(T element) {
        return new SingeltonSet<T>(element);
    }

    @Override
    public Set<T> intersection(Set<T> other) {
        return other;
    }

    @Override
    public boolean subsetOf(Set<?> other) {
        return true;
    }

}
