Class UniqueResultStructure<R>
- java.lang.Object
-
- org.faktorips.runtime.internal.tableindex.SearchStructure<R>
-
- org.faktorips.runtime.internal.tableindex.UniqueResultStructure<R>
-
- All Implemented Interfaces:
MergeAndCopyStructure<UniqueResultStructure<R>>
public class UniqueResultStructure<R> extends SearchStructure<R> implements MergeAndCopyStructure<UniqueResultStructure<R>>
UniqueResultStructuresare the leaves in the tree of nestedSearchStructures. EachUniqueResultStructuredefines a result of a search. It is designed to hold exactly one value, in contrast toResultStructures. Because of thisUniqueResultStructuresthrow anUnsupportedOperationExceptionwhen trying to merge them. The benefit is that setting up aSearchStructurewith ambiguous results provokes an exception, even before it is put to use.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UniqueResultStructure<R>copy()This method copies the object which calls it.static <R> UniqueResultStructure<R>createWith(R resultValue)Creates a newResultSetwith the given resultValue as its only result value.booleanequals(java.lang.Object obj)java.util.Set<R>get()Returns the set of resulting values.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.inthashCode()voidmerge(UniqueResultStructure<R> otherStructure)Merging adds the contents of the otherMergable to this object.java.lang.StringtoString()
-
-
-
Method Detail
-
createWith
public static <R> UniqueResultStructure<R> createWith(R resultValue)
Creates a newResultSetwith the given resultValue as its only result value. The resultValue must not be null.
-
get
public SearchStructure<R> get(java.lang.Object key)
Description copied from class:SearchStructureReturns the nestedSearchStructurefor the given key. This method never returnsnull. If no value exists for a given key anEmptySearchStructureis returned as a fall-back.- Specified by:
getin classSearchStructure<R>- Parameters:
key- The key for the requested nestedSearchStructure- Returns:
- The nested
SearchStructureor anEmptySearchStructureif the key does not exist.
-
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
-
merge
public void merge(UniqueResultStructure<R> otherStructure)
Description copied from interface:MergeAndCopyStructureMerging adds the contents of the otherMergable to this object. This object then contains the combined content. The other object remains unchanged.Merging aSearchStructuredeletes no content, instead equal values are being merged recursively.- Specified by:
mergein interfaceMergeAndCopyStructure<R>- Parameters:
otherStructure- The object that should be merged into this object
-
getUnique
public R getUnique(R defaultValue)
Description copied from class:SearchStructureReturns 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.- Overrides:
getUniquein classSearchStructure<R>- Parameters:
defaultValue- The defaultValue which is returned if thisSearchStructureis empty.- Returns:
- The result hold by this
SearchStructureor the defaultValue if the structure is empty.
-
getUnique
public R getUnique()
Description copied from class:SearchStructureReturns 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.- Overrides:
getUniquein classSearchStructure<R>- Returns:
- The one and only result hold by this
SearchStructure.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
copy
public UniqueResultStructure<R> copy()
This method copies the object which calls it. The newly created object has the same properties like the object callingMergeAndCopyStructure.copy().The
UniqueResultStructureis immutable. Hence it is not needed to create a copy.- Specified by:
copyin interfaceMergeAndCopyStructure<R>- Returns:
- T that is a copy of the calling object
-
-