1 22 23 package org.xquark.mediator.DOMUtils; 24 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 28 import org.xquark.xpath.datamodel.TypedNode; 29 import org.xquark.xquery.parser.XQueryExpression; 30 31 public class BufferTuple extends ArrayList { 32 private static final String RCSRevision = "$Revision: 1.10 $"; 36 private static final String RCSName = "$Name: $"; 37 44 private ArrayList pathlist = null; 46 private HashMap indexpaths = null; 47 private long identifier = 0; 48 private ArrayList indexes = null; private ArrayList indexesSpec = null; private int idsize = 0; 51 52 60 public BufferTuple(ArrayList list, int idsize) { 61 if (list == null) 62 return; 63 this.idsize = idsize; 64 pathlist = new ArrayList (list.size()); 66 indexpaths = new HashMap (list.size()); 67 68 for (int i = 0; i < list.size(); i++) { 69 XQueryExpression tmpExpri = (XQueryExpression) list.get(i); 70 pathlist.add(tmpExpri.getStringValue()); 81 indexpaths.put(tmpExpri.getStringValue(), new Integer (i)); 82 } 83 } 84 85 public long getIdentifier() { 89 identifier++; 90 return identifier - 1; 91 } 92 public int getPathIndex(String path) { 93 if (indexpaths == null) 94 return -1; 95 Integer idx = (Integer ) indexpaths.get(path); 96 if (idx == null) 97 return -1; 98 return idx.intValue(); 99 } 100 public HashMap getIndexPath() { 101 return indexpaths; 102 } 103 public ArrayList getPathList() { 104 return pathlist; 105 } 106 107 public void add(Tuple tuple) { 109 super.add(tuple); 110 tuple.setParent(this); 111 fillIndexes(tuple); 113 } 114 public void add(int index, Tuple tuple) { 115 super.add(index, tuple); 116 tuple.setParent(this); 117 fillIndexes(tuple); 119 } 120 private void fillIndexes(Tuple tuple) { 121 if (this.indexesSpec != null && !this.indexesSpec.isEmpty()) { 122 if (this.indexes == null) 123 this.indexes = new ArrayList (indexesSpec.size()); 124 for (int i = 0; i < this.indexesSpec.size(); i++) { 125 ArrayList indexspeci = (ArrayList ) this.indexesSpec.get(i); 126 TupleKey valuelist = new TupleKey(indexspeci.size(), ((XQueryExpression) indexspeci.get(indexspeci.size() - 1)).getOrder(0)); 127 for (int j = 0; j < indexspeci.size(); j++) { 128 XQueryExpression indexspecistrj = (XQueryExpression) indexspeci.get(j); 129 ArrayList tmpnodes = tuple.getPath(indexspecistrj.getStringValue()); 130 if (tmpnodes != null) 131 valuelist.add(((TypedNode) tmpnodes.get(0)).getExtendedTypedValue()); 132 } 133 if (valuelist.isEmpty()) 134 continue; 135 if (this.getIndex(i) == null) 136 this.addIndex(new SortedKeyMap()); 137 SortedKeyMap sortedmap = this.getIndex(i); 138 ArrayList tuplelist = (ArrayList ) sortedmap.get(valuelist); 139 if (tuplelist == null) { 140 tuplelist = new ArrayList (1); 141 sortedmap.put(valuelist, tuplelist); 142 } 143 tuplelist.add(tuple); 144 } 145 } 146 } 147 148 public void removeLast() { 149 super.remove(size() - 1); 150 } 151 public int getPos(String path) { 153 for (int i = 0; i < pathlist.size(); i++) { 154 String pathi = (String ) pathlist.get(i); 155 if (pathi.equals(path)) 156 return i; 157 } 158 return -1; 159 } 160 public Tuple newTuple() { 161 Tuple newTuple = new Tuple(pathlist.size(), idsize); 162 newTuple.setParent(this); 163 return newTuple; 164 } 165 169 public void setIndexesSpec(ArrayList indexesSpec) { 171 this.indexesSpec = indexesSpec; 172 } 173 public ArrayList getIndexesSpec() { 174 return this.indexesSpec; 175 } 176 public ArrayList getIndexSpec(int index) { 177 return (ArrayList ) this.indexesSpec.get(index); 178 } 179 public int addIndexSpec(ArrayList list) { 180 if (this.indexesSpec == null) 181 this.indexesSpec = new ArrayList (); 182 this.indexesSpec.add(list); 183 return this.indexesSpec.size(); 184 } 185 public ArrayList getIndexes() { 187 return this.indexes; 188 } 189 public SortedKeyMap getIndex(int index) { 190 if (this.indexes == null) 191 return null; 192 if (this.indexes.size() <= index) 193 return null; 194 return (SortedKeyMap) this.indexes.get(index); 195 } 196 public int addIndex(SortedKeyMap map) { 197 if (this.indexes == null) 198 this.indexes = new ArrayList (); 199 this.indexes.add(map); 200 return this.indexes.size(); 201 } 202 208 public String toString() { 209 StringBuffer sb = new StringBuffer (); 210 for (int i = 0; i < pathlist.size(); i++) { 211 sb.append(pathlist.get(i)); 212 sb.append("\t"); 213 } 214 sb.append("\n---------------------------------------------------\n"); 215 for (int i = 0; i < size(); i++) { 216 sb.append(((Tuple) get(i)).toCompleteString()); 217 sb.append("\n-----------------------------------------------\n"); 218 } 219 return sb.toString(); 220 } 221 } 222 | Popular Tags |