Package org.apache.juneau.internal
Class ListBuilder<E>
java.lang.Object
org.apache.juneau.internal.ListBuilder<E>
- Type Parameters:
E- Element type.
Builder for lists.
See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionListBuilder(Class<E> elementType, Type... elementTypeArgs) Constructor.ListBuilder(List<E> addTo) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdds a single value to this list.Adds multiple values to this list.addAll(Collection<E> value) Appends the contents of the specified collection into this list.Adds arbitrary values to this list.Appends a value to this list of the flag is true.Adds entries to this list via JSON array strings.build()Builds the list.copy()Forces the existing list to be copied instead of appended to.static <E> ListBuilder<E>Static creator.sorted()Sorts the contents of the list.sorted(Comparator<E> comparator) Sorts the contents of the list using the specified comparator.sparse()When specified, thebuild()method will returnnull if the list is empty.When specified,build()will return an unmodifiable list.
-
Constructor Details
-
ListBuilder
Constructor.- Parameters:
elementType- The element type.elementTypeArgs- The element type generic arguments if there are any.
-
ListBuilder
Constructor.- Parameters:
addTo- The list to add to.
-
-
Method Details
-
create
Static creator.- Type Parameters:
E- The element type.- Parameters:
elementType- The element type.elementTypeArgs- Optional element type arguments.- Returns:
- A new builder.
-
build
Builds the list.- Returns:
- A list conforming to the settings on this builder.
-
sparse
When specified, thebuild()method will returnnull if the list is empty.Otherwise
build()will never returnnull .- Returns:
- This object.
-
unmodifiable
When specified,build()will return an unmodifiable list.- Returns:
- This object.
-
copy
Forces the existing list to be copied instead of appended to.- Returns:
- This object.
-
sorted
Sorts the contents of the list.- Returns:
- This object.
-
sorted
Sorts the contents of the list using the specified comparator.- Parameters:
comparator- The comparator to use for sorting.- Returns:
- This object.
-
addAll
Appends the contents of the specified collection into this list.This is a no-op if the value is
null .- Parameters:
value- The collection to add to this list.- Returns:
- This object.
-
add
Adds a single value to this list.- Parameters:
value- The value to add to this list.- Returns:
- This object.
-
add
Adds multiple values to this list.- Parameters:
values- The values to add to this list.- Returns:
- This object.
-
addJson
Adds entries to this list via JSON array strings.- Parameters:
values- The JSON array strings to parse and add to this list.- Returns:
- This object.
-
addAny
Adds arbitrary values to this list.Objects can be any of the following:
- The same type or convertible to the element type of this list.
- Collections or arrays of anything on this list.
- JSON array strings parsed and convertible to the element type of this list.
- Parameters:
values- The values to add.- Returns:
- This object.
-
addIf
Appends a value to this list of the flag is true.- Parameters:
flag- The flag.value- The value.- Returns:
- This object.
-