1 17 18 package com.finalist.jag.template; 19 20 21 import java.util.*; 22 23 24 31 public class TemplateTextBlockList extends LinkedList { 32 33 39 public TemplateTextBlockList() { 40 } 41 42 43 50 public void add(TemplateTextBlock block) { 51 this.addLast(block); 52 } 53 54 55 66 public TemplateTextBlockList cut(TemplateTextBlock block1, 67 TemplateTextBlock block2) { 68 69 TemplateTextBlockList list = new TemplateTextBlockList(); 70 int nIndex1 = indexOf(block1); 71 int nIndex2 = indexOf(block2); 72 73 while ((nIndex1 != -1) && (nIndex1 <= nIndex2)) { 74 list.add(list.get(nIndex1)); 75 remove(nIndex1++); 76 } 77 78 return list; 79 } 80 81 82 91 public TemplateTextBlock getBefore(TemplateTextBlock block) { 92 93 int nIndex = indexOf(block); 94 95 if (nIndex == -1) { 96 return null; 97 } 98 99 ListIterator iterator = listIterator(nIndex); 100 101 return iterator.hasPrevious() 102 ? (TemplateTextBlock) iterator.previous() 103 : null; 104 } 105 106 107 116 public TemplateTextBlock getAfter(TemplateTextBlock block) { 117 118 int nIndex = indexOf(block); 119 120 if (nIndex == -1) { 121 return null; 122 } 123 124 ListIterator iterator = listIterator(nIndex); 125 126 return iterator.hasNext() 127 ? (TemplateTextBlock) iterator.next() 128 : null; 129 } 130 131 132 139 public StringBuffer getStringBuffer() { 140 141 StringBuffer returnValue = new StringBuffer (); 142 ListIterator iterator = listIterator(); 143 144 while (iterator.hasNext()) { 145 returnValue 146 .append(((TemplateTextBlock) iterator.next()).getText()); 147 } 148 149 return returnValue; 150 } 151 152 153 160 public TemplateTextBlock[] toTextBlockArray() { 161 return (TemplateTextBlock[]) super 162 .toArray(new TemplateTextBlock[size()]); 163 } 164 } | Popular Tags |