Package org.apache.wicket.util.string
Class AbstractStringList
- java.lang.Object
-
- 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:
- join(String) Joins strings together using a given separator
- join() Joins Strings using comma as a separator
- join(int first, int last, String) Joins a sublist of strings using a given separator
- Author:
- Jonathan Locke
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractStringList()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract String
get(int index)
Gets a string at a given index in the sequenceabstract 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 separatorString
join(String separator)
Joins this sequence of strings using a separatorabstract 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 representationint
totalLength()
-
-
-
Constructor Detail
-
AbstractStringList
public AbstractStringList()
-
-
Method Detail
-
iterator
public abstract IStringIterator iterator()
- Specified by:
iterator
in interfaceIStringSequence
- Returns:
- String iterator
- See Also:
IStringSequence.iterator()
-
size
public abstract int size()
- Specified by:
size
in interfaceIStringSequence
- 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 interfaceIStringSequence
- 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, inclusivelast
- The last index to use, exclusiveseparator
- The separator to use- Returns:
- The joined String
-
-