Class SearchStructure<R>
- java.lang.Object
-
- org.faktorips.runtime.internal.tableindex.SearchStructure<R>
-
- Type Parameters:
R- The type of the resulting values.
- Direct Known Subclasses:
AbstractMapStructure,ResultStructure,UniqueResultStructure
public abstract class SearchStructure<R> extends java.lang.ObjectASearchStructureis a data structure that is used by tables to optimize index key access on their data. The fundamental idea is that aSearchStructureis a self containing composite, that means every structure contains another structure.For each part of an index a nested
SearchStructureexists. The containedSearchStructurecan be retrieved via theget(Object)method, called with the key that is to be searched for. The last call isget()which then retrieves the resulting values as aSet.To prevent
NullPointerExceptions without checking fornull, everyget(Object)will return a validSearchStructure. If there is no nested structure for any given key, anEmptySearchStructureis returned as a fall-back. Callingget(Object)on it (with any key) simply returns theEmptySearchStructureitself. In other words anEmptySearchStructureis a kind of null-Object.Example: given a nested structure Map → Tree → Tree and the call
get(x).get(y).get(z)on it. Ifget(x)on the map yields no result anEmptySearchStructureis returned. Nevertheless the followingget(y).get(z)can be called without checking fornull. The empty result is returned on every subsequent call.- See Also:
ResultStructure
-
-
Constructor Summary
Constructors Constructor Description SearchStructure()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.util.Set<R>get()Returns the set of resulting values.abstract SearchStructure<R>get(java.lang.Object key)Returns the nestedSearchStructurefor the given key.RgetUnique()Returns the value if there is exactly one value.RgetUnique(R defaultValue)Returns the value if there is exactly one value or the given defaultValue if this structure is empty.
-
-
-
Method Detail
-
get
public abstract SearchStructure<R> get(java.lang.Object key)
Returns the nestedSearchStructurefor the given key. This method never returnsnull. If no value exists for a given key anEmptySearchStructureis returned as a fall-back.- Parameters:
key- The key for the requested nestedSearchStructure- Returns:
- The nested
SearchStructureor anEmptySearchStructureif the key does not exist.
-
get
public abstract java.util.Set<R> get()
Returns the set of resulting values. If thisSearchStructureis noResultStructurethis method simply aggregates every nestedstructures'results. Beware that the aggregation of nested elements has linear complexity.- Returns:
- The set of resulting values that are reachable by this
SearchStructure
-
getUnique
public R getUnique()
Returns the value if there is exactly one value.Use this method if you know there should be exactly one result value. This method throws an
AssertionErrorif there is more than one values. If there is no value it throws anNoSuchElementExceptionexception.- Returns:
- The one and only result hold by this
SearchStructure. - Throws:
java.lang.AssertionError- if your assertion that there is at most one element is wrong and hence there is more than one value.java.util.NoSuchElementException- If there is no element at all.
-
getUnique
public R getUnique(R defaultValue)
Returns the value if there is exactly one value or the given defaultValue if this structure is empty.Use this method if you know there should be at most one result value. This method throws an
AssertionErrorif there is more than one value.- Parameters:
defaultValue- The defaultValue which is returned if thisSearchStructureis empty.- Returns:
- The result hold by this
SearchStructureor the defaultValue if the structure is empty. - Throws:
java.lang.AssertionError- if your assertion that there is at most one element is wrong and hence there are more than one result values.
-
-