1 5 6 package org.exoplatform.services.jcr.impl.util; 7 8 import java.util.Iterator ; 9 import javax.jcr.NodeIterator; 10 import javax.jcr.PropertyIterator; 11 import javax.jcr.nodetype.NodeTypeIterator; 12 import javax.jcr.Node; 13 import javax.jcr.Item; 14 import javax.jcr.Property; 15 import javax.jcr.nodetype.NodeType; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 import java.util.Collection ; 19 20 21 import javax.jcr.StringIterator; 22 import org.exoplatform.services.jcr.impl.core.ItemIterator; 23 24 30 31 public class EntityCollection 32 implements NodeIterator, PropertyIterator, ItemIterator, 33 NodeTypeIterator, StringIterator { 34 35 private Iterator iter; 36 private List list; 37 private long pos; 38 39 public EntityCollection(List list) { 40 if (list == null) 41 this.list = new ArrayList (); 42 else 43 this.list = list; 44 45 this.iter = list.iterator(); 46 this.pos = 0; 47 } 48 49 public EntityCollection() { 50 this.list = new ArrayList (); 51 this.iter = list.iterator(); 52 this.pos = 0; 53 } 54 55 56 59 public Node nextNode() { 60 pos++; 61 return (Node) iter.next(); 62 } 63 64 67 public void skip(int skipNum) { 68 pos += skipNum; 69 while (skipNum-- > 0) { 70 iter.next(); 71 } 72 } 73 74 80 public long getSize() { 81 return list.size(); 82 } 83 84 94 public long getPos() { 95 return pos; 96 } 97 98 101 public Item nextItem() { 102 pos++; 103 return (Item) iter.next(); 104 } 105 106 109 public boolean hasNext() { 110 return iter.hasNext(); 111 } 112 113 116 public Object next() { 117 pos++; 118 return iter.next(); 119 } 120 121 124 public void remove() { 125 iter.remove(); 126 } 127 128 131 public Property nextProperty() { 132 pos++; 133 return (Property) iter.next(); 134 } 135 136 143 public String nextString() { 144 pos++; 145 return (String ) iter.next(); 146 } 147 148 149 152 public NodeType nextNodeType() { 153 pos++; 154 return (NodeType) iter.next(); 155 } 156 157 160 165 public void add(Object obj) { 166 pos = 0; 167 list.add(obj); 168 iter = list.iterator(); 169 } 170 171 public void addAll(Collection col) { 172 pos = 0; 173 list.addAll(col); 174 iter = list.iterator(); 175 } 176 177 public void remove(Object obj) { 178 pos = 0; 179 list.remove(obj); 180 iter = list.iterator(); 181 } 182 183 public long size() { 184 return getSize(); 185 } 186 187 public List getList() { 188 return list; 189 } 190 191 } 192 | Popular Tags |