LogicalCheckExceptionList.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  */
15 
16 package org.qedeq.kernel.bo.logic.common;
17 
18 import java.util.ArrayList;
19 import java.util.List;
20 
21 /**
22  * Type save {@link org.qedeq.kernel.bo.logic.common.LogicalCheckException} list.
23  *
24  @author  Michael Meyling
25  */
26 public class LogicalCheckExceptionList {
27 
28     /** List with parse exceptions. */
29     private final List exceptions = new ArrayList();
30 
31     /**
32      * Constructor.
33      */
34     public LogicalCheckExceptionList() {
35     }
36 
37     /**
38      * Add exception.
39      *
40      @param   e   Exception to add.
41      */
42     public void add(final LogicalCheckException e) {
43         exceptions.add(e);
44     }
45 
46     /**
47      * Add exceptions.
48      *
49      @param   e   Exceptions to add.
50      */
51     public void add(final LogicalCheckExceptionList e) {
52         exceptions.addAll(e.exceptions);
53     }
54 
55     /**
56      * Get number of collected exceptions.
57      *
58      @return  Number of collected exceptions.
59      */
60     public int size() {
61         return exceptions.size();
62     }
63 
64     /**
65      * Get <code>i</code>-th exception.
66      *
67      @param   i   Starts with 0 and must be smaller than {@link #size()}.
68      @return  Wanted exception.
69      */
70     public LogicalCheckException get(final int i) {
71         return (LogicalCheckExceptionexceptions.get(i);
72     }
73 
74     /**
75      * Contains this list any errors?
76      *
77      @return  Do I contain any errors?
78      */
79     public boolean hasErrors() {
80         return size() 0;
81     }
82 
83     public String toString() {
84         final StringBuffer buffer = new StringBuffer();
85         for (int i = 0; i < size(); i++) {
86             if (i != 0) {
87                 buffer.append("\n");
88             }
89             final LogicalCheckException e = get(i);
90             buffer.append(i).append(": ");
91             buffer.append(e.toString());
92         }
93         return buffer.toString();
94     }
95 
96 }