Class FeatureList<T extends FeatureInput>
- Type Parameters:
T
- input type of features contained in the list
public class FeatureList<T extends FeatureInput>
extends AnchorBean<FeatureList<T>>
implements Iterable<Feature<T>>
A list of features with the same input-type.
- Author:
- Owen Feehan
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates with an empty list.FeatureList
(int capacity) Creates with an empty list of particular capacity.FeatureList
(List<Feature<T>> list) Wraps an existing list.FeatureList
(Stream<Feature<T>> stream) Creates from a stream ofFeature
s.FeatureList
(Feature<T> feature) Creates with a singleFeature
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a feature to the current list.void
addAll
(FeatureList<? extends T> toAdd) Add all the features inother
to the current list.append
(Optional<FeatureList<T>> featureList) Appends the features one or more (optional) feature-lists to the existing list.asList()
Exposes the underlying list of features in this data-structure.void
clear()
Removes all of the elements from this list.Derives the names of the features.A (maybe longer) description identifying the bean and perhaps its key parameters.<S extends FeatureInput,
E extends Exception>
FeatureList<S> filterAndMap
(Predicate<Feature<T>> predicate, CheckedFunction<Feature<T>, Feature<S>, E> mappingFunction) get
(int index) Returns the element at the specified position in this list.getList()
The list of features.void
initializeRecursive
(FeatureInitialization initialization, Logger logger) Initializes all features in the list, and recursively any features they contain.boolean
isEmpty()
Returnstrue
if this list contains no elements.iterator()
<S extends FeatureInput,
E extends Exception>
FeatureList<S> map
(CheckedFunction<Feature<T>, Feature<S>, E> mapFunc) Creates a new feature-list where each feature is the result of applying a map-function to an existing feature.void
The list of features.Creates a new feature-list which contains identical elements.int
size()
Returns the number of elements in this list.sort
(Comparator<Feature<T>> comparator) Creates a new feature-list sorted in a particular order.Methods inherited from class org.anchoranalysis.bean.AnchorBean
checkMisconfigured, describeChildren, duplicateBean, fields, findFieldsOfClass, getBeanName, getLocalPath, localise, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FeatureList
public FeatureList()Creates with an empty list. -
FeatureList
public FeatureList(int capacity) Creates with an empty list of particular capacity.- Parameters:
capacity
- initial capacity of the created empty list.
-
FeatureList
Creates with a singleFeature
.- Parameters:
feature
- the feature.
-
FeatureList
Creates from a stream ofFeature
s.- Parameters:
stream
- the stream of features.
-
FeatureList
Wraps an existing list.- Parameters:
list
- the list to wrap.
-
-
Method Details
-
initializeRecursive
public void initializeRecursive(FeatureInitialization initialization, Logger logger) throws InitializeException Initializes all features in the list, and recursively any features they contain.A feature must be initialized before being used for calculation.
- Parameters:
initialization
- the initialization parameters.logger
- the logger.- Throws:
InitializeException
- if any feature cannot be successfully initialized.
-
map
public <S extends FeatureInput,E extends Exception> FeatureList<S> map(CheckedFunction<Feature<T>, Feature<S>, throws EE> mapFunc) Creates a new feature-list where each feature is the result of applying a map-function to an existing feature.- Type Parameters:
S
- input-type of feature to be created as result of mappingE
- exception that can be thrown during mapping- Parameters:
mapFunc
- function to perform the mapping of each item.- Returns:
- a newly created feature-list (with the same number of items) containing the mapped features.
- Throws:
E
- if the mapping-function throws this exception.
-
filterAndMap
public <S extends FeatureInput,E extends Exception> FeatureList<S> filterAndMap(Predicate<Feature<T>> predicate, CheckedFunction<Feature<T>, Feature<S>, throws EE> mappingFunction) Filters inputs and then performs amap(org.anchoranalysis.core.functional.checked.CheckedFunction<org.anchoranalysis.feature.bean.Feature<T>, org.anchoranalysis.feature.bean.Feature<S>, E>)
.This is an immutable operation.
- Type Parameters:
S
- input-type of feature to be created as result of mappingE
- exception that can be thrown during mapping- Parameters:
predicate
- iff true object is included, otherwise excluded.mappingFunction
- the function that performs the mapping.- Returns:
- a newly created feature-list, a filtered version of all features, then mapped.
- Throws:
E
- if the mapping-function throws this exception.
-
append
Appends the features one or more (optional) feature-lists to the existing list.This is an immutable operation and the existing list is not altered.
- Parameters:
featureList
- the optional feature-lists to append.- Returns:
- a newly-created list with all the existing features, as well as any optional additional features.
-
deriveNames
Derives the names of the features.- Returns:
- the names.
-
sort
Creates a new feature-list sorted in a particular order.- Parameters:
comparator
- used to determine the order of elements when sorting.- Returns:
- a newly-created list with the same elements in sorted order.
-
shallowDuplicate
Creates a new feature-list which contains identical elements.- Returns:
- a newly-created list with the same elements in the same order.
-
add
Adds a feature to the current list.- Parameters:
feature
- the feature to add.
-
isEmpty
public boolean isEmpty()Returnstrue
if this list contains no elements.- Returns:
true
if this list contains no elements.
-
iterator
- Specified by:
iterator
in interfaceIterable<T extends FeatureInput>
-
size
public int size()Returns the number of elements in this list.- Returns:
- the number of elements in this list.
-
asList
Exposes the underlying list of features in this data-structure.Changing this list, will change the current instance.
- Returns:
- the internal list used to store features.
-
describeBean
Description copied from class:AnchorBean
A (maybe longer) description identifying the bean and perhaps its key parameters.By default, it returns the same as
AnchorBean.getBeanName()
but beans can optionally override it- Overrides:
describeBean
in classAnchorBean<FeatureList<T extends FeatureInput>>
- Returns:
- either the short-name of the bean, or a longer description
-
get
Returns the element at the specified position in this list.- Parameters:
index
- the index.- Returns:
- the feature at position
index
in the list.
-
clear
public void clear()Removes all of the elements from this list.The list will be empty after this call returns.
-
addAll
Add all the features inother
to the current list.- Parameters:
toAdd
- the features to add.
-
getList
The list of features. -
setList
The list of features.
-