java.lang.Object
org.apache.wicket.util.string.AbstractStringList
org.apache.wicket.util.string.StringList
- All Implemented Interfaces:
Serializable,IStringSequence
A typesafe, mutable list of strings supporting a variety of convenient operations as well as
expected operations from List such as add(), size(), remove(), iterator(), get(int index) and
toArray(). Instances of the class are not threadsafe.
StringList objects can be constructed empty or they can be created using any of several static factory methods:
- valueOf(String[])
- valueOf(String)
- valueOf(Collection)
- valueOf(Object[])
The tokenize() factory methods allow easy creation of StringLists via StringTokenizer. The repeat() static factory method creates a StringList that repeats a given String a given number of times.
The prepend() method adds a String to the beginning of the StringList. The removeLast() method pops a String off the end of the list. The sort() method sorts strings in the List using Collections.sort(). The class also inherits useful methods from AbstractStringList that include join() methods ala Perl and a toString() method which joins the list of strings with comma separators for easy viewing.
- Author:
- Jonathan Locke
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the string to the stringlist at position pos.voidAdds a string to the back of this list.voidadd(StringValue value) Adds a string value to this list as a string.booleanget(int index) Gets the string at the given index.getList()iterator()Returns a typesafe iterator over this collection of strings.voidAdds the given string to the front of the list.voidremove(int index) Removes the string at the given index.voidRemoves the last string in this list.static StringListReturns a list of a string repeated a given number of times.intsize()voidsort()Sorts this string list alphabetically.String[]toArray()Converts this string list to a string array.static StringListExtracts tokens from a comma and space delimited string.static StringListExtracts tokens from a delimited string.intstatic StringListConverts an array of objects into a list of strings by using the object to string conversion method of the StringValue class.static StringListReturns a string list with just one string in it.static StringListConverts a string array to a string list.static StringListvalueOf(Collection<?> collection) Converts a collection of objects into a list of string values by using the conversion methods of the StringValue class.
-
Constructor Details
-
StringList
public StringList()Constructor. -
StringList
Constructor.- Parameters:
size- Number of elements to preallocate
-
-
Method Details
-
repeat
Returns a list of a string repeated a given number of times.- Parameters:
count- The number of times to repeat the stringstring- The string to repeat- Returns:
- The list of strings
-
tokenize
Extracts tokens from a comma and space delimited string.- Parameters:
string- The string- Returns:
- The string tokens as a list
-
tokenize
Extracts tokens from a delimited string.- Parameters:
string- The stringdelimiters- The delimiters- Returns:
- The string tokens as a list
-
valueOf
Converts a collection of objects into a list of string values by using the conversion methods of the StringValue class.- Parameters:
collection- The collection to add as strings- Returns:
- The list
-
valueOf
Converts an array of objects into a list of strings by using the object to string conversion method of the StringValue class.- Parameters:
objects- The objects to convert- Returns:
- The list of strings
-
valueOf
Returns a string list with just one string in it.- Parameters:
string- The string- Returns:
- The list of one string
-
valueOf
Converts a string array to a string list.- Parameters:
array- The array- Returns:
- The list
-
add
Adds a string to the back of this list.- Parameters:
string- String to add
-
add
Adds the string to the stringlist at position pos.- Parameters:
pos- the position to add the string atstring- the string to add.
-
add
Adds a string value to this list as a string.- Parameters:
value- The value to add
-
contains
- Parameters:
string- The string to look for- Returns:
- True if the list contains the string
-
get
Gets the string at the given index.- Specified by:
getin interfaceIStringSequence- Specified by:
getin classAbstractStringList- Parameters:
index- The index- Returns:
- The string at the index
- Throws:
IndexOutOfBoundsException- See Also:
-
getList
- Returns:
- List value (not a copy of this list)
-
iterator
Returns a typesafe iterator over this collection of strings.- Specified by:
iteratorin interfaceIStringSequence- Specified by:
iteratorin classAbstractStringList- Returns:
- Typesafe string iterator
- See Also:
-
prepend
Adds the given string to the front of the list.- Parameters:
string- The string to add
-
remove
Removes the string at the given index.- Parameters:
index- The index
-
removeLast
Removes the last string in this list. -
size
- Specified by:
sizein interfaceIStringSequence- Specified by:
sizein classAbstractStringList- Returns:
- The number of strings in this list.
- See Also:
-
sort
Sorts this string list alphabetically. -
toArray
Converts this string list to a string array.- Overrides:
toArrayin classAbstractStringList- Returns:
- The string array
-
totalLength
- Overrides:
totalLengthin classAbstractStringList- Returns:
- The total length of all strings in this list.
-