1 23 24 29 30 package com.sun.appserv.management.util.stringifier; 31 32 import java.util.Collection ; 33 import java.util.Iterator ; 34 35 public class CollectionStringifier implements Stringifier 36 { 37 public final static CollectionStringifier DEFAULT = new CollectionStringifier( "," ); 38 39 public final String mDelim; 40 public final Stringifier mElementStringifier; 41 42 public 43 CollectionStringifier( String delim ) 44 { 45 this( delim, SmartStringifier.DEFAULT ); 46 } 47 48 public 49 CollectionStringifier( Stringifier elementStringifier ) 50 { 51 this( ",", elementStringifier ); 52 } 53 54 public 55 CollectionStringifier( String delim, Stringifier elementStringifier ) 56 { 57 mDelim = delim; 58 mElementStringifier = elementStringifier; 59 } 60 61 public String 62 stringify( Object o ) 63 { 64 final Collection c = (Collection )o; 65 final Iterator iter = c.iterator(); 66 67 String result = IteratorStringifier.DEFAULT.stringify( iter, mDelim, mElementStringifier); 68 69 return( result ); 70 } 71 72 73 public static String 74 toString( final Object o, final String delim ) 75 { 76 final Collection c = (Collection )o; 77 final Iterator iter = c.iterator(); 78 79 String result = IteratorStringifier.DEFAULT.stringify( iter, delim ); 80 81 return( result ); 82 } 83 } 84 | Popular Tags |