dom4j - 1.6.1

Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00
FRAMES NO FRAMES

file stats: | LOC: | 200 |  | Methods: | 21
| NCLOC: | 105 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ContentListFacade.java

8,3%

27,9%

38,1%

27,6%

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