1 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 31 public class ContentListFacade extends AbstractList { 32 33 private List branchContent; 34 35 36 private AbstractBranch branch; 37 38 public ContentListFacade(AbstractBranch branch, List branchContent) { 39 this.branch = branch; 40 this.branchContent = branchContent; 41 } 42 43 public boolean add(Object object) { 44 branch.childAdded(asNode(object)); 45 46 return branchContent.add(object); 47 } 48 49 public void add(int index, Object object) { 50 branch.childAdded(asNode(object)); 51 branchContent.add(index, object); 52 } 53 54 public Object set(int index, Object object) { 55 branch.childAdded(asNode(object)); 56 57 return branchContent.set(index, object); 58 } 59 60 public boolean remove(Object object) { 61 branch.childRemoved(asNode(object)); 62 63 return branchContent.remove(object); 64 } 65 66 public Object remove(int index) { 67 Object object = branchContent.remove(index); 68 69 if (object != null) { 70 branch.childRemoved(asNode(object)); 71 } 72 73 return object; 74 } 75 76 public boolean addAll(Collection collection) { 77 int count = branchContent.size(); 78 79 for (Iterator iter = collection.iterator(); iter.hasNext(); count++) { 80 add(iter.next()); 81 } 82 83 return count == branchContent.size(); 84 } 85 86 public boolean addAll(int index, Collection collection) { 87 int count = branchContent.size(); 88 89 for (Iterator iter = collection.iterator(); iter.hasNext(); count--) { 90 add(index++, iter.next()); 91 } 92 93 return count == branchContent.size(); 94 } 95 96 public void clear() { 97 for (Iterator iter = iterator(); iter.hasNext();) { 98 Object object = iter.next(); 99 branch.childRemoved(asNode(object)); 100 } 101 102 branchContent.clear(); 103 } 104 105 public boolean removeAll(Collection c) { 106 for (Iterator iter = c.iterator(); iter.hasNext();) { 107 Object object = iter.next(); 108 branch.childRemoved(asNode(object)); 109 } 110 111 return branchContent.removeAll(c); 112 } 113 114 public int size() { 115 return branchContent.size(); 116 } 117 118 public boolean isEmpty() { 119 return branchContent.isEmpty(); 120 } 121 122 public boolean contains(Object o) { 123 return branchContent.contains(o); 124 } 125 126 public Object [] toArray() { 127 return branchContent.toArray(); 128 } 129 130 public Object [] toArray(Object [] a) { 131 return branchContent.toArray(a); 132 } 133 134 public boolean containsAll(Collection c) { 135 return branchContent.containsAll(c); 136 } 137 138 public Object get(int index) { 139 return branchContent.get(index); 140 } 141 142 public int indexOf(Object o) { 143 return branchContent.indexOf(o); 144 } 145 146 public int lastIndexOf(Object o) { 147 return branchContent.lastIndexOf(o); 148 } 149 150 protected Node asNode(Object object) { 151 if (object instanceof Node) { 152 return (Node) object; 153 } else { 154 throw new IllegalAddException( 155 "This list must contain instances of " 156 + "Node. Invalid type: " + object); 157 } 158 } 159 160 protected List getBackingList() { 161 return branchContent; 162 } 163 } 164 165 201 | Popular Tags |