StringifiedListpublic 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.
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 void | append(java.lang.String item)
mItems.add( item );
| public boolean | exists(java.lang.String name)
return( mItems.contains( name ) );
| public java.util.Iterator | iterator()
return( mItems.iterator() );
| public void | prepend(java.lang.String item)
mItems.add( 0, item );
| public void | remove(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.String | toString()
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 ) );
|
|