KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > misc > lib > StringBufferHelper


1 /*====================================================================
2
3 ObjectWeb Util Package.
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 --------------------------------------------------------------------
26 $Id: StringBufferHelper.java,v 1.1 2004/02/13 17:46:07 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.misc.lib;
30
31 /**
32  * Some helper functions for the java.lang.StringBuffer class.
33  *
34  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
35  * @version 0.1
36  */

37 public abstract class StringBufferHelper
38 {
39     // ==================================================================
40
//
41
// Internal state.
42
//
43
// ==================================================================
44

45     // ==================================================================
46
//
47
// Constructors.
48
//
49
// ==================================================================
50

51     // ==================================================================
52
//
53
// Internal methods.
54
//
55
// ==================================================================
56

57     // ==================================================================
58
//
59
// Static public methods.
60
//
61
// ==================================================================
62

63     /**
64      * Appends a string to the given string buffer.
65      *
66      * @param sb The string buffer.
67      * @param string The string.
68      */

69     public static void append(StringBuffer JavaDoc sb, String JavaDoc string) {
70         sb.append('\"');
71         sb.append(string);
72         sb.append('\"');
73     }
74
75     /**
76      * Appends a string array to the given string buffer.
77      *
78      * @param sb The string buffer.
79      * @param strings The string array.
80      */

81     public static void append(StringBuffer JavaDoc sb, String JavaDoc[] strings) {
82         sb.append('{');
83         if(strings.length > 0) {
84             append(sb, strings[0]);
85             for(int i=1; i<strings.length; i++) {
86                 sb.append(',');
87                 append(sb, strings[i]);
88             }
89         }
90         sb.append('}');
91     }
92
93     /**
94      * Appends a <name,value> pair to the given string buffer.
95      *
96      * @param sb The string buffer.
97      * @param name The name.
98      * @param value The value.
99      */

100     public static void append(StringBuffer JavaDoc sb, String JavaDoc name, boolean value) {
101         sb.append(name);
102         sb.append('=');
103         sb.append(value);
104         sb.append(',');
105     }
106
107     /**
108      * Appends a <name,value> pair to the given string buffer.
109      *
110      * @param sb The string buffer.
111      * @param name The name.
112      * @param value The value.
113      */

114     public static void append(StringBuffer JavaDoc sb, String JavaDoc name, int value) {
115         sb.append(name);
116         sb.append('=');
117         sb.append(value);
118         sb.append(',');
119     }
120
121     /**
122      * Appends a <name,value> pair to the given string buffer.
123      *
124      * @param sb The string buffer.
125      * @param name The name.
126      * @param value The value.
127      */

128     public static void append(StringBuffer JavaDoc sb, String JavaDoc name, String JavaDoc value) {
129         sb.append(name);
130         sb.append('=');
131         append(sb, value);
132         sb.append(',');
133     }
134
135     /**
136      * Appends a <name,value> pair to the given string buffer.
137      *
138      * @param sb The string buffer.
139      * @param name The name.
140      * @param value The value.
141      */

142     public static void append(StringBuffer JavaDoc sb, String JavaDoc name, String JavaDoc[] value) {
143         sb.append(name);
144         sb.append('=');
145         append(sb, value);
146         sb.append(',');
147     }
148
149     /**
150      * Appends a given array of strings to a given string buffer
151      * and separates items with a given separator.
152      *
153      * @param sb The given string buffer.
154      * @param strings The given array of strings.
155      * @param separator The given sperator.
156      */

157     public static void append(StringBuffer JavaDoc sb, String JavaDoc[] strings, String JavaDoc separator) {
158         if(strings.length > 0) {
159             sb.append(strings[0]);
160             for(int i=1; i<strings.length; i++) {
161                 sb.append(separator);
162                 sb.append(strings[i]);
163             }
164         }
165     }
166
167     // ==================================================================
168
//
169
// Other public methods.
170
//
171
// ==================================================================
172
}
173
Popular Tags