FileDocCategorySizeDatePackage
StringifiedList.javaAPI DocGlassfish v2 API4448Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

StringifiedList

public class StringifiedList extends Object
Maintain a list of Strings, ensuring that a String constructor may be used to repopulate the list and that toString() generates a String appropriate for such use. NOTE: this should be improved so that items may contain the delimiter

Fields Summary
final List
mItems
final char
mDelim
public static final char
DEFAULT_DELIM
Constructors Summary
public StringifiedList(String listString)
Create a new list with the delimiter DEFAULT_DELIM

	
			       	 
		
	    
	
		this( listString, DEFAULT_DELIM );
	
public StringifiedList(String[] items, char delim)
Create a new list with the specified delimiter

		mDelim	= delim;
		mItems	= new ArrayList<String>();
		
		for( int i = 0; i < items.length; ++i )
		{
			append( items[ i ] );
		}
	
public StringifiedList(String listString, char delim)
Create a new list with the specified delimiter, with contents taken from the supplied String.

param
listString the string containing 0 or more items for the list
param
delim the delimiter between items

		mDelim	= delim;
		
		mItems	= new ArrayList<String>();
		
		if ( listString != null )
		{
			final StringEscaper	escaper	= new StringEscaper( "" + mDelim );
		
			final String []	list	= listString.trim().split( "" + delim );
			
			// first listed should be first in priority, so add to end
			for ( int i = 0; i < list.length; ++i )
			{
				mItems.add( escaper.unescape( list[ i ] ) );
			}
		}
	
Methods Summary
public voidappend(java.lang.String item)

		mItems.add( item );
	
public booleanexists(java.lang.String name)

		return( mItems.contains( name ) );
	
public java.util.Iteratoriterator()

		return( mItems.iterator() );
	
public voidprepend(java.lang.String item)

		mItems.add( 0, item );
	
public voidremove(java.lang.String item)

		if ( exists( item ) )
		{
			mItems.remove( item );
		}
	
public java.lang.String[]toArray()

		return( (String [])mItems.toArray( new String[ mItems.size() ] ) );
	
public java.lang.StringtoString()

		final StringEscaper	escaper	= new StringEscaper( "" + mDelim );
		final String[]		items	= toArray();
		
		for( int i = 0; i < items.length; ++i )
		{
			items[ i ]	= escaper.escape( items[ i ] );
		}

		return( ArrayStringifier.stringify( items, "" + mDelim ) );