Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 201   Methods: 21
NCLOC: 104   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContentListFacade.java 8,3% 27,9% 38,1% 27,6%
coverage coverage
 1    /*
 2    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 3    *
 4    * This software is open source.
 5    * See the bottom of this file for the licence.
 6    *
 7    * $Id: ContentListFacade.java,v 1.8 2004/06/25 12:34:50 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.tree;
 11   
 12    import java.util.AbstractList;
 13    import java.util.Collection;
 14    import java.util.Iterator;
 15    import java.util.List;
 16   
 17    import org.dom4j.IllegalAddException;
 18    import org.dom4j.Node;
 19   
 20    /** <p><code>ContentListFacade</code> represents a facade of the
 21    * content of a {@link org.dom4j.Branch} which is returned via calls to the
 22    * {@link org.dom4j.Branch#content} method to allow users to modify the content
 23    * of a {@link org.dom4j.Branch} directly using the {@link List} interface.
 24    * This list is backed by the branch such that changes to the list will
 25    * be reflected in the branch and changes to the branch will be reflected
 26    * be reflected in this list.</p>
 27    *
 28    * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
 29    * @version $Revision: 1.8 $
 30    */
 31    public class ContentListFacade extends AbstractList {
 32   
 33    /** The content of the Branch which is modified if I am modified */
 34    private List branchContent;
 35   
 36    /** The <code>AbstractBranch</code> instance which owns the content */
 37    private AbstractBranch branch;
 38   
 39   
 40  9790 public ContentListFacade(AbstractBranch branch, List branchContent) {
 41  9790 this.branch = branch;
 42  9790 this.branchContent = branchContent;
 43    }
 44   
 45  0 public boolean add(Object object) {
 46  0 branch.childAdded( asNode( object ) );
 47  0 return branchContent.add(object);
 48    }
 49   
 50  10 public void add(int index, Object object) {
 51  10 branch.childAdded( asNode( object ) );
 52  10 branchContent.add(index, object);
 53    }
 54   
 55  2 public Object set(int index, Object object) {
 56  2 branch.childAdded( asNode( object ) );
 57  2 return branchContent.set(index, object);
 58    }
 59   
 60  0 public boolean remove(Object object) {
 61  0 branch.childRemoved( asNode( object ) );
 62  0 return branchContent.remove(object);
 63    }
 64   
 65  0 public Object remove(int index) {
 66  0 Object object = branchContent.remove(index);
 67  0 if ( object != null ) {
 68  0 branch.childRemoved( asNode( object ) );
 69    }
 70  0 return object;
 71    }
 72   
 73  0 public boolean addAll(Collection collection) {
 74  0 int count = branchContent.size();
 75  0 for (Iterator iter = collection.iterator(); iter.hasNext(); count++ ) {
 76  0 add(iter.next());
 77    }
 78  0 return count == branchContent.size();
 79    }
 80   
 81  0 public boolean addAll(int index, Collection collection) {
 82  0 int count = branchContent.size();
 83  0 for (Iterator iter = collection.iterator(); iter.hasNext(); count-- ) {
 84  0 add(index++, iter.next());
 85    }
 86  0 return count == branchContent.size();
 87    }
 88   
 89  0 public void clear() {
 90  0 for ( Iterator iter = iterator(); iter.hasNext(); ) {
 91  0 Object object = iter.next();
 92  0 branch.childRemoved( asNode( object ) );
 93    }
 94  0 branchContent.clear();
 95    }
 96   
 97  0 public boolean removeAll(Collection c) {
 98  0 for ( Iterator iter = c.iterator(); iter.hasNext(); ) {
 99  0 Object object = iter.next();
 100  0 branch.childRemoved( asNode( object ) );
 101    }
 102  0 return branchContent.removeAll(c);
 103    }
 104   
 105  10032 public int size() {
 106  10032 return branchContent.size();
 107    }
 108   
 109  0 public boolean isEmpty() {
 110  0 return branchContent.isEmpty();
 111    }
 112   
 113  0 public boolean contains(Object o) {
 114  0 return branchContent.contains(o);
 115    }
 116   
 117  0 public Object[] toArray() {
 118  0 return branchContent.toArray();
 119    }
 120   
 121  0 public Object[] toArray(Object[] a) {
 122  0 return branchContent.toArray(a);
 123    }
 124   
 125  0 public boolean containsAll(Collection c) {
 126  0 return branchContent.containsAll(c);
 127    }
 128   
 129  26760 public Object get(int index) {
 130  26760 return branchContent.get(index);
 131    }
 132   
 133  4 public int indexOf(Object o) {
 134  4 return branchContent.indexOf(o);
 135    }
 136   
 137  0 public int lastIndexOf(Object o) {
 138  0 return branchContent.lastIndexOf(o);
 139    }
 140   
 141  12 protected Node asNode(Object object) {
 142  12 if (object instanceof Node) {
 143  12 return (Node) object;
 144    }
 145    else {
 146  0 throw new IllegalAddException( "This list must contain instances of Node. Invalid type: "+ object );
 147    }
 148    }
 149   
 150  4 protected List getBackingList() {
 151  4 return branchContent;
 152    }
 153    }
 154   
 155   
 156   
 157   
 158    /*
 159    * Redistribution and use of this software and associated documentation
 160    * ("Software"), with or without modification, are permitted provided
 161    * that the following conditions are met:
 162    *
 163    * 1. Redistributions of source code must retain copyright
 164    * statements and notices. Redistributions must also contain a
 165    * copy of this document.
 166    *
 167    * 2. Redistributions in binary form must reproduce the
 168    * above copyright notice, this list of conditions and the
 169    * following disclaimer in the documentation and/or other
 170    * materials provided with the distribution.
 171    *
 172    * 3. The name "DOM4J" must not be used to endorse or promote
 173    * products derived from this Software without prior written
 174    * permission of MetaStuff, Ltd. For written permission,
 175    * please contact dom4j-info@metastuff.com.
 176    *
 177    * 4. Products derived from this Software may not be called "DOM4J"
 178    * nor may "DOM4J" appear in their names without prior written
 179    * permission of MetaStuff, Ltd. DOM4J is a registered
 180    * trademark of MetaStuff, Ltd.
 181    *
 182    * 5. Due credit should be given to the DOM4J Project -
 183    * http://www.dom4j.org
 184    *
 185    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 186    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 187    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 188    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 189    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 190    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 191    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 192    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 193    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 194    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 195    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 196    * OF THE POSSIBILITY OF SUCH DAMAGE.
 197    *
 198    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 199    *
 200    * $Id: ContentListFacade.java,v 1.8 2004/06/25 12:34:50 maartenc Exp $
 201    */