1 16 package org.apache.commons.jxpath; 17 18 import java.util.ArrayList ; 19 import java.util.Collections ; 20 import java.util.List ; 21 22 27 public class BasicNodeSet implements NodeSet { 28 private List pointers = new ArrayList (); 29 private List readOnlyPointers; 30 private List nodes; 31 private List values; 32 33 public void add(Pointer pointer) { 34 pointers.add(pointer); 35 readOnlyPointers = null; 36 } 37 38 public void remove(Pointer pointer) { 39 pointers.remove(pointer); 40 readOnlyPointers = null; 41 } 42 43 public List getPointers() { 44 if (readOnlyPointers == null) { 45 readOnlyPointers = Collections.unmodifiableList(pointers); 46 } 47 return readOnlyPointers; 48 } 49 50 public List getNodes() { 51 if (nodes == null) { 52 nodes = new ArrayList (); 53 for (int i = 0; i < pointers.size(); i++) { 54 Pointer pointer = (Pointer) pointers.get(i); 55 nodes.add(pointer.getValue()); 56 } 57 nodes = Collections.unmodifiableList(nodes); 58 } 59 return nodes; 60 } 61 62 public List getValues() { 63 if (values == null) { 64 values = new ArrayList (); 65 for (int i = 0; i < pointers.size(); i++) { 66 Pointer pointer = (Pointer) pointers.get(i); 67 values.add(pointer.getValue()); 68 } 69 values = Collections.unmodifiableList(values); 70 } 71 return values; 72 } 73 74 public String toString() { 75 return pointers.toString(); 76 } 77 } 78 | Popular Tags |