KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > StringList


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/rolap/StringList.java#4 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2001-2002 Kana Software, Inc.
7 // Copyright (C) 2001-2006 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // jhyde, 29 December, 2001
12 */

13
14 package mondrian.rolap;
15 import mondrian.olap.Util;
16
17 /**
18  * <code>StringList</code> makes it easy to build up a comma-separated string.
19  *
20  * @author jhyde
21  * @since 29 December, 2001
22  * @version $Id: //open/mondrian/src/main/mondrian/rolap/StringList.java#4 $
23  */

24 class StringList
25 {
26     private final StringBuilder JavaDoc buf;
27     private final String JavaDoc first, mid, last;
28     private int count;
29
30     StringList(String JavaDoc first, String JavaDoc mid)
31     {
32         this.buf = new StringBuilder JavaDoc(first);
33         this.count = 0;
34         this.first = first;
35         this.mid = mid;
36         this.last = "";
37     }
38     StringList(String JavaDoc first)
39     {
40         this(first, ", ");
41     }
42     int getCount()
43     {
44         return count;
45     }
46     boolean isEmpty()
47     {
48         return count == 0;
49     }
50     /** Creates a new item. */
51     void newItem(String JavaDoc s)
52     {
53         if (count++ > 0) {
54             buf.append(mid);
55         }
56         buf.append(s);
57     }
58     /** Appends to an existing item. */
59     void append(String JavaDoc s)
60     {
61         Util.assertTrue(count > 0);
62         buf.append(s);
63     }
64     // override Object
65
public String JavaDoc toString()
66     {
67         buf.append(last);
68         return buf.toString();
69     }
70 };
71
72
73 // End StringList.java
74
Popular Tags