Class KeyCollection.Builder<E>
- java.lang.Object
-
- org.magicwerk.brownies.collections.KeyCollectionImpl.BuilderImpl<E>
-
- org.magicwerk.brownies.collections.KeyCollection.Builder<E>
-
- Direct Known Subclasses:
KeySet.Builder
- Enclosing class:
- KeyCollection<E>
public static class KeyCollection.Builder<E> extends KeyCollectionImpl.BuilderImpl<E>
Builder to construct KeyCollection instances.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.magicwerk.brownies.collections.KeyCollectionImpl.BuilderImpl
KeyCollectionImpl.BuilderImpl.KeyMapBuilder<E,K>
-
-
Field Summary
-
Fields inherited from class org.magicwerk.brownies.collections.KeyCollectionImpl.BuilderImpl
afterDeleteTrigger, afterInsertTrigger, allowNullElem, array, beforeDeleteTrigger, beforeInsertTrigger, capacity, collection, constraint, count, keyColl, keyList, keyMapBuilders, maxSize, movingWindow, setBehavior, useBigList
-
-
Constructor Summary
Constructors Constructor Description Builder()
Default constructor.Builder(KeyCollection<E> keyColl)
Private constructor used if extending KeyCollection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyCollection<E>
build()
KeyCollection.Builder<E>
withAfterDeleteTrigger(java.util.function.Consumer<E> trigger)
Specify delete trigger.KeyCollection.Builder<E>
withAfterInsertTrigger(java.util.function.Consumer<E> trigger)
Specify insert trigger.KeyCollection.Builder<E>
withBeforeDeleteTrigger(java.util.function.Consumer<E> trigger)
Specify delete trigger.KeyCollection.Builder<E>
withBeforeInsertTrigger(java.util.function.Consumer<E> trigger)
Specify insert trigger.KeyCollection.Builder<E>
withCapacity(int capacity)
Specify initial capacity.KeyCollection.Builder<E>
withConstraint(java.util.function.Predicate<E> constraint)
Specify element constraint.KeyCollection.Builder<E>
withContent(E... elements)
Specify elements added to the collection upon creation.KeyCollection.Builder<E>
withContent(java.util.Collection<? extends E> elements)
Specify elements added to the collection upon creation.KeyCollection.Builder<E>
withElemCount(boolean count)
Specifies that the collection only counts the number of occurrences of equal elements, but does not store the elements themselves.KeyCollection.Builder<E>
withElemDuplicates(boolean allowDuplicates)
Specify whether duplicates are allowed or not.KeyCollection.Builder<E>
withElemDuplicates(boolean allowDuplicates, boolean allowDuplicatesNull)
Specify whether duplicates are allowed or not.KeyCollection.Builder<E>
withElemNull(boolean allowNull)
Specifies whether null elements are allowed or not.KeyCollection.Builder<E>
withElemSet()
Add element map (with ident mapper).KeyCollection.Builder<E>
withElemSort(boolean sort)
Specify that the element set should be sorted using the natural comparator.KeyCollection.Builder<E>
withElemSort(java.util.Comparator<? super E> comparator)
Set comparator to use for sorting the element set.KeyCollection.Builder<E>
withElemSort(java.util.Comparator<? super E> comparator, boolean sortNullsFirst)
Set comparator to use for sorting the element set.KeyCollection.Builder<E>
withMaxSize(int maxSize)
Specify maximum size of collection.KeyCollection.Builder<E>
withNull(boolean allowNull)
Specifies whether null elements are allowed or not.KeyCollection.Builder<E>
withOrderByElem(boolean orderBy)
Specifies that the collection will have the order of the element set.KeyCollection.Builder<E>
withPrimaryElem()
Specify the element to be a primary key.KeyCollection.Builder<E>
withSetBehavior(boolean setBehavior)
Specifies that the collection behaves like aSet
on adding elements, i.e.KeyCollection.Builder<E>
withUniqueElem()
Specify the element to be a unique key.-
Methods inherited from class org.magicwerk.brownies.collections.KeyCollectionImpl.BuilderImpl
build, buildKeyMap, getKeyMapBuilder, hasElemMapBuilder, init, init, initKeyMapBuilder, initList, isFalse, isTrue, withKey1Duplicates, withKey1Duplicates, withKey1Null, withKey1Sort, withKey2Duplicates, withKey2Duplicates, withKey2Null, withKey2Sort, withKeyDuplicates, withKeyMap, withKeyNull, withKeySort, withKeySort, withKeySort, withListBig, withListType, withOrderByElem, withOrderByKey, withOrderByKey, withOrderByKey1, withOrderByKey1, withOrderByKey2, withOrderByKey2, withPrimaryKeyMap, withUniqueKeyMap, withWindowSize
-
-
-
-
Constructor Detail
-
Builder
public Builder()
Default constructor.
-
Builder
Builder(KeyCollection<E> keyColl)
Private constructor used if extending KeyCollection.- Parameters:
keyColl
- key collection
-
-
Method Detail
-
build
public KeyCollection<E> build()
- Returns:
- created collection
-
withNull
public KeyCollection.Builder<E> withNull(boolean allowNull)
Description copied from class:KeyCollectionImpl.BuilderImpl
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 asKeyCollectionImpl.BuilderImpl.withElemNull(boolean)
does.- Overrides:
withNull
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
allowNull
- true to allow null elements (default), false to disallow- Returns:
- this (fluent interfaces)
-
withConstraint
public KeyCollection.Builder<E> withConstraint(java.util.function.Predicate<E> constraint)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify element constraint.- Overrides:
withConstraint
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
constraint
- constraint element must satisfy, null for none (default)- Returns:
- this (fluent interface)
-
withBeforeInsertTrigger
public KeyCollection.Builder<E> withBeforeInsertTrigger(java.util.function.Consumer<E> trigger)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify insert trigger.- Overrides:
withBeforeInsertTrigger
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
trigger
- insert trigger method, null for none (default)- Returns:
- this (fluent interface)
-
withAfterInsertTrigger
public KeyCollection.Builder<E> withAfterInsertTrigger(java.util.function.Consumer<E> trigger)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify insert trigger.- Overrides:
withAfterInsertTrigger
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
trigger
- insert trigger method, null for none (default)- Returns:
- this (fluent interface)
-
withBeforeDeleteTrigger
public KeyCollection.Builder<E> withBeforeDeleteTrigger(java.util.function.Consumer<E> trigger)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify delete trigger.- Overrides:
withBeforeDeleteTrigger
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
trigger
- delete trigger method, null for none (default)- Returns:
- this (fluent interface)
-
withAfterDeleteTrigger
public KeyCollection.Builder<E> withAfterDeleteTrigger(java.util.function.Consumer<E> trigger)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify delete trigger.- Overrides:
withAfterDeleteTrigger
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
trigger
- delete trigger method, null for none (default)- Returns:
- this (fluent interface)
-
withCapacity
public KeyCollection.Builder<E> withCapacity(int capacity)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify initial capacity.- Overrides:
withCapacity
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
capacity
- initial capacity- Returns:
- this (fluent interface)
-
withContent
public KeyCollection.Builder<E> withContent(java.util.Collection<? extends E> elements)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify elements added to the collection upon creation.- Overrides:
withContent
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
elements
- initial elements- Returns:
- this (fluent interface)
-
withContent
public KeyCollection.Builder<E> withContent(E... elements)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify elements added to the collection upon creation.- Overrides:
withContent
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
elements
- initial elements- Returns:
- this (fluent interface)
-
withMaxSize
public KeyCollection.Builder<E> withMaxSize(int maxSize)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify maximum size of collection. If an attempt is made to add more elements, an exception is thrown.- Overrides:
withMaxSize
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
maxSize
- maximum size- Returns:
- this (fluent interface)
-
withSetBehavior
public KeyCollection.Builder<E> withSetBehavior(boolean setBehavior)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specifies that the collection behaves like aSet
on adding elements, i.e. if an element cannot be added due to duplicate or other constraints, no exception is thrown.- Overrides:
withSetBehavior
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
setBehavior
- true to define set behavior (default is false)- Returns:
- this (fluent interface)
-
withElemCount
public KeyCollection.Builder<E> withElemCount(boolean count)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specifies that the collection only counts the number of occurrences of equal elements, but does not store the elements themselves.- Overrides:
withElemCount
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
count
- true to count only number of occurrences (default is false)- Returns:
- this (fluent interface)
-
withElemSet
public KeyCollection.Builder<E> withElemSet()
Add element map (with ident mapper).Note that a
KeyCollection
always has an element set, so this call is not necessary.- Overrides:
withElemSet
in classKeyCollectionImpl.BuilderImpl<E>
- Returns:
- this (fluent interface)
-
withOrderByElem
public KeyCollection.Builder<E> withOrderByElem(boolean orderBy)
Description copied from class:KeyCollectionImpl.BuilderImpl
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.- Overrides:
withOrderByElem
in classKeyCollectionImpl.BuilderImpl<E>
- 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)
-
withElemNull
public KeyCollection.Builder<E> withElemNull(boolean allowNull)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specifies whether null elements are allowed or not. A null element will have null keys. This method does implicitly create an element set, where asKeyCollectionImpl.BuilderImpl.withNull(boolean)
does not.- Overrides:
withElemNull
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
allowNull
- true to allow null elements, false to disallow (default is true)- Returns:
- this (fluent interfaces)
-
withElemDuplicates
public KeyCollection.Builder<E> withElemDuplicates(boolean allowDuplicates)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify whether duplicates are allowed or not. This method does implicitly create an element set.- Overrides:
withElemDuplicates
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
allowDuplicates
- true to allow duplicates (default is true)- Returns:
- this (fluent interfaces)
-
withElemDuplicates
public KeyCollection.Builder<E> withElemDuplicates(boolean allowDuplicates, boolean allowDuplicatesNull)
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify whether duplicates are allowed or not. This method does implicitly create an element set.- Overrides:
withElemDuplicates
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
allowDuplicates
- true to allow duplicates (default is true)allowDuplicatesNull
- true to allow duplicate null values (default is true)- Returns:
- this (fluent interfaces)
-
withElemSort
public KeyCollection.Builder<E> withElemSort(boolean sort)
Description copied from class:KeyCollectionImpl.BuilderImpl
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.- Overrides:
withElemSort
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
sort
- true to sorted, false for unsorted (default is false)- Returns:
- this (fluent interface)
-
withElemSort
public KeyCollection.Builder<E> withElemSort(java.util.Comparator<? super E> comparator)
Description copied from class:KeyCollectionImpl.BuilderImpl
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.- Overrides:
withElemSort
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
comparator
- comparator to use for sorting (null for natural comparator)- Returns:
- this (fluent interface)
-
withElemSort
public KeyCollection.Builder<E> withElemSort(java.util.Comparator<? super E> comparator, boolean sortNullsFirst)
Description copied from class:KeyCollectionImpl.BuilderImpl
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.- Overrides:
withElemSort
in classKeyCollectionImpl.BuilderImpl<E>
- Parameters:
comparator
- comparator to use for sortingsortNullsFirst
- true to sort null values first, false for last- Returns:
- this (fluent interface)
-
withPrimaryElem
public KeyCollection.Builder<E> withPrimaryElem()
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify the element to be a primary key. This is identical to callingwithElemNull(false) and withElemDuplicates(false)
.- Overrides:
withPrimaryElem
in classKeyCollectionImpl.BuilderImpl<E>
- Returns:
- this (fluent interface)
-
withUniqueElem
public KeyCollection.Builder<E> withUniqueElem()
Description copied from class:KeyCollectionImpl.BuilderImpl
Specify the element to be a unique key. This is identical to callingwithElemNull(true) and withElemDuplicates(false, true)
.- Overrides:
withUniqueElem
in classKeyCollectionImpl.BuilderImpl<E>
- Returns:
- this (fluent interface)
-
-