public class StringList extends ListBase implements java.lang.Iterable<java.lang.String>
A list of item type string
.
Uses the property and function naming conventions of the JavaScript Array object.
Modifier and Type | Field and Description |
---|---|
static StringList |
empty |
Constructor and Description |
---|
StringList()
See StringList(int).
|
StringList(int capacity)
Construct a new list with
StringList.length of zero and optional initial capacity . |
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String item)
Add
item to the end of this list. |
void |
addAll(StringList list)
Add all the items of
list to the end of this list. |
StringList |
addThis(java.lang.String item)
Add
item to the end of this list. |
java.lang.String |
concat()
Return a concatenation of all the string items in this list into a single string value.
|
StringList |
copy()
Return a shallow copy of this list.
|
StringList |
dropEmpty()
Return a new list with the items of this list, excluding empty items.
|
java.lang.String |
first()
Return the first item in this list.
|
static StringList |
from(java.util.List<java.lang.String> list) |
java.lang.String |
get(int index)
Return the item in this list at the specified
index . |
boolean |
includes(java.lang.String item)
Return
true if this list contains item . |
int |
indexOf(java.lang.String item)
See indexOf(String, int).
|
int |
indexOf(java.lang.String item,
int start)
Return first index in this list of
item , or -1 if not found. |
void |
insertAll(int index,
StringList list)
Insert all items of
list into this list, before the item (if any) at index . |
void |
insertAt(int index,
java.lang.String item)
Insert
item into this list, before the item (if any) at index . |
java.util.Iterator<java.lang.String> |
iterator() |
java.lang.String |
join(java.lang.String separator)
Return a concatenation of all the string items in this list into a single string value, with the specified
separator between items. |
java.lang.String |
joinLines()
Return
this.join("\n") plus a final newline (if list is non-empty). |
java.lang.String |
last()
Return the last item in this list.
|
int |
lastIndexOf(java.lang.String item)
|
int |
lastIndexOf(java.lang.String item,
int start)
Return last index in this list of
item , or -1 if not found. |
static StringList |
lines(java.lang.String value)
Return a list of the lines in this string.
|
void |
set(int index,
java.lang.String item)
Set the item in this list at the specified
index . |
static StringList |
share(ListBase list)
|
java.lang.String |
single()
Return a single item from this list.
|
StringList |
slice(int start)
See slice(int, int).
|
StringList |
slice(int start,
int end)
Return a slice of this list from index
start (inclusive) to index end (exclusive). |
StringList |
sortIgnoreCase()
Sort this list (in place) with a case-insensitive ordering.
|
static StringList |
split(java.lang.String value,
java.lang.String separator)
|
static StringList |
split(java.lang.String value,
java.lang.String separator,
int limit)
Split a string value into a list of string values, divided by the specified separator.
|
ListBase |
toDynamic()
Return (nullable) a dynamic representation of this list (
DataValueList , ComplexValueList , or EntityValueList ), or null if there is no dynamic representation available. |
java.util.List<java.lang.String> |
toGeneric() |
StringList |
trimAll()
Return a new list where each item is the corresponding trimmed item from this list.
|
clear, getComparer, getDataType, getEquality, getUntypedList, isEmpty, length, removeAt, removeFirst, removeLast, removeRange, reverse, shareWith, sort, sortWith, toString, validate
cloneMutable, equals, getTypeCode, hashCode
public static final StringList empty
public StringList()
public StringList(int capacity)
Construct a new list with StringList.length
of zero and optional initial capacity
.
A list can expand in length beyond its initial capacity, but best performance
will be obtained if the initial capacity is close to the list's maximum length.
capacity
- Optional initial capacity.public void add(java.lang.String item)
Add item
to the end of this list.
item
- Item to be added.public void addAll(StringList list)
Add all the items of list
to the end of this list.
list
- Items to be added.public StringList addThis(java.lang.String item)
Add item
to the end of this list.
item
- Item to be added.public java.lang.String concat()
Return a concatenation of all the string items in this list into a single string value.
public StringList copy()
Return a shallow copy of this list.
public StringList dropEmpty()
Return a new list with the items of this list, excluding empty items.
public java.lang.String first()
Return the first item in this list.
EmptyListException
if the list is empty.
public static StringList from(java.util.List<java.lang.String> list)
public java.lang.String get(int index)
Return the item in this list at the specified index
.
ListIndexException
if index
is out of range (0 to StringList.length
- 1).
index
- Zero-based index.public boolean includes(java.lang.String item)
Return true
if this list contains item
.
item
- Item for comparison. Comparison uses the StringList.equality
property, which would usually be expected to match the ==
operator for item type string
.true
if this list contains item
.public int indexOf(java.lang.String item)
item
- Item parameter.public int indexOf(java.lang.String item, int start)
Return first index in this list of item
, or -1
if not found.
item
- Item for comparison. Comparison uses the StringList.equality
property, which would usually be expected to match the ==
operator for item type string
.start
- Zero-based starting index (search moves forwards from this index).item
, or -1
if not found.public void insertAll(int index, StringList list)
Insert all items of list
into this list, before the item (if any) at index
.
ListIndexException
if index
is out of range (0 to StringList.length
).
index
- Zero-based index.list
- List of items to be inserted.public void insertAt(int index, java.lang.String item)
Insert item
into this list, before the item (if any) at index
.
ListIndexException
if index
is out of range (0 to StringList.length
).
index
- Zero-based index.item
- Item to be added.public java.util.Iterator<java.lang.String> iterator()
iterator
in interface java.lang.Iterable<java.lang.String>
public java.lang.String join(java.lang.String separator)
Return a concatenation of all the string items in this list into a single string value, with the specified separator
between items.
separator
- The separator string value.separator
between items.public java.lang.String joinLines()
Return this.join("\n")
plus a final newline (if list is non-empty).
this.join("\n")
plus a final newline (if list is non-empty).public java.lang.String last()
Return the last item in this list.
EmptyListException
if the list is empty.
public int lastIndexOf(java.lang.String item)
item
- Item parameter.public int lastIndexOf(java.lang.String item, int start)
Return last index in this list of item
, or -1
if not found.
item
- Item for comparison. Comparison uses the StringList.equality
property, which would usually be expected to match the ==
operator for item type string
.start
- Zero-based starting index (search moves backwards from this index).item
, or -1
if not found.public static StringList lines(java.lang.String value)
Return a list of the lines in this string.
value
- Text where each line is terminated by the newline character (optionally preceeded by carriage return). The final newline character can be omitted.public void set(int index, java.lang.String item)
Set the item in this list at the specified index
.
index
- Zero-based index.item
- Item value.public static StringList share(ListBase list)
Return a new StringList
that shares the ListBase.untypedList
as the list
parameter.
To ensure type safety, items in list
that do not have the item type string
will be removed.
list
- List whose items will be shared by the resulting list.string
, sharing the same items as list
.public java.lang.String single()
Return a single item from this list.
EmptyListException
if the list has no items, NotUniqueException
if the list has multiple items.
public StringList slice(int start)
start
- Start parameter.public StringList slice(int start, int end)
Return a slice of this list from index start
(inclusive) to index end
(exclusive).
start
- Zero-based starting index (inclusive), or negative for starting index relative to the end of this list.end
- Zero-based ending index (exclusive), or negative for ending index relative to the end of this list.start
(inclusive) to index end
(exclusive).public StringList sortIgnoreCase()
Sort this list (in place) with a case-insensitive ordering.
public static StringList split(java.lang.String value, java.lang.String separator)
value
- Value parameter.separator
- Separator parameter.public static StringList split(java.lang.String value, java.lang.String separator, int limit)
Split a string value into a list of string values, divided by the specified separator.
value
- The string value to be split.separator
- The separator value.limit
- separator Maximum number of string values to return. The separator can appear (possibly multiple times) in the final string value.public ListBase toDynamic()
Return (nullable) a dynamic representation of this list (DataValueList
, ComplexValueList
, or EntityValueList
), or null
if there is no dynamic representation available.
toDynamic
in class ListBase
DataValueList
, ComplexValueList
, or EntityValueList
), or null
if there is no dynamic representation available.public java.util.List<java.lang.String> toGeneric()
public StringList trimAll()
Return a new list where each item is the corresponding trimmed item from this list.