Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart1.png 95% of files have more coverage
24   110   16   4
20   50   0.67   6
6     2.67  
1    
 
  ExceptionList       Line # 29 24 16 4% 0.04
 
  (1)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
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.xml.test;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20   
21    import org.xml.sax.SAXParseException;
22   
23    /**
24    * Type save Exception list.
25    *
26    * @version $Revision: 1.2 $
27    * @author Michael Meyling
28    */
 
29    public class ExceptionList {
30   
31    /** List with parse exceptions. */
32    private List exceptions;
33   
34    /** Maximum number of exceptions. */
35    public static final int MAXIMUM = 10;
36   
37    /**
38    * Constructor.
39    */
 
40  260 toggle public ExceptionList() {
41  260 exceptions = new ArrayList(MAXIMUM);
42    }
43   
44    /**
45    * Add Exception. This is only done if the number of already collected exceptions is below
46    * {@link #MAXIMUM}.
47    *
48    * @param e Exception to add.
49    */
 
50  0 toggle public void add(final Exception e) {
51  0 if (e == null) {
52  0 final NullPointerException ex = new NullPointerException("Exception expected!");
53  0 exceptions.add(ex);
54  0 throw ex;
55    }
56  0 if (size() < MAXIMUM) {
57  0 exceptions.add(e);
58    }
59    }
60   
61    /**
62    * Get number of collected exceptions.
63    *
64    * @return Number of collected exceptions.
65    */
 
66  0 toggle public int size() {
67  0 return exceptions.size();
68    }
69   
70    /**
71    * Get <code>i</code>-th exception.
72    *
73    * @param i Starts with 0 and must be smaller than {@link #size()}.
74    * @return Wanted exception.
75    */
 
76  0 toggle public Exception get(final int i) {
77  0 return (Exception) exceptions.get(i);
78    }
79   
80    /**
81    * Get all exceptions.
82    *
83    * @return All exceptions.
84    */
 
85  0 toggle public Exception[] toArray() {
86  0 return (Exception[]) exceptions.toArray(new Exception[0]);
87    }
88   
 
89  0 toggle public String toString() {
90  0 final StringBuffer buffer = new StringBuffer();
91  0 for (int i = 0; i < size(); i++) {
92  0 if (i != 0) {
93  0 buffer.append("\n");
94    }
95  0 final Exception e = get(i);
96  0 if (e instanceof SAXParseException) {
97  0 final SAXParseException ex = (SAXParseException) e;
98  0 buffer.append(ex.getSystemId() != null ? ex.getPublicId() + " " : "");
99  0 buffer.append(ex.getSystemId() != null ? ex.getSystemId() + " " : "");
100  0 buffer.append(ex.getLineNumber() != -1 ? "Row: " + ex.getLineNumber() + ". " : "");
101  0 buffer.append(ex.getColumnNumber() != -1 ? "Column: " + ex.getColumnNumber() + ". " : "");
102  0 buffer.append((ex.getException() != null ? ex.getException().getMessage() : ex.getMessage()));
103    } else {
104  0 buffer.append(get(i));
105    }
106    }
107  0 return buffer.toString();
108    }
109   
110    }