Class FeatureList<T extends FeatureInput>
Object
org.anchoranalysis.bean.AnchorBean<FeatureList<T>>
org.anchoranalysis.feature.bean.list.FeatureList<T>
- 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:
for the preferred means of creating instances.
-
Constructor Summary
Constructors Constructor Description FeatureList()Creates 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 ofFeatures.FeatureList(Feature<T> feature)Creates with a singleFeature. -
Method Summary
Modifier and Type Method Description voidadd(Feature<? extends T> feature)Adds a feature to the current list.voidaddAll(FeatureList<? extends T> toAdd)Add all the features inotherto the current list.FeatureList<T>append(Optional<FeatureList<T>> featureList)Appends the features one or more (optional) feature-lists to the existing list.List<Feature<T>>asList()Exposes the underlying list of features in this data-structure.voidclear()Removes all of the elements from this list.FeatureNameListderiveNames()Derives the names of the features.StringdescribeBean()<S extends FeatureInput, E extends Exception>
FeatureList<S>filterAndMap(Predicate<Feature<T>> predicate, CheckedFunction<Feature<T>,Feature<S>,E> mappingFunction)Feature<T>get(int index)Returns the element at the specified position in this list.List<Feature<T>>getList()The list of features.voidinitializeRecursive(FeatureInitialization initialization, Logger logger)Initializes all features in the list, and recursively any features they contain.booleanisEmpty()Returnstrueif this list contains no elements.Iterator<Feature<T>>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.voidsetList(List<Feature<T>> list)The list of features.FeatureList<T>shallowDuplicate()Creates a new feature-list which contains identical elements.intsize()Returns the number of elements in this list.FeatureList<T>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
-
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 ofFeatures.- 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 InitializeExceptionInitializes 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>,E> mapFunc) throws E extends ExceptionCreates 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.E extends Exception
-
filterAndMap
public <S extends FeatureInput, E extends Exception> FeatureList<S> filterAndMap(Predicate<Feature<T>> predicate, CheckedFunction<Feature<T>,Feature<S>,E> mappingFunction) throws E extends ExceptionFilters 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:
mappingFunction- the function that performs the mapping.predicate- iff true object is included, otherwise excluded.- Returns:
- a newly created feature-list, a filtered version of all features, then mapped.
- Throws:
E- if the mapping-function throws this exception.E extends 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()Returnstrueif this list contains no elements.- Returns:
trueif this list contains no elements.
-
iterator
- Specified by:
iteratorin 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
- Overrides:
describeBeanin classAnchorBean<FeatureList<T extends FeatureInput>>
-
get
Returns the element at the specified position in this list.- Parameters:
index- the index.- Returns:
- the feature at position
indexin 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 inotherto the current list.- Parameters:
toAdd- the features to add.
-
getList
The list of features. -
setList
The list of features.
-