org.faktorips.runtime.internal.tableindex
Class AbstractMapStructure<K,V extends SearchStructure<R> & MergeAndCopyStructure<V>,R>

java.lang.Object
  extended by org.faktorips.runtime.internal.tableindex.SearchStructure<R>
      extended by org.faktorips.runtime.internal.tableindex.AbstractMapStructure<K,V,R>
Type Parameters:
K - The type of key in the underlying map - can be restricted in subclasses
V - The type of values in the map. Values are nested structures which must:
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
protected AbstractMapStructure(Map<K,V> map)
          Creates a new AbstractMapStructure with the specified map instance.
 
Method Summary
protected  SearchStructure<R> emptyResult()
          Simply returns an EmptySearchStructure.
protected
<T extends AbstractMapStructure<K,V,R>>
T
fillCopy(T structure)
           
 Set<R> get()
          Returns the set of resulting values.
protected  Map<K,V> getMap()
           
protected  SearchStructure<R> getValidResult(V result)
          Checks whether the given result is null and returns a fall-back result (an empty ResultStructure) in that case.
protected  void merge(AbstractMapStructure<K,V,R> otherMap)
           
 void put(K key, V value)
          Puts a new element in the map.
 
Methods inherited from class org.faktorips.runtime.internal.tableindex.SearchStructure
get, getUnique, getUnique
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMapStructure

protected AbstractMapStructure(Map<K,V> map)
Creates a new AbstractMapStructure with 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 value
value - 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 Set<R> get()
Description copied from class: SearchStructure
Returns the set of resulting values. If this SearchStructure is no ResultStructure this method simply aggregates every nested structures' results. Beware that the aggregation of nested elements has linear complexity.

Specified by:
get in class SearchStructure<R>
Returns:
The set of resulting values that are reachable by this SearchStructure

getMap

protected Map<K,V> getMap()

getValidResult

protected SearchStructure<R> getValidResult(V result)
Checks whether the given result is null and returns a fall-back result (an empty ResultStructure) in that case.

Parameters:
result - a valid result or null.
Returns:
the given result or an EmptySearchStructure if the given result is null. Never returns null.

emptyResult

protected SearchStructure<R> emptyResult()
Simply returns an EmptySearchStructure. This is the typesafe representation of EMPTY.



Copyright © 2015. All rights reserved.