org.apache.wicket.util.string
Class AbstractStringList

java.lang.Object
  extended by org.apache.wicket.util.string.AbstractStringList
All Implemented Interfaces:
Serializable, IStringSequence
Direct Known Subclasses:
StringList

public abstract class AbstractStringList
extends Object
implements IStringSequence, Serializable

An abstract base class for string list implementations. Besides having an implementation for IStringSequence (iterator(), get(int index) and size()), an AbstractStringList can be converted to a String array or a List of Strings.

The total length of all Strings in the list can be determined by calling totalLength().

Strings or a subset of Strings in the list can be formatted using three join() methods:

Author:
Jonathan Locke
See Also:
Serialized Form

Constructor Summary
AbstractStringList()
           
 
Method Summary
abstract  String get(int index)
          Gets a string at a given index in the sequence
abstract  IStringIterator iterator()
           
 String join()
          Joins this sequence of strings using a comma separator.
 String join(int first, int last, String separator)
          Joins this sequence of strings from first index to last using a separator
 String join(String separator)
          Joins this sequence of strings using a separator
abstract  int size()
           
 String[] toArray()
          Returns this String sequence as an array of Strings.
 List<String> toList()
          Returns this String sequence as an array of Strings.
 String toString()
          Converts this object to a string representation
 int totalLength()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractStringList

public AbstractStringList()
Method Detail

iterator

public abstract IStringIterator iterator()
Specified by:
iterator in interface IStringSequence
Returns:
String iterator
See Also:
IStringSequence.iterator()

size

public abstract int size()
Specified by:
size in interface IStringSequence
Returns:
Number of strings in this string list
See Also:
IStringSequence.size()

get

public abstract String get(int index)
Description copied from interface: IStringSequence
Gets a string at a given index in the sequence

Specified by:
get in interface IStringSequence
Parameters:
index - The index into this string list
Returns:
The string at the given index
See Also:
IStringSequence.get(int)

toArray

public String[] toArray()
Returns this String sequence as an array of Strings. Subclasses may provide a more efficient implementation than the one provided here.

Returns:
An array containing exactly this sequence of Strings

toList

public final List<String> toList()
Returns this String sequence as an array of Strings. Subclasses may provide a more efficient implementation than the one provided here.

Returns:
An array containing exactly this sequence of Strings

totalLength

public int totalLength()
Returns:
The total length of all Strings in this sequence.

join

public final String join()
Joins this sequence of strings using a comma separator. For example, if this sequence contains [1 2 3], the result of calling this method will be "1, 2, 3".

Returns:
The joined String

join

public final String join(String separator)
Joins this sequence of strings using a separator

Parameters:
separator - The separator to use
Returns:
The joined String

join

public final String join(int first,
                         int last,
                         String separator)
Joins this sequence of strings from first index to last using a separator

Parameters:
first - The first index to use, inclusive
last - The last index to use, exclusive
separator - The separator to use
Returns:
The joined String

toString

public String toString()
Converts this object to a string representation

Overrides:
toString in class Object
Returns:
String version of this object


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.