1 23 24 29 30 package com.sun.appserv.management.util.stringifier; 31 32 import java.util.Iterator ; 33 34 35 40 41 public abstract class IteratorStringifierBase implements Stringifier 42 { 43 public final String mDelim; 44 public final Stringifier mElementStringifier; 45 46 public 47 IteratorStringifierBase() 48 { 49 this( ObjectStringifier.DEFAULT ); 50 } 51 52 public 53 IteratorStringifierBase( String delim ) 54 { 55 this( delim, new SmartStringifier( delim ) ); 56 } 57 58 public 59 IteratorStringifierBase( Stringifier elementStringifier ) 60 { 61 this( ",", elementStringifier ); 62 } 63 64 public 65 IteratorStringifierBase( String delim, Stringifier elementStringifier ) 66 { 67 mDelim = delim; 68 mElementStringifier = elementStringifier; 69 } 70 71 public String 72 stringify( Object o ) 73 { 74 assert( o != null ); 75 Iterator iter = (Iterator )o; 76 77 return( this.stringify( iter, mDelim, mElementStringifier ) ); 78 } 79 80 81 84 protected abstract void 85 stringifyElement( 86 Object elem, 87 String delim, 88 StringBuffer buf); 89 90 91 92 public String 93 stringify( Iterator iter, String delim, Stringifier stringifier ) 94 { 95 assert( iter != null ); 96 97 StringBuffer buf = new StringBuffer (); 98 99 while ( iter.hasNext() ) 100 { 101 final Object elem = iter.next(); 102 103 stringifyElement( elem, delim, buf ); 104 buf.append( delim ); 105 } 106 107 final int length = buf.length(); 109 if ( length != 0 ) 110 { 111 buf.setLength( length - delim.length() ); 112 } 113 114 return( buf.toString() ); 115 } 116 117 public final static IteratorStringifier DEFAULT = new IteratorStringifier( "," ); 118 } 119 120 | Popular Tags |