source: branches/0.17.x/abcl/src/org/armedbear/lisp/FastStringBuffer.java

Last change on this file was 11527, checked in by Mark Evenson, 17 years ago

(Phil Hudson) Make FastStringBuffer? an adapter to java-1.5's StringBuilder?.

JUnit tests integrated into 'build.xml', run via 'ant abcl.test'.

Further integration with other build systems (Lisp and Netbeans) has not been done.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/*
2 * FastStringBuffer.java
3 *
4 * Copyright (C) 1998-2005 Peter Graves
5 * Copyright (C) 2008 Phil Hudson
6 * $Id: FastStringBuffer.java 11527 2009-01-03 12:30:16Z mevenson $
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 *
22 * As a special exception, the copyright holders of this library give you
23 * permission to link this library with independent modules to produce an
24 * executable, regardless of the license terms of these independent
25 * modules, and to copy and distribute the resulting executable under
26 * terms of your choice, provided that you also meet, for each linked
27 * independent module, the terms and conditions of the license of that
28 * module.  An independent module is a module which is not derived from
29 * or based on this library.  If you modify this library, you may extend
30 * this exception to your version of the library, but you are not
31 * obligated to do so.  If you do not wish to do so, delete this
32 * exception statement from your version.
33 */
34
35package org.armedbear.lisp;
36
37/**
38 * An adaptor of the Java 1.5 java.lang.StringBuilder.
39 *
40 * "This class should be removed with all references to it replaced
41 *  with java.lang.StringBuilder once enough confidence in this change
42 *  has been gained." -- Phil Hudson 20090202 via <armedbear-j-devel>.
43 */
44public final class FastStringBuffer implements Appendable, CharSequence
45{
46  private static final int SPARE_CAPACITY = 128;
47
48  private final StringBuilder builder;
49
50  public FastStringBuffer()
51  {
52    this(SPARE_CAPACITY);
53  }
54
55  public FastStringBuffer(String s) 
56  {
57    builder = new StringBuilder(s);
58  }
59
60  public FastStringBuffer(char c)
61  {
62    this(String.valueOf(c));
63  }
64
65  public FastStringBuffer(int length) throws NegativeArraySizeException
66  {
67    builder = new StringBuilder(length);
68  }
69
70  public final int length()
71  {
72    return builder.length();
73  }
74
75  public final int capacity()
76  {
77    return builder.capacity();
78  }
79
80  public final char charAt(int index)
81  {
82    return builder.charAt(index);
83  }
84
85  public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)
86  {
87    builder.getChars(srcBegin, srcEnd, dst, dstBegin);
88  }
89
90  public void setCharAt(int index, char c)
91  {
92    builder.setCharAt(index, c);
93  }
94
95  public void ensureCapacity(int minimumCapacity)
96  {
97    builder.ensureCapacity(minimumCapacity);
98  }
99
100  public FastStringBuffer append(String s)
101  {
102    builder.append(s);
103    return this;
104  }
105
106  public FastStringBuffer append(char[] chars)
107  {
108    builder.append(chars);
109    return this;
110  }
111
112  public FastStringBuffer append(char[] chars, int offset, int len)
113  {
114    builder.append(chars, offset, len);
115    return this;
116  }
117
118  public FastStringBuffer append(Object object)
119  {
120    return append(String.valueOf(object));
121  }
122
123  public FastStringBuffer append(char c)
124  {
125    builder.append(c);
126    return this;
127  }
128
129  public final FastStringBuffer append(int n)
130  {
131    return append(String.valueOf(n));
132  }
133
134  public final FastStringBuffer append(long n)
135  {
136    return append(String.valueOf(n));
137  }
138
139  public void setLength(int newLength) throws IndexOutOfBoundsException
140  {
141    builder.setLength(newLength);
142  }
143
144  public FastStringBuffer reverse()
145  {
146    builder.reverse();
147    return this; 
148  }
149
150  @Override
151  public final String toString()
152  {
153    return builder.toString();
154  }
155
156  public final char[] toCharArray()
157  {
158    return toString().toCharArray();
159  }
160
161   public CharSequence subSequence(int start, int end)
162  {
163    return builder.subSequence(start, end);
164   }
165 
166   public FastStringBuffer append(CharSequence seq)
167   {
168     builder.append(seq);
169     return this;
170   }
171 
172   public FastStringBuffer append(CharSequence seq, int start, int end)
173   {
174     builder.append(seq, start, end);
175     return this;
176   }
177}
Note: See TracBrowser for help on using the repository browser.