1 23 package com.sun.appserv.management.util.misc; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 28 import com.sun.appserv.management.util.stringifier.ArrayStringifier; 29 30 31 38 public class StringifiedList 39 { 40 final List <String > mItems; 41 final char mDelim; 42 43 public final static char DEFAULT_DELIM = ','; 44 45 48 public 49 StringifiedList( final String listString ) 50 { 51 this( listString, DEFAULT_DELIM ); 52 } 53 54 57 public 58 StringifiedList( final String [] items, final char delim ) 59 { 60 mDelim = delim; 61 mItems = new ArrayList <String >(); 62 63 for( int i = 0; i < items.length; ++i ) 64 { 65 append( items[ i ] ); 66 } 67 } 68 69 76 public 77 StringifiedList( final String listString, final char delim ) 78 { 79 mDelim = delim; 80 81 mItems = new ArrayList <String >(); 82 83 if ( listString != null ) 84 { 85 final StringEscaper escaper = new StringEscaper( "" + mDelim ); 86 87 final String [] list = listString.trim().split( "" + delim ); 88 89 for ( int i = 0; i < list.length; ++i ) 91 { 92 mItems.add( escaper.unescape( list[ i ] ) ); 93 } 94 } 95 } 96 97 public String 98 toString() 99 { 100 final StringEscaper escaper = new StringEscaper( "" + mDelim ); 101 final String [] items = toArray(); 102 103 for( int i = 0; i < items.length; ++i ) 104 { 105 items[ i ] = escaper.escape( items[ i ] ); 106 } 107 108 return( ArrayStringifier.stringify( items, "" + mDelim ) ); 109 } 110 111 public String [] 112 toArray() 113 { 114 return( (String [])mItems.toArray( new String [ mItems.size() ] ) ); 115 } 116 117 public boolean 118 exists( final String name ) 119 { 120 return( mItems.contains( name ) ); 121 } 122 123 public java.util.Iterator 124 iterator() 125 { 126 return( mItems.iterator() ); 127 } 128 129 130 public void 131 prepend( String item ) 132 { 133 mItems.add( 0, item ); 134 } 135 136 public void 137 append( String item ) 138 { 139 mItems.add( item ); 140 } 141 142 143 public void 144 remove( String item ) 145 { 146 if ( exists( item ) ) 147 { 148 mItems.remove( item ); 149 } 150 } 151 } 152 153 | Popular Tags |