Package io.vertigo.core.lang
Class ListBuilder<X>
java.lang.Object
io.vertigo.core.lang.ListBuilder<X>
- Type Parameters:
X- Element type in the list
Fluent builder for List construction.
Features:
- Type-safe list creation
- Required value validation
- Collection bulk insertion
- Optional sorting
- Immutability support
- Author:
- pchretien
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a required element to the list.addAll(Collection<? extends X> values) Adds all elements from a collection.build()Creates the final list.sort(Comparator<? super X> comparator) Sets list sorting comparator.Makes the resulting list unmodifiable.
-
Constructor Details
-
ListBuilder
public ListBuilder()
-
-
Method Details
-
add
Adds a required element to the list. Element must be non-null.- Parameters:
value- Element to add- Returns:
- Current builder for chaining
- Throws:
NullPointerException- if value is null
-
addAll
Adds all elements from a collection. All elements must be non-null.- Parameters:
values- Collection to add from- Returns:
- Current builder for chaining
- Throws:
NullPointerException- if collection or any element is null
-
unmodifiable
Makes the resulting list unmodifiable. Creates defensive copy on build.- Returns:
- Current builder for chaining
-
sort
Sets list sorting comparator. Applied during build.- Parameters:
comparator- Comparator to sort elements- Returns:
- Current builder for chaining
- Throws:
IllegalStateException- if comparator already set
-
build
Creates the final list. Applies sorting if configured and returns unmodifiable copy if requested.
-