1 package net.sf.saxon.event; 2 import net.sf.saxon.om.*; 3 import net.sf.saxon.value.EmptySequence; 4 import net.sf.saxon.value.SequenceExtent; 5 6 import java.util.ArrayList ; 7 8 9 26 27 public final class SequenceOutputter extends SequenceWriter { 28 29 private ArrayList list; 30 31 34 35 public SequenceOutputter() { 36 this.list = new ArrayList (50); 37 } 38 39 public SequenceOutputter(int estimatedSize) { 40 this.list = new ArrayList (estimatedSize); 41 } 42 43 46 47 public void write(Item item) { 48 list.add(item); 49 } 50 51 54 55 public ValueRepresentation getSequence() { 56 switch (list.size()) { 57 case 0: 58 return EmptySequence.getInstance(); 59 case 1: 60 return (Item)list.get(0); 61 default: 62 return new SequenceExtent(list); 63 } 64 } 65 66 69 70 public SequenceIterator iterate() { 71 if (list.size() == 0) { 72 return EmptyIterator.getInstance(); 73 } else { 74 return new ListIterator(list); 75 } 76 } 77 78 81 82 public ArrayList getList() { 83 return list; 84 } 85 86 89 90 public Item getFirstItem() { 91 if (list.size() == 0) { 92 return null; 93 } else { 94 return (Item)list.get(0); 95 } 96 } 97 98 101 102 public Item popLastItem() { 103 if (list.size() == 0) { 104 return null; 105 } else { 106 return (Item)list.remove(list.size()-1); 107 } 108 } 109 110 111 } 112 113 | Popular Tags |