Class AbstractMapStructure<K,V extends SearchStructure<R> & MergeAndCopyStructure<V>,R>
java.lang.Object
org.faktorips.runtime.internal.tableindex.SearchStructure<R>
org.faktorips.runtime.internal.tableindex.AbstractMapStructure<K,V,R>
- Type Parameters:
K- The type of key in the underlying map - can be restricted in subclassesV- The type of values in the map. Values are nestedstructureswhich must:- have the same result type
Ras thisAbstractMapStructure - implement the
MergeAndCopyStructureinterface. The class definition enforces the implementation ofMergeAndCopyStructurewithout restricting the type V to a specificSearchStructure. Therefore the mergable type is bound to? super V.
- have the same result type
R- The type of the result values. The result type must be the same in every nested structure.
- Direct Known Subclasses:
KeyStructure,RangeStructure,TwoColumnRangeStructure
public abstract class AbstractMapStructure<K,V extends SearchStructure<R> & MergeAndCopyStructure<V>,R>
extends SearchStructure<R>
Abstract implementation for all
structures that map keys to nested
structures much like a map.
This class provides a put(Object, SearchStructure) method to add nested structures.
Adding multiple structures with the same key will result in those structures being merged. This
makes setting up nested map structures easy.
This abstract implementation makes no assumption about the underlying map implementation. The map
instance is provided by subclasses via the constructor. Thus the SearchStructure.get(Object) method
implementation must also be provided by subclasses using the chosen data structure.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMapStructure(Map<K, V> map) Creates a newAbstractMapStructurewith the specified map instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected SearchStructure<R>Simply returns anEmptySearchStructure.protected <T extends AbstractMapStructure<K,V, R>>
TfillCopy(T structure) get()Returns the set of resulting values.getMap()protected SearchStructure<R>getValidResult(V result) Checks whether the given result isnulland returns a fall-back result (an emptyResultStructure) in that case.protected voidmerge(AbstractMapStructure<K, V, R> otherMap) voidPuts a new element in the map.Methods inherited from class org.faktorips.runtime.internal.tableindex.SearchStructure
get, getUnique, getUnique
-
Constructor Details
-
AbstractMapStructure
Creates a newAbstractMapStructurewith the specified map instance.- Parameters:
map- The map that should be used as underlying data structure.
-
-
Method Details
-
put
Puts a new element in the map. If there is already a value for the given key, the two values will be merged together. Thus existing values will never be overwritten.- Parameters:
key- key that maps to the specified valuevalue- value to be associated with the specified key.- See Also:
-
merge
-
fillCopy
-
get
Description copied from class:SearchStructureReturns the set of resulting values. If thisSearchStructureis noResultStructurethis method simply aggregates every nestedstructures'results. Beware that the aggregation of nested elements has linear complexity.- Specified by:
getin classSearchStructure<R>- Returns:
- The set of resulting values that are reachable by this
SearchStructure
-
getMap
-
getValidResult
Checks whether the given result isnulland returns a fall-back result (an emptyResultStructure) in that case.- Parameters:
result- a valid result ornull.- Returns:
- the given result or an
EmptySearchStructureif the given result isnull. Never returnsnull.
-
emptyResult
Simply returns anEmptySearchStructure. This is the typesafe representation ofEMPTY.
-