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 allstructuresthat map keys to nestedstructuresmuch 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
Constructors Modifier Constructor Description protectedAbstractMapStructure(java.util.Map<K,V> map)Creates a newAbstractMapStructurewith the specified map instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SearchStructure<R>emptyResult()Simply returns anEmptySearchStructure.protected <T extends AbstractMapStructure<K,V,R>>
TfillCopy(T structure)java.util.Set<R>get()Returns the set of resulting values.protected java.util.Map<K,V>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)voidput(K key, V value)Puts a new element in the map.-
Methods inherited from class org.faktorips.runtime.internal.tableindex.SearchStructure
get, getUnique, getUnique
-
-
-
-
Constructor Detail
-
AbstractMapStructure
protected AbstractMapStructure(java.util.Map<K,V> map)
Creates a newAbstractMapStructurewith the specified map instance.- Parameters:
map- The map that should be used as underlying data structure.
-
-
Method Detail
-
put
public void put(K key, V value)
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:
Map.put(Object, Object),merge(AbstractMapStructure)
-
merge
protected void merge(AbstractMapStructure<K,V,R> otherMap)
-
fillCopy
protected <T extends AbstractMapStructure<K,V,R>> T fillCopy(T structure)
-
get
public java.util.Set<R> 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
-
getValidResult
protected SearchStructure<R> getValidResult(V result)
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
protected SearchStructure<R> emptyResult()
Simply returns anEmptySearchStructure. This is the typesafe representation ofEMPTY.
-
-