/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.trace;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author ranides
 */
public class RuntimeExceptions extends RuntimeException implements Iterable<Throwable> {

    private final List<Throwable> causeList;
    
    public RuntimeExceptions(Collection<? extends Throwable> causeList) {
        super();
        this.causeList = new LinkedList<>(causeList);
    }

    public <T extends Throwable> RuntimeExceptions(String message, Collection<? extends Throwable> causeList) {
        super(message);
        this.causeList = new LinkedList<>(causeList);
    }

    public RuntimeExceptions(String message) {
        super(message);
        this.causeList = new LinkedList<>();
    }
    
    @Override
    public Iterator<Throwable> iterator() {
		return causeList.iterator();
    }
    
    public List<Throwable> getCauseList() {
        return causeList;
    }
    
    public void addCause(Throwable cause) {
        causeList.add(cause);
    }

    @Override
    public void printStackTrace(PrintStream stream) {
        super.printStackTrace(stream);
		ExceptionInspector.print(stream, causeList);
    }

    @Override
    public void printStackTrace(PrintWriter writer) {
        super.printStackTrace(writer);
		ExceptionInspector.print(writer, causeList);
    }
    
}
