package bali;

import java.util.ArrayList;

/**
 * MultipleBaliException allows for the reporting of more than one error.
 * The suggested method of use is to create an exception at the start of compilation,
 * and add errors to it as they are found. If errorCount() > 0 at the end, the
 * exception should then be thrown.
 */
public class MultipleBaliException extends BaliException {
    
    private ArrayList<BaliException> errors = new ArrayList<BaliException>();
    
    /*  Constructor. */
    public MultipleBaliException() {super("Multiple Bali errors");}
    
    /* Add an error. */
    public void addError (BaliException e) {errors.add(e);}
    
    /* Number of errors. */
    public int errorCount() {return errors.size();}
    
    /* String representation of all the errors. */
    public String toString () {
        String s = "\n";
        int i = 0;
        for (BaliException e: errors) {s += "Error " + (i++) + ":\n   " + e + "\n";}
        return s;
    }
}