T - The type of the elements to storepublic class Container<T> extends Object implements Iterable<T>
this).| Constructor and Description |
|---|
Container()
Creates an empty container.
|
Container(Collection<? extends T> elements)
Creates a new container from the given collection.
|
Container(Iterable<? extends T> elements)
Creates a new container from the given iterable.
|
Container(Iterator<? extends T> elementIterator)
Creates a new container from the given iterator.
|
Container(T element)
Creates a container that stores the given element.
|
Container(T[] elements)
Creates a new container and stores the given elements.
|
| Modifier and Type | Method and Description |
|---|---|
Container<T> |
add(int index,
T element)
Creates and returns a new container that contains the elements of this
container with the given element inserted at the given index.
|
Container<T> |
add(T element)
Creates and returns a new container that contains all elements of this
container and the given element, which is appended at the end.
|
List<T> |
asList()
Returns the elements of this contains as a
List. |
boolean |
contains(T element)
Returns whether the given element is stored in this container.
|
Container<T> |
crop(int index)
Returns a container that contains only the element at the given index.
|
Container<T> |
crop(int start,
int end)
Returns a container that contains a part of this container, starting at
the index
start (inclusive) and ending at the index end
(exclusive). |
Container<T> |
filter(Filter<T> filter)
Filters the elements of this container through the given filter.
|
T |
get()
Returns the first element of this container, or
null if this
container is empty. |
T |
get(T defaultValue)
Returns the first element of this container, or the default value if this
container is empty.
|
int |
indexOf(T element)
Returns the index of the given element in this container.
|
boolean |
isEmpty()
Returns whether this container is empty.
|
Iterator<T> |
iterator() |
Container<T> |
last()
Returns a container that only contains the last element of this
container.
|
<O> Container<O> |
map(Map<T,O> map)
Maps all elements in this container using the given map and returns a
container containing the mapped elements.
|
<O> Container<O> |
map(Mapper<T,O> mapper)
Maps all elements in this container using the given mapper and returns a
container containing the mapped elements.
|
Container<T> |
process(Processor<T> processor)
Processes all elements in this container.
|
Container<T> |
remove(int index)
Returns a container that contains the elements of this container with the
exception of the element at the given index which is removed.
|
Container<T> |
remove(T element)
Returns a container that contains the elements of this container with the
exception of the first occurence of the given element which is removed.
|
Container<T> |
reverse()
Returns a container with the elements of this container in reverse order.
|
int |
size()
Returns the number of elements stored in this container.
|
Container<T> |
sort()
Returns a container that contains all elements of this container sorted
by their natural order.
|
Container<T> |
sort(Comparator<? super T> comparator)
Returns a container that contains all elements of this container sorted
using the given comparator.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic Container()
public Container(T element)
element - The element to storepublic Container(T[] elements)
elements - The elements to storepublic Container(Collection<? extends T> elements)
Collection.iterator().elements - The collection with the elements to storepublic Container(Iterable<? extends T> elements)
Container(Iterator) constructor with an Iterator created
from Iterable.iterator().elements - The iterable containing the elements to storepublic int size()
public boolean isEmpty()
true if this container is empty, false if it
contains at least one elementpublic T get()
null if this
container is empty.null if this
container is emptypublic T get(T defaultValue)
defaultValue - The default value to return if the container is emptypublic Container<T> last()
public int indexOf(T element)
element - The element to locate in this container-1 if the given element can
not be located in this containerpublic boolean contains(T element)
element - The element to check fortrue if the given element is stored in this container,
false otherwisepublic Container<T> add(T element)
element - The element to addpublic Container<T> add(int index, T element)
index - The index at which to insert the new elementelement - The element to insertpublic Container<T> crop(int index)
index - The index of the elementpublic Container<T> crop(int start, int end)
start (inclusive) and ending at the index end
(exclusive).start - The index of the first element to returnend - The index of the first element that is not returnedpublic Container<T> remove(T element)
element - The element to removepublic Container<T> remove(int index)
index - The index of the element to removepublic Container<T> reverse()
public Container<T> sort()
Comparable interface.Arrays#sort(Object[])public Container<T> sort(Comparator<? super T> comparator)
comparator - The comparator to compare the objects (or null to use
natural ordering)Arrays#sort(Object[], Comparator)public Container<T> filter(Filter<T> filter)
filter - The filter to apply on the elementspublic <O> Container<O> map(Mapper<T,O> mapper)
O - The type of the mapped elementsmapper - The mapper to usepublic <O> Container<O> map(Map<T,O> map)
O - The type of the mapped elementsmap - The map to use to look up elementspublic Container<T> process(Processor<T> processor)
processor - The processor to apply to all elementspublic List<T> asList()
List.Copyright © 2026. All rights reserved.