Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 105   Methods: 7
NCLOC: 34   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Namespaces.java 100% 100% 100% 100%
coverage
 1    /* Copyright 2002-2006 Elliotte Rusty Harold
 2   
 3    This library is free software; you can redistribute it and/or modify
 4    it under the terms of version 2.1 of the GNU Lesser General Public
 5    License as published by the Free Software Foundation.
 6   
 7    This library is distributed in the hope that it will be useful,
 8    but WITHOUT ANY WARRANTY; without even the implied warranty of
 9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 10    GNU Lesser General Public License for more details.
 11   
 12    You should have received a copy of the GNU Lesser General Public
 13    License along with this library; if not, write to the
 14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 15    Boston, MA 02111-1307 USA
 16   
 17    You can contact Elliotte Rusty Harold by sending e-mail to
 18    elharo@metalab.unc.edu. Please include the word "XOM" in the
 19    subject line. The XOM home page is located at http://www.xom.nu/
 20    */
 21   
 22    package nu.xom;
 23   
 24    import java.util.ArrayList;
 25    import java.util.HashMap;
 26   
 27    /**
 28    * <p>
 29    * The <code>Namespaces</code> container is a read-only list
 30    * used to hold the additional namespace declarations of an
 31    * element. It provides indexed access for convenience,
 32    * but the order is neither predictable nor reproducible,
 33    * and has no meaning.
 34    * </p>
 35    *
 36    * @author Elliotte Rusty Harold
 37    * @version 1.2d1
 38    */
 39    class Namespaces {
 40   
 41    private HashMap namespaces = new HashMap(1);
 42    private ArrayList prefixes = new ArrayList(1);
 43   
 44   
 45  1427 void put(String prefix, String URI) {
 46  1427 namespaces.put(prefix, URI);
 47  1427 prefixes.remove(prefix);
 48  1427 prefixes.add(prefix);
 49    }
 50   
 51   
 52  12 void remove(String prefix) {
 53  1 if (prefix == null) prefix = "";
 54  12 namespaces.remove(prefix);
 55  12 prefixes.remove(prefix);
 56    }
 57   
 58   
 59    /**
 60    * <p>
 61    * Return the URI associated with a prefix, as determined
 62    * by the namespaces stored in this list. This method
 63    * returns null if the prefix is not found in the list.
 64    * </p>
 65    *
 66    * @param prefix the prefix whose URI is desired
 67    *
 68    * @return the namespace URI for this prefix, or null if this
 69    * prefix is not not mapped to a URI by these namespace
 70    * declarations
 71    */
 72  2522 String getURI(String prefix) {
 73  2522 return (String) (namespaces.get(prefix));
 74    }
 75   
 76   
 77    // This violates encapsulation. Don't change the
 78    // array returned.
 79  2459 ArrayList getPrefixes() {
 80  2459 return this.prefixes;
 81    }
 82   
 83   
 84  69 Namespaces copy() {
 85   
 86  69 Namespaces result = new Namespaces();
 87    // shallow copies work here because these collections only
 88    // contain immutable strings
 89  69 result.namespaces = (HashMap) this.namespaces.clone();
 90  69 result.prefixes = (ArrayList) this.prefixes.clone();
 91  69 return result;
 92   
 93    }
 94   
 95   
 96  112 int size() {
 97  112 return prefixes.size();
 98    }
 99   
 100   
 101  149 String getPrefix(int i) {
 102  149 return (String) prefixes.get(i);
 103    }
 104   
 105    }