1 package net.sf.saxon.sort; 2 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.om.SequenceIterator; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.value.EmptySequence; 7 import net.sf.saxon.value.ObjectValue; 8 import net.sf.saxon.value.Value; 9 10 16 17 class SortedTupleIterator extends SortedIterator { 18 19 22 public SortedTupleIterator(XPathContext context, SequenceIterator base, 23 FixedSortKeyDefinition[] sortKeys) throws XPathException { 24 super(context, base, sortKeys); 25 } 26 27 31 32 protected void buildArray() throws XPathException { 33 int allocated = 100; 34 nodeKeys = new Object [allocated * recordSize]; 35 count = 0; 36 37 39 while (true) { 40 ObjectValue tupleObject = (ObjectValue)base.next(); 41 if (tupleObject == null) { 42 break; 43 } 44 Value[] tuple = (Value[])tupleObject.getObject(); 45 if (count==allocated) { 46 allocated *= 2; 47 Object [] nk2 = new Object [allocated * recordSize]; 48 System.arraycopy(nodeKeys, 0, nk2, 0, count * recordSize); 49 nodeKeys = nk2; 50 } 51 int k = count*recordSize; 52 nodeKeys[k] = new ObjectValue(tuple[0]); 53 for (int n=1; n<=sortkeys.length; n++) { 58 Value v = tuple[n].reduce(); 59 if (v instanceof EmptySequence) { 60 nodeKeys[k+n] = null; 61 } else { 62 nodeKeys[k+n] = v; 63 } 64 } 65 nodeKeys[k+sortkeys.length+1] = new Integer (count); 66 count++; 67 } 68 } 69 } 70 71 72 | Popular Tags |