1 4 5 9 10 package org.openlaszlo.utils; 11 12 import java.text.*; 13 import java.util.*; 14 15 public class ListFormat extends Format { 16 protected final String junction; 17 18 public ListFormat(String junction) { 19 this.junction = junction; 20 } 21 22 public ListFormat() { 23 this("and"); 24 } 25 26 public StringBuffer format(Object obj, StringBuffer buffer, 27 FieldPosition pos) 28 { 29 List list = (List) obj; 30 int listSize = list.size(); 31 for (ListIterator iter = list.listIterator(); iter.hasNext(); ) { 32 if (iter.hasPrevious()) { 33 if (listSize > 2) 34 buffer.append(','); 35 buffer.append(' '); 36 if (iter.nextIndex() == listSize-1) { 37 buffer.append(junction); 38 buffer.append(' '); 39 } 40 } 41 buffer.append(iter.next()); 42 } 43 return buffer; 44 } 45 46 public Object parseObject(String source, ParsePosition parsePosition) { 47 throw new RuntimeException ("unimplemented functionality"); 48 } 49 } 50 | Popular Tags |