Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 121   Methods: 6
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SyntaxExceptionList.java 10% 24% 66,7% 23,5%
coverage coverage
 1    /* $Id: SyntaxExceptionList.java,v 1.1 2007/04/12 23:50:10 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.common;
 19   
 20    import java.util.ArrayList;
 21    import java.util.List;
 22   
 23    import org.xml.sax.SAXException;
 24    import org.xml.sax.SAXParseException;
 25   
 26   
 27    /**
 28    * Type save SyntaxException list.
 29    *
 30    * @version $Revision: 1.1 $
 31    * @author Michael Meyling
 32    */
 33    public final class SyntaxExceptionList {
 34   
 35    /** List with parse exceptions. */
 36    private List exceptions;
 37   
 38    /** Maximum number of exceptions. */
 39    public static final int MAXIMUM = 10;
 40   
 41    /**
 42    * Constructor.
 43    */
 44  389 public SyntaxExceptionList() {
 45  389 exceptions = new ArrayList(MAXIMUM);
 46    }
 47   
 48    /**
 49    * Add Exception. This is only done if the number of already collected exceptions is below
 50    * {@link #MAXIMUM}.
 51    *
 52    * @param e Exception to add.
 53    * @throws SAXException Maximum number of exception reached.
 54    */
 55  10 public final void add(final SyntaxException e) throws SAXException {
 56  10 if (e == null) {
 57  0 final NullPointerException ex = new NullPointerException("Exception expected!");
 58  0 exceptions.add(ex);
 59  0 throw ex;
 60    }
 61  10 if (size() < MAXIMUM) {
 62  10 exceptions.add(e);
 63    } else {
 64  0 throw new SAXException("Too much errors already occurred.");
 65    }
 66    }
 67   
 68    /**
 69    * Get number of collected exceptions.
 70    *
 71    * @return Number of collected exceptions.
 72    */
 73  276 public final int size() {
 74  276 return exceptions.size();
 75    }
 76   
 77    /**
 78    * Get <code>i</code>-th exception.
 79    *
 80    * @param i Starts with 0 and must be smaller than {@link #size()}.
 81    * @return Wanted exception.
 82    */
 83  10 public final SyntaxException get(final int i) {
 84  10 return (SyntaxException) exceptions.get(i);
 85    }
 86   
 87    /**
 88    * Get all exceptions.
 89    *
 90    * @return All exceptions.
 91    */
 92  0 public final SyntaxException[] toArray() {
 93  0 return (SyntaxException[]) exceptions.toArray(new SyntaxException[0]);
 94    }
 95   
 96  0 public String toString() {
 97  0 final StringBuffer buffer = new StringBuffer();
 98  0 for (int i = 0; i < size(); i++) {
 99  0 if (i != 0) {
 100  0 buffer.append("\n");
 101    }
 102  0 final Exception e = get(i);
 103  0 if (e instanceof SAXParseException) {
 104  0 final SAXParseException ex = (SAXParseException) e;
 105  0 buffer.append(ex.getSystemId() != null ? ex.getPublicId() + " " : "");
 106  0 buffer.append(ex.getSystemId() != null ? ex.getSystemId() + " " : "");
 107  0 buffer.append(ex.getLineNumber() != -1 ? "Row: " + ex.getLineNumber() + ". " : "");
 108  0 buffer.append(ex.getColumnNumber() != -1
 109    ? "Column: " + ex.getColumnNumber() + ". "
 110    : "");
 111  0 buffer.append((ex.getException() != null
 112    ? ex.getException().getMessage()
 113    : ex.getMessage()));
 114    } else {
 115  0 buffer.append(get(i));
 116    }
 117    }
 118  0 return buffer.toString();
 119    }
 120   
 121    }