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>>
UniqueResultStructures are the leaves in the tree of nested SearchStructures. Each UniqueResultStructure defines a result of a search. It is designed to hold exactly one value, in contrast to ResultStructures. Because of this UniqueResultStructures throw an UnsupportedOperationException when trying to merge them. The benefit is that setting up a SearchStructure with ambiguous results provokes an exception, even before it is put to use.
  • Method Details

    • createWith

      public static <R> UniqueResultStructure<R> createWith(R resultValue)
      Creates a new ResultSet with the given resultValue as its only result value. The resultValue must not be null.
    • get

      public SearchStructure<R> get(Object key)
      Description copied from class: SearchStructure
      Returns the nested SearchStructure for the given key. This method never returns null. If no value exists for a given key an EmptySearchStructure is returned as a fall-back.
      Specified by:
      get in class SearchStructure<R>
      Parameters:
      key - The key for the requested nested SearchStructure
      Returns:
      The nested SearchStructure or an EmptySearchStructure if the key does not exist.
    • 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
    • merge

      public void merge(UniqueResultStructure<R> otherStructure)
      Description copied from interface: MergeAndCopyStructure
      Merging adds the contents of the otherMergable to this object. This object then contains the combined content. The other object remains unchanged.Merging a SearchStructure deletes no content, instead equal values are being merged recursively.
      Specified by:
      merge in interface MergeAndCopyStructure<R>
      Parameters:
      otherStructure - The object that should be merged into this object
    • getUnique

      public R getUnique(R defaultValue)
      Description copied from class: SearchStructure
      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 AssertionError if there is more than one value.

      Overrides:
      getUnique in class SearchStructure<R>
      Parameters:
      defaultValue - The defaultValue which is returned if this SearchStructure is empty.
      Returns:
      The result hold by this SearchStructure or the defaultValue if the structure is empty.
    • getUnique

      public R getUnique()
      Description copied from class: SearchStructure
      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 AssertionError if there is more than one values. If there is no value it throws an NoSuchElementException exception.

      Overrides:
      getUnique in class SearchStructure<R>
      Returns:
      The one and only result hold by this SearchStructure.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class 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 calling MergeAndCopyStructure.copy().

      The UniqueResultStructure is immutable. Hence it is not needed to create a copy.

      Specified by:
      copy in interface MergeAndCopyStructure<R>
      Returns:
      T that is a copy of the calling object