001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2001-2005 Julian Hyde 008// Copyright (C) 2005-2006 Pentaho and others 009// All Rights Reserved. 010// 011// jhyde, 29 December, 2001 012*/ 013package mondrian.rolap; 014 015import mondrian.olap.Util; 016 017/** 018 * <code>StringList</code> makes it easy to build up a comma-separated string. 019 * 020 * @author jhyde 021 * @since 29 December, 2001 022 */ 023class StringList 024{ 025 private final StringBuilder buf; 026 private final String first, mid, last; 027 private int count; 028 029 StringList(String first, String mid) 030 { 031 this.buf = new StringBuilder(first); 032 this.count = 0; 033 this.first = first; 034 this.mid = mid; 035 this.last = ""; 036 } 037 StringList(String first) 038 { 039 this(first, ", "); 040 } 041 int getCount() 042 { 043 return count; 044 } 045 boolean isEmpty() 046 { 047 return count == 0; 048 } 049 /** Creates a new item. */ 050 void newItem(String s) 051 { 052 if (count++ > 0) { 053 buf.append(mid); 054 } 055 buf.append(s); 056 } 057 /** Appends to an existing item. */ 058 void append(String s) 059 { 060 Util.assertTrue(count > 0); 061 buf.append(s); 062 } 063 // override Object 064 public String toString() 065 { 066 buf.append(last); 067 return buf.toString(); 068 } 069}; 070 071 072// End StringList.java