Class KeyCollectionImpl.BuilderImpl<E>

java.lang.Object
org.magicwerk.brownies.collections.KeyCollectionImpl.BuilderImpl<E>
Direct Known Subclasses:
Key1Collection.Builder, Key1List.Builder, Key2Collection.Builder, Key2List.Builder, KeyCollection.Builder, KeyList.Builder
Enclosing class:
KeyCollectionImpl<E>

public static class KeyCollectionImpl.BuilderImpl<E> extends Object
Implementation of builder.
  • Field Details

    • keyColl

    • keyList

      KeyListImpl<E> keyList
    • allowNullElem

      boolean allowNullElem
    • constraint

      Predicate<E> constraint
    • beforeInsertTrigger

      Consumer<E> beforeInsertTrigger
    • afterInsertTrigger

      Consumer<E> afterInsertTrigger
    • beforeDeleteTrigger

      Consumer<E> beforeDeleteTrigger
    • afterDeleteTrigger

      Consumer<E> afterDeleteTrigger
    • keyMapBuilders

    • collection

      Collection<? extends E> collection
    • array

      E[] array
    • capacity

      int capacity
    • maxSize

      int maxSize
    • movingWindow

      Boolean movingWindow
    • setBehavior

      boolean setBehavior
      True to specify that the collection behaves like a Set on adding elements, i.e. if an element cannot be added due to duplicate or other constraints, no exception is thrown.
    • count

      boolean count
      True to count only number of occurrences of equal elements
    • useBigList

      boolean useBigList
      True to store list data in a BigList instance, false for a GapList instance (only used for KeyList, Key1List, Key2List)
  • Constructor Details

    • BuilderImpl

      public BuilderImpl()
  • Method Details

    • withNull

      protected KeyCollectionImpl.BuilderImpl<E> withNull(boolean allowNull)
      Specifies whether null elements are allowed or not. A null element will have null keys. This method does not implicitly create an element set, where as withElemNull(boolean) does.
      Parameters:
      allowNull - true to allow null elements (default), false to disallow
      Returns:
      this (fluent interfaces)
    • withConstraint

      protected KeyCollectionImpl.BuilderImpl<E> withConstraint(Predicate<E> constraint)
      Specify element constraint.
      Parameters:
      constraint - constraint element must satisfy, null for none (default)
      Returns:
      this (fluent interface)
    • withBeforeInsertTrigger

      protected KeyCollectionImpl.BuilderImpl<E> withBeforeInsertTrigger(Consumer<E> trigger)
      Specify insert trigger.
      Parameters:
      trigger - insert trigger method, null for none (default)
      Returns:
      this (fluent interface)
    • withAfterInsertTrigger

      protected KeyCollectionImpl.BuilderImpl<E> withAfterInsertTrigger(Consumer<E> trigger)
      Specify insert trigger.
      Parameters:
      trigger - insert trigger method, null for none (default)
      Returns:
      this (fluent interface)
    • withBeforeDeleteTrigger

      protected KeyCollectionImpl.BuilderImpl<E> withBeforeDeleteTrigger(Consumer<E> trigger)
      Specify delete trigger.
      Parameters:
      trigger - delete trigger method, null for none (default)
      Returns:
      this (fluent interface)
    • withAfterDeleteTrigger

      protected KeyCollectionImpl.BuilderImpl<E> withAfterDeleteTrigger(Consumer<E> trigger)
      Specify delete trigger.
      Parameters:
      trigger - delete trigger method, null for none (default)
      Returns:
      this (fluent interface)
    • withCapacity

      protected KeyCollectionImpl.BuilderImpl<E> withCapacity(int capacity)
      Specify initial capacity.
      Parameters:
      capacity - initial capacity
      Returns:
      this (fluent interface)
    • withContent

      protected KeyCollectionImpl.BuilderImpl<E> withContent(Collection<? extends E> elements)
      Specify elements added to the collection upon creation.
      Parameters:
      elements - initial elements
      Returns:
      this (fluent interface)
    • withContent

      protected KeyCollectionImpl.BuilderImpl<E> withContent(E... elements)
      Specify elements added to the collection upon creation.
      Parameters:
      elements - initial elements
      Returns:
      this (fluent interface)
    • withMaxSize

      protected KeyCollectionImpl.BuilderImpl<E> withMaxSize(int maxSize)
      Specify maximum size of collection. If an attempt is made to add more elements, an exception is thrown.
      Parameters:
      maxSize - maximum size
      Returns:
      this (fluent interface)
    • withWindowSize

      protected KeyCollectionImpl.BuilderImpl<E> withWindowSize(int maxSize)
      Specify maximum window size of collection. If an attempt is made to add and additional element, the first element is removed.
      Parameters:
      maxSize - maximum window size
      Returns:
      this (fluent interface)
    • withSetBehavior

      protected KeyCollectionImpl.BuilderImpl<E> withSetBehavior(boolean setBehavior)
      Specifies that the collection behaves like a Set on adding elements, i.e. if an element cannot be added due to duplicate or other constraints, no exception is thrown.
      Parameters:
      setBehavior - true to define set behavior (default is false)
      Returns:
      this (fluent interface)
    • withElemCount

      protected KeyCollectionImpl.BuilderImpl<E> withElemCount(boolean count)
      Specifies that the collection only counts the number of occurrences of equal elements, but does not store the elements themselves.
      Parameters:
      count - true to count only number of occurrences (default is false)
      Returns:
      this (fluent interface)
    • withElemSet

      protected KeyCollectionImpl.BuilderImpl<E> withElemSet()
      Add element map (with ident mapper).
      Returns:
      this (fluent interface)
    • withOrderByElem

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByElem(boolean orderBy)
      Specifies that the collection will have the order of the element set. The element set must be sorted, if no sort order has been defined, the natural comparator will be used. If the set allows null values, the used comparator will sort them last.
      Parameters:
      orderBy - if true the collection will have the order of the element set (default is false, only one key map or the element set can have the order by option set)
      Returns:
      this (fluent interface)
    • withOrderByElem

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByElem(Class<?> type)
      Specifies that the list will have the order of the element set. The set will store values of the primitive type specified like int. The set will be sorted using the natural comparator and no null values are allowed.
      Parameters:
      type - primitive type to use for key map (only one key map or the element set can have the order by option set)
      Returns:
      this (fluent interface)
    • withElemNull

      protected KeyCollectionImpl.BuilderImpl<E> withElemNull(boolean allowNull)
      Specifies whether null elements are allowed or not. A null element will have null keys. This method does implicitly create an element set, where as withNull(boolean) does not.
      Parameters:
      allowNull - true to allow null elements, false to disallow (default is true)
      Returns:
      this (fluent interfaces)
    • withElemDuplicates

      protected KeyCollectionImpl.BuilderImpl<E> withElemDuplicates(boolean allowDuplicates)
      Specify whether duplicates are allowed or not. This method does implicitly create an element set.
      Parameters:
      allowDuplicates - true to allow duplicates (default is true)
      Returns:
      this (fluent interfaces)
    • withElemDuplicates

      protected KeyCollectionImpl.BuilderImpl<E> withElemDuplicates(boolean allowDuplicates, boolean allowDuplicatesNull)
      Specify whether duplicates are allowed or not. This method does implicitly create an element set.
      Parameters:
      allowDuplicates - true to allow duplicates (default is true)
      allowDuplicatesNull - true to allow duplicate null values (default is true)
      Returns:
      this (fluent interfaces)
    • withElemSort

      protected KeyCollectionImpl.BuilderImpl<E> withElemSort(boolean sort)
      Specify that the element set should be sorted using the natural comparator. If the collection supports null values, they are sorted last. This method does implicitly create an element set. Note that this does not automatically sort the collection itself, call a withOrderBy method for this.
      Parameters:
      sort - true to sorted, false for unsorted (default is false)
      Returns:
      this (fluent interface)
    • withElemSort

      protected KeyCollectionImpl.BuilderImpl<E> withElemSort(Comparator<? super E> comparator)
      Set comparator to use for sorting the element set. If the collection allows null values, the comparator must be able to compare null values. If the comparator does not support null values, use withElemSort(Comparator, boolean) to explicitly specify how null values should be sorted. This method does implicitly create an element set. Note that this does not automatically sort the collection itself, call a withOrderBy method for this.
      Parameters:
      comparator - comparator to use for sorting (null for natural comparator)
      Returns:
      this (fluent interface)
    • withElemSort

      protected KeyCollectionImpl.BuilderImpl<E> withElemSort(Comparator<? super E> comparator, boolean sortNullsFirst)
      Set comparator to use for sorting the element set. This method should be used if the collection can contain null values, but the comparator is not able to handle them. The parameter sortNullsFirst determine how the null values should be sorted. This method does implicitly create an element set.
      Parameters:
      comparator - comparator to use for sorting
      sortNullsFirst - true to sort null values first, false for last
      Returns:
      this (fluent interface)
    • withPrimaryElem

      protected KeyCollectionImpl.BuilderImpl<E> withPrimaryElem()
      Specify the element to be a primary key. This is identical to calling withElemNull(false) and withElemDuplicates(false).
      Returns:
      this (fluent interface)
    • withUniqueElem

      protected KeyCollectionImpl.BuilderImpl<E> withUniqueElem()
      Specify the element to be a unique key. This is identical to calling withElemNull(true) and withElemDuplicates(false, true).
      Returns:
      this (fluent interface)
    • withKeyMap

      protected KeyCollectionImpl.BuilderImpl<E> withKeyMap(int keyIndex, Function mapper)
    • withOrderByKey

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByKey(int keyIndex, boolean orderBy)
    • withOrderByKey

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByKey(int keyIndex, Class<?> type)
    • withListType

      protected KeyCollectionImpl.BuilderImpl<E> withListType(Class<?> type)
      Specifies that the list will store its elements as primitive type.
      Parameters:
      type - primitive type to use for list
      Returns:
      this (fluent interface)
    • withListBig

      protected KeyCollectionImpl.BuilderImpl<E> withListBig(boolean big)
      Specify whether list should be stored in an instance of BigList or GapList.
      Parameters:
      big - true to store list content in an instance of BigList, false for GapList
      Returns:
      this (fluent interface)
    • withKeyNull

      protected KeyCollectionImpl.BuilderImpl<E> withKeyNull(int keyIndex, boolean allowNull)
    • withKeyDuplicates

      protected KeyCollectionImpl.BuilderImpl<E> withKeyDuplicates(int keyIndex, boolean allowDuplicates, boolean allowDuplicatesNull)
    • withKeySort

      protected KeyCollectionImpl.BuilderImpl<E> withKeySort(int keyIndex, boolean sort)
    • withKeySort

      protected KeyCollectionImpl.BuilderImpl<E> withKeySort(int keyIndex, Comparator<?> comparator)
    • withKeySort

      protected KeyCollectionImpl.BuilderImpl<E> withKeySort(int keyIndex, Comparator<?> comparator, boolean sortNullsFirst)
    • withPrimaryKeyMap

      protected KeyCollectionImpl.BuilderImpl<E> withPrimaryKeyMap(int keyIndex, Function mapper)
    • withUniqueKeyMap

      protected KeyCollectionImpl.BuilderImpl<E> withUniqueKeyMap(int keyIndex, Function mapper)
    • withOrderByKey1

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByKey1(boolean orderBy)
      Specifies that the collection will have the order of the key map. The key map must be sorted, if no sort order has been defined, the natural comparator will be used. If the map allows null values, the used comparator will sort them last.
      Parameters:
      orderBy - if true the collection will have the order of the key map (default is false, only one key map or the element set can have the order by option set)
      Returns:
      this (fluent interface)
    • withOrderByKey1

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByKey1(Class<?> type)
      Specifies that the list will have the order of the key map. The key map will store values of the primitive type specified like int. The key map will be sorted using the natural comparator and no null values are allowed.
      Parameters:
      type - primitive type to use for key map (only one key map or the element set can have the order by option set)
      Returns:
      this (fluent interface)
    • withKey1Null

      protected KeyCollectionImpl.BuilderImpl<E> withKey1Null(boolean allowNull)
      Specify whether null elements are allowed or not. A null element will have a null key.
      Parameters:
      allowNull - true to allow null elements, false to disallow
      Returns:
      this (fluent interfaces)
    • withKey1Duplicates

      protected KeyCollectionImpl.BuilderImpl<E> withKey1Duplicates(boolean allowDuplicates)
      Specify whether duplicates are allowed or not.
      Parameters:
      allowDuplicates - true to allow duplicates
      Returns:
      this (fluent interfaces)
    • withKey1Duplicates

      protected KeyCollectionImpl.BuilderImpl<E> withKey1Duplicates(boolean allowDuplicates, boolean allowDuplicatesNull)
      Specify whether duplicates are allowed or not.
      Parameters:
      allowDuplicates - true to allow duplicates
      allowDuplicatesNull - true to allow duplicate null values
      Returns:
      this (fluent interfaces)
    • withKey1Sort

      protected KeyCollectionImpl.BuilderImpl<E> withKey1Sort(boolean sort)
      Set comparator to use for sorting the key map. Note that this does not automatically sort the list itself, call a withOrderBy method for this.
      Parameters:
      sort - true to sort key map
      Returns:
      this (fluent interface)
    • withOrderByKey2

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByKey2(boolean orderBy)
      Specifies that the collection will have the order of the key map. The key map must be sorted, if no sort order has been defined, the natural comparator will be used. If the map allows null values, the used comparator will sort them last.
      Parameters:
      orderBy - if true the collection will have the order of the key map (default is false, only one key map or the element set can have the order by option set)
      Returns:
      this (fluent interface)
    • withOrderByKey2

      protected KeyCollectionImpl.BuilderImpl<E> withOrderByKey2(Class<?> type)
      Specifies that the list will have the order of the key map. The key map will store values of the primitive type specified like int. The key map will be sorted using the natural comparator and no null values are allowed.
      Parameters:
      type - primitive type to use for key map (only one key map or the element set can have the order by option set)
      Returns:
      this (fluent interface)
    • withKey2Null

      protected KeyCollectionImpl.BuilderImpl<E> withKey2Null(boolean allowNull)
      Specify whether null elements are allowed or not. A null element will have a null key.
      Parameters:
      allowNull - true to allow null elements, false to disallow
      Returns:
      this (fluent interfaces)
    • withKey2Duplicates

      protected KeyCollectionImpl.BuilderImpl<E> withKey2Duplicates(boolean allowDuplicates)
      Specify whether duplicates are allowed or not.
      Parameters:
      allowDuplicates - true to allow duplicates
      Returns:
      this (fluent interfaces)
    • withKey2Duplicates

      protected KeyCollectionImpl.BuilderImpl<E> withKey2Duplicates(boolean allowDuplicates, boolean allowDuplicatesNull)
      Specify whether duplicates are allowed or not.
      Parameters:
      allowDuplicates - true to allow duplicates
      allowDuplicatesNull - true to allow duplicate null values
      Returns:
      this (fluent interfaces)
    • withKey2Sort

      protected KeyCollectionImpl.BuilderImpl<E> withKey2Sort(boolean sort)
      Set comparator to use for sorting the key map. Note that this does not automatically sort the list itself, call a withOrderBy method for this.
      Parameters:
      sort - true to sort key map
      Returns:
      this (fluent interface)
    • initKeyMapBuilder

      void initKeyMapBuilder(int numKeys)
      Parameters:
      numKeys - number of keys
    • hasElemMapBuilder

      boolean hasElemMapBuilder()
    • getKeyMapBuilder

    • isTrue

      boolean isTrue(Boolean b)
    • isFalse

      boolean isFalse(Boolean b)
    • buildKeyMap

      KeyCollectionImpl.KeyMap buildKeyMap(KeyCollectionImpl.BuilderImpl.KeyMapBuilder keyMapBuilder, boolean list)
      Initialize KeyMap.
      Parameters:
      list - true if a KeyListImpl is built up, false for KeyCollectionImpl
      keyMapBuild - key map builder to use for initialization
    • build

      void build(KeyCollectionImpl keyColl, boolean list)
      Initialize KeyCollectionImpl.
      Parameters:
      keyColl - collection to initialize
      list - true if a KeyListImpl is built up, false for KeyCollectionImpl
    • init

      void init(KeyCollectionImpl keyColl)
      This method is called if a KeyCollection, Key1Collection, Key2Collection is initialized.
      Parameters:
      keyColl - KeyCollectionImpl which has already been initialized
    • init

      void init(KeyCollectionImpl keyColl, KeyListImpl keyList)
      This method is called if a KeyList, Key1List, Key2List is initialized.
      Parameters:
      keyColl - KeyCollectionImpl which has already been initialized
      keyList - KeyListImpl to initialize
    • initList

      IList<?> initList()