1 22 package org.jboss.ejb.plugins.cmp.ejbql; 23 24 import java.util.Iterator ; 25 import java.util.LinkedList ; 26 27 37 public final class BlockStringBuffer { 38 private LinkedList list = new LinkedList (); 39 private int length; 40 41 public BlockStringBuffer() { 42 } 43 44 public BlockStringBuffer append(boolean b) { 45 String string = String.valueOf(b); 46 length += string.length(); 47 list.addLast(string); 48 return this; 49 } 50 51 public BlockStringBuffer append(char c) { 52 String string = String.valueOf(c); 53 length += string.length(); 54 list.addLast(string); 55 return this; 56 } 57 58 public BlockStringBuffer append(char[] str) { 59 String string = String.valueOf(str); 60 length += string.length(); 61 list.addLast(string); 62 return this; 63 } 64 65 public BlockStringBuffer append(char[] str, int offset, int len) { 66 String string = String.valueOf(str, offset, len); 67 length += string.length(); 68 list.addLast(string); 69 return this; 70 } 71 72 public BlockStringBuffer append(double d) { 73 String string = String.valueOf(d); 74 length += string.length(); 75 list.addLast(string); 76 return this; 77 } 78 79 public BlockStringBuffer append(float f) { 80 String string = String.valueOf(f); 81 length += string.length(); 82 list.addLast(string); 83 return this; 84 } 85 86 public BlockStringBuffer append(int i) { 87 String string = String.valueOf(i); 88 length += string.length(); 89 list.addLast(string); 90 return this; 91 } 92 93 public BlockStringBuffer append(long l) { 94 String string = String.valueOf(l); 95 length += string.length(); 96 list.addLast(string); 97 return this; 98 } 99 100 public BlockStringBuffer append(Object obj) { 101 if(obj instanceof String ) { 102 String string = (String )obj; 103 length += string.length(); 104 list.addLast(string); 105 } else if(obj instanceof BlockStringBuffer) { 106 BlockStringBuffer buf = (BlockStringBuffer)obj; 107 length += buf.length; 108 list.addAll(buf.list); 109 } else { 110 String string = String.valueOf(obj); 111 length += string.length(); 112 list.addLast(string); 113 } 114 return this; 115 } 116 117 public BlockStringBuffer prepend(boolean b) { 118 String string = String.valueOf(b); 119 length += string.length(); 120 list.addFirst(string); 121 return this; 122 } 123 124 public BlockStringBuffer prepend(char c) { 125 String string = String.valueOf(c); 126 length += string.length(); 127 list.addFirst(string); 128 return this; 129 } 130 131 public BlockStringBuffer prepend(char[] str) { 132 String string = String.valueOf(str); 133 length += string.length(); 134 list.addFirst(string); 135 return this; 136 } 137 138 public BlockStringBuffer prepend(char[] str, int offset, int len) { 139 String string = String.valueOf(str, offset, len); 140 length += string.length(); 141 list.addFirst(string); 142 return this; 143 } 144 145 public BlockStringBuffer prepend(double d) { 146 String string = String.valueOf(d); 147 length += string.length(); 148 list.addFirst(string); 149 return this; 150 } 151 152 public BlockStringBuffer prepend(float f) { 153 String string = String.valueOf(f); 154 length += string.length(); 155 list.addFirst(string); 156 return this; 157 } 158 159 public BlockStringBuffer prepend(int i) { 160 String string = String.valueOf(i); 161 length += string.length(); 162 list.addFirst(string); 163 return this; 164 } 165 166 public BlockStringBuffer prepend(long l) { 167 String string = String.valueOf(l); 168 length += string.length(); 169 list.addFirst(string); 170 return this; 171 } 172 173 public BlockStringBuffer prepend(Object obj) { 174 if(obj instanceof String ) { 175 String string = (String )obj; 176 length += string.length(); 177 list.addFirst(string); 178 } else if(obj instanceof BlockStringBuffer) { 179 BlockStringBuffer buf = (BlockStringBuffer)obj; 180 length += buf.length; 181 list.addAll(0, buf.list); 182 } else { 183 String string = String.valueOf(obj); 184 length += string.length(); 185 list.addFirst(string); 186 } 187 return this; 188 } 189 190 public int length() { 191 return length; 192 } 193 194 public int size() { 195 return length; 196 } 197 198 public StringBuffer toStringBuffer() { 199 StringBuffer buf = new StringBuffer (length); 202 203 for(int i = 0; i < list.size(); i++) 204 { 205 buf.append( (String )list.get(i)); 206 } 207 return buf; 208 } 209 210 public String toString() { 211 return toStringBuffer().toString(); 212 } 213 } 214 | Popular Tags |