|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.cilib.util.selection.Selection<E>
E
- The comparable type.public final class Selection<E>
A Selection
is an abstraction that allows operations to be applied to
a collection instace that result in a selection of list elements, based on a varied of
potential combination of operators.
The Selection
is implemented to be a fluent interface that is easily
understandable and for which the intent of the selection is clear.
As an example, applying tournament selection on a list of Entity
instances
would be done as follows:
Listselection = Selection.from(population).orderBy(new RandomOrdering ()).first(tournamentSize) .orderBy(new SortedOrdering ()).last().select(); return selection.get(0);
where T
is a Comparable
type. The above performs the following steps:
tournamentSize
entities.
Nested Class Summary | |
---|---|
static class |
Selection.Entry<E>
This class provides the notion of an entry within a list for the selection process. |
Method Summary | ||
---|---|---|
List<Selection.Entry<E>> |
entries()
Obtain the list of internal Entry instances. |
|
SelectionSyntax<E> |
first()
Obtain the first result from the current selection. |
|
SelectionSyntax<E> |
first(int number)
Obtain the frist number of elements from the current selection. |
|
static
|
from(List<? extends T> elements)
Create a selection that will operate on the provided collection. |
|
SelectionSyntax<E> |
last()
Obtain the last element contained within the current selection. |
|
SelectionSyntax<E> |
last(int number)
Obtain the last number of elements from the current selection. |
|
SelectionSyntax<E> |
orderBy(Ordering<E> ordering)
Apply the provided ordering on the current selection. |
|
static
|
randomFrom(List<? extends T> elements,
Random random)
Obtain a random element from the provided list. |
|
static
|
randomFrom(List<? extends T> elements,
Random random,
int number)
Obtain a random element sublist from the provided list. |
|
List<E> |
select()
Obtain the result of the selection. |
|
E |
singleSelect()
Obtain the first result of the selection. |
|
SelectionSyntax<E> |
weigh(Weighing<E> weighing)
Apply the provided weighing on the current selection. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> Selection<T> from(List<? extends T> elements)
T
- The comparable type.elements
- The collection of elements to operate on.
public static <T> T randomFrom(List<? extends T> elements, Random random)
Random
.
This method terminates the selection.
T
- The type of the selection.elements
- The element from which the selection is to be performed.random
- The random number to be used in the selection.
elements
.public static <T> List<T> randomFrom(List<? extends T> elements, Random random, int number)
Random
.
This method terminates the selection.
T
- The selection type.elements
- The elements from which the selection is to be performed.random
- The random number to be used in the selection.number
- The number of elements to select.
elements
.public SelectionSyntax<E> orderBy(Ordering<E> ordering)
orderBy
in interface SelectionSyntax<E>
ordering
- The ordering to orderBy.
UnsupportedOperationException
- if the ordering cannot be applied.public SelectionSyntax<E> weigh(Weighing<E> weighing)
weigh
in interface SelectionSyntax<E>
weighing
- The weighing to weighWith.
public SelectionSyntax<E> first()
first
in interface SelectionSyntax<E>
public SelectionSyntax<E> first(int number)
number
of elements from the current selection. These
elements are returned from the front of the current selection.
first
in interface SelectionSyntax<E>
number
- The number of elements to return.
number
elements.public SelectionSyntax<E> last()
last
in interface SelectionSyntax<E>
public SelectionSyntax<E> last(int number)
number
of elements from the current selection.
last
in interface SelectionSyntax<E>
number
- The number of elements to select.
number
of elements.public List<E> select()
select
in interface SelectionSyntax<E>
public E singleSelect()
singleSelect
in interface SelectionSyntax<E>
public List<Selection.Entry<E>> entries()
Entry
instances.
entries
in interface SelectionSyntax<E>
Entry
instances.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |