Maven module :un.api : api-common :
Class : un.api.collection.Collections
Extends/Implements : -
Subclasses : -

A collections utility class.
author  Johann Sorel
author  Yann D'Isanto


Variables : EMPTY_SEQUENCE
Functions : constraint, flatten, bind, exists, filter, find, fold, forAll, forEach, forEach, headOption, map, partition, reduce, reduceOption, foldLeft, foldRight, getOption, lastOption, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, reverse, slice, tail, fold, reduce, reduceOption, sort, sort, quickSort, sort, quickSort, sort, copy, emptyIterator, serie, view, view, singleton, singletonSequence


public Sequence EMPTY_SEQUENCE



Attach a listener to the given collection and check all added values
pass the given predicate.
param  col
param  predicate
public void constraint (Collection col, Predicate predicate)


Flatten the specified collection of collections.
param  collections the collections to flatten.
return  a list with all flattened items.
public Sequence flatten (Collection collections)


Binds all items with the specified mapping.
param  source collection of objects to bind
param  mapping the mapping to apply when binding.
return  a new list resulting from the binding.
public Sequence bind (Collection source, Mapping mapping)


param  source collection
param  predicate the predicate.
return  true if an item matches the specified predicate, false otherwise.
public boolean exists (Collection source, Predicate predicate)


Filters this collection according to the specified predicate.
param  source collection
param  predicate the predicate.
return  a list which contains the item matching the predicate.
public Sequence filter (Collection source, Predicate predicate)


Finds the first item of the collection matching the specified predicate.
param  source collection
param  predicate the predicate.
return  an optional item.
public Option find (Collection source, Predicate predicate)


Folds the items of this collection using the specified associative binary
operator. The order in which operations are performed on items is
unspecified and may be nondeterministic.
param  source collection
param  op an associative binary operator.
param  startValue the start value for the fold operation.
return  the result of applying the specified fold operator between all
the items of this collection and the specified startValue.
public Object fold (Collection source, BinaryOperator op, Object startValue)


Evaluates the specified predicate for all items.
param  source collection
param  predicate the predicate.
return  true if this entire collection (all items) matches the specified
predicate.
public boolean forAll (Collection source, Predicate predicate)


Applies the specified Batch for each item of this collection.
param  source collection
param  batch the batch to perform on each item.
public void forEach (Collection source, Batch batch)


Calls the specified callback for each item of this collection. The for
each loop stop iterating as soon as a callback return a defined value.
param  source collection
param  callback the callback to call on each item.
return  an optional value.
public Option forEach (Collection source, Callback callback)


param  source collection
return  the first element of this collection as an optional value.
public Option headOption (Collection source)


Maps this collection's items according to the specified mapping.
param  source collection
param  mapping the mapping to apply.
return  a list which contains the mapping result items.
public Sequence map (Collection source, Mapping mapping)


Partitions this list according to the specified predicate.
param  source collection
param  predicate the predicate.
return  a pair of list. The first contains the items matching the
predicate and the second contains the items not matching the predicate.
public Pair partition (Collection source, Predicate predicate)


Reduces the items of this collection using the specified associative
binary operator. The order in which operations are performed on items is
unspecified and may be nondeterministic.
param  source collection
param  op an associative binary operator.
return  the result of applying the specified reduce operator between all
the items of this collection.
throws  UnsupportedOperationException if this collection is empty.
public Object reduce (Collection source, BinaryOperator op)


Reduces the items of this collection using the specified associative
binary operator. The order in which operations are performed on items is
unspecified and may be nondeterministic.
param  source collection
param  op an associative binary operator.
return  the optional result of applying the specified reduce operator
between all the items of this collection.
public Option reduceOption (Collection source, BinaryOperator op)


Folds the items of this collection using the specified binary operator
going left to right.
param  source collection
param  op a binary operator.
param  startValue the start value for the fold operation.
return  the result of applying the specified fold operator between all
the items of this list and the specified startValue.
public Object foldLeft (Sequence source, ExtBinaryOperator op, Object startValue)


Folds the items of this collection using the specified binary operator
going right to left.
param  source collection
param  op a binary operator.
param  startValue the start value for the fold operation.
return  the result of applying the specified fold operator between all
the items of this list and the specified startValue.
public Object foldRight (Sequence source, ExtBinaryOperator op, Object startValue)


Returns the optional item at the specified index.
param  source collection
param  index the index.
return  the optional item corresponding to the specified index.
public Option getOption (Sequence source, int index)


param  source collection
return  the optional last item of this list.
public Option lastOption (Sequence source)


Reduces the items of this collection using the specified binary operator
going left to right. WARNING: be sure that B type is a super type
of this collection items type or an exception will be thrown.
param  source collection
param  op a binary operator.
return  the result of applying the specified reduce operator between all
the items of this list.
throws  ClassCastException if A doesn't extends B.
throws  UnsupportedOperationException if this collection is empty.
public Object reduceLeft (Sequence source, ExtBinaryOperator op)


Reduces the items of this collection using the specified binary operator
going left to right. WARNING: be sure that B type is a super type
of this collection items type or an exception will be thrown.
param  source collection
param  op a binary operator.
return  the optional result of applying the specified reduce operator
between all the items of this list.
throws  ClassCastException if A doesn't extends B.
public Option reduceLeftOption (Sequence source, ExtBinaryOperator op)


Reduces the items of this collection using the specified binary operator
going right to left. WARNING: be sure that B type is a super type
of this collection items type or an exception will be thrown.
param  source collection
param  op a binary operator.
return  the result of applying the specified reduce operator between all
the items of this list.
throws  ClassCastException if A doesn't extends B.
throws  UnsupportedOperationException if this collection is empty.
public Object reduceRight (Sequence source, ExtBinaryOperator op)


Reduces the items of this collection using the specified binary operator
going right to left. WARNING: be sure that B type is a super type
of this collection items type or an exception will be thrown.
param  source collection
param  op a binary operator.
return  the optional result of applying the specified reduce operator
between all the items of this list.
throws  ClassCastException if A doesn't extends B.
public Option reduceRightOption (Sequence source, ExtBinaryOperator op)


param  source collection
return  a list which items are this list items in reverse order.
public Sequence reverse (Sequence source)


Slices this list according to the specified from and until indexes.
param  source collection
param  from the index to slice from (inclusive).
param  until the index to slice until (exclusive).
return  a sublist from this list according to the specified from and
until indexes.
public Sequence slice (Sequence source, int from, int until)


param  source collection
return  a list containing all items from this list but the first one.
public Sequence tail (Sequence source)

public Object fold (Iterator ite, ExtBinaryOperator op, Object startValue)

public Object reduce (Iterator ite, ExtBinaryOperator op)

public Option reduceOption (Iterator ite, ExtBinaryOperator op)


Sort given sequence on given range.
Object in sequence are expected to by instances of Orderable.
param  seq not null
param  startIndex inclusive
param  endIndex exclusive
public void sort (Sequence seq, int startIndex, int endIndex)


Sort given array on given range.
param  seq not null
param  startIndex inclusive
param  endIndex exclusive
param  sorter Sorter to use
public void sort (Sequence seq, int startIndex, int endIndex, Sorter sorter)


Sort given array using QuickSort in-place algorithm.
Average case performance: O(n log n)
Worst case performance: O(n^2)
https://en.wikipedia.org/wiki/Quicksort
param  array the array to be sorted.
param  leftIndex the beginning index array (inclusive)
param  rightIndex the ending index array (inclusive)
public void quickSort (Sequence array, int leftIndex, int rightIndex)


Sort given array (QuickSort algorithm).
param  array the array to be sorted.
public void sort (Sequence array)


Sort given array using QuickSort in-place algorithm using Sorter.
Average case performance: O(n log n)
Worst case performance: O(n^2)
https://en.wikipedia.org/wiki/Quicksort
param  array the array to be sorted.
param  leftIndex the beginning index array (inclusive)
param  rightIndex the ending index array (inclusive)
param  sorter the Sorter
public void quickSort (Sequence array, int leftIndex, int rightIndex, Sorter sorter)


Sort given array using Sorter (QuickSort algorithm).
param  array the array to be sorted.
param  sorter the Sorter
public void sort (Sequence array, Sorter sorter)


Copy content of given collection in given array, starting at given position.
param  collection collection to copy from
param  array Array where to insert elements
param  offset index where to start inserting elements
public void copy (Collection collection, Object[] array, int offset)

public Iterator emptyIterator ()

public Iterator serie (Iterator[] iterators)

public Collection view (Collection collection, Predicate predicate)

public Iterator view (Iterator collection, Predicate predicate)

public Iterator singleton (Object obj)

public Sequence singletonSequence (Object obj)