Class BreakableCollection<E>
- Type Parameters:
E
- The elements type for theCollection
.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Breakable
,SupportedMethods
- Direct Known Subclasses:
BreakableSequencedCollection
A collection that can be broken in well-defined ways in order to test collection utilities or testing classes.
Breaks
The breaks that are supported for this class are listed in the description of the method that they impact.
In addition it supports the breaks in the BreakableIterable
, BreakableIterator
, and BreakableSpliterator
classes. Any iterator or spliterator breaks that are added to this iterable will be passes along to iterator or
spliterator instances that are created.
Any breaks that are not listed in the supported classes can be added to an instance of BreakableCollection
, but
will not have any impact on how it functions.
Builder methods are provided to make declaring a broken collection easier, for example:
BreakableCollection<Integer> broken = Breakables.buildCollection.of(1, 2)
.withBreak(CollectionBreaks,EMPTY_ALWAYS_RETURNS_TRUE)
.build();
- Since:
- 1.0.0
- Author:
- evanbergstrom
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
BreakableCollection.AbstractBuilder<B extends BreakableCollection.AbstractBuilder<B,
C, E>, C extends BreakableCollection<E>, E> Utility class for implementing builders for subclasses of BreakableCollection.static class
The builder for BreakableCollection objects.static interface
Mixin interface that adds an implementation of theprovider()
method that provides instances ofBreakableCollection
that do not have any breaks applied. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Break
The addAll method always return a result offalse
, even if the element is added.static final Break
The addAll method always returns the opposite of the appropriate result.static final Break
The addAll method always return a result oftrue
, even if the element is not added.static final Break
The addAll method will not add any elements to the collectionstatic final Break
The addAll method skips the first element to be added.static final Break
The addAll method skips the last element to be added.static final Break
The add method always return a result offalse
, even if the element is added.static final Break
The add method always returns the opposite of the appropriate result.static final Break
The add method always return a result oftrue
, even if the element is not added.static final Break
The add method does not add an element to the collectionstatic final Break
The clear method doers not remove any elements,static final Break
The clear method skips the first element,static final Break
The clear method skips the last element,static final Break
ThecontainsAll
method will always return a false.static final Break
ThecontainsAll
method will always return a true.static final Break
ThecontainsAll
method will return the opposite value.static final Break
Thecontains
method will always return a false.static final Break
Thecontains
method will always return a true.static final Break
Thecontains
method will return the opposite value.static final Break
TheisEmpty
method will always return a false.static final Break
TheisEmpty
method will always return a true.static final Break
TheisEmpty
method will return the opposite value.static final Break
The removeAll method always return a result offalse
, even any of the elements are removed.static final Break
The removeAll method always returns the opposite of the appropriate result.static final Break
The removeAll method always return a result oftrue
, even if the element is not removed.static final Break
The removeAll method will not remove any elements to the collectionstatic final Break
The removeAll method skips the first element to be removed.static final Break
The removeAll method skips the last element to be removed.static final Break
Theremove
method always return a result offalse
, even if the element is removed.static final Break
Theremove
method always returns the opposite of the appropriate result.static final Break
Theremove
method always return a result oftrue
, even if the element is not removed.static final Break
Theremove
method will not remove an element to the collectionstatic final Break
The removeIf method always return a result offalse
, even any of the elements are removed.static final Break
The removeIf method always returns the opposite of the appropriate result.static final Break
The removeIf method always return a result oftrue
, even if the element is not removed.static final Break
The removeIf method will not remove any elements to the collectionstatic final Break
The removeIf method skips the first element to be removed.static final Break
The removeIf method skips the last element to be removed.static final Break
The retainAll method always return a result offalse
, even the collection is modifiedstatic final Break
The retainAll method always returns the opposite of the appropriate result.static final Break
The retainAll method always return a result oftrue
, even if the collection is not modified.static final Break
The retainAll method will not retain any elements to the collectionstatic final Break
The retainAll method skips the first element to be retained.static final Break
The retainAll method skips the last element to be retained.static final Break
Thesize
method will always return a constant value.static final Break
Thesize
method will always return zero.static final Break
The 'toArray' method will always return an array missing the first elementstatic final Break
The 'toArray' method will always return an array missing the last elementstatic final Break
The 'toArray' method will always return an empty arraystatic final Break
The 'toArray' method will always returnnull
static final Break
The 'toArray([])' method does not copy the elements into the arraystatic final Break
The 'toArray' method will always return an array missing the first elementstatic final Break
The 'toArray' method will always return an array missing the last elementstatic final Break
The 'toArray' method will always return an empty arraystatic final Break
The 'toArray' method will always returnnull
Fields inherited from class org.soliscode.test.breakable.BreakableIterable
FOR_EACH_DOES_NOT_CALL_ACTION, FOR_EACH_SKIPS_FIRST_ELEMENT, FOR_EACH_SKIPS_LAST_ELEMENT, FOR_EACH_THROWS_WRONG_EXCEPTION_FOR_NULL_ARGUMENT
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty collection that has no breaks.BreakableCollection
(@NotNull Collection<E> collection) Creates a breakable iterable from an iterable.BreakableCollection
(@NotNull Collection<E> c, @NotNull Collection<Break> breaks, int characteristics) Creates aBreakableCollection
from en existing collection and specifying the breaks and collection characteristics.BreakableCollection
(@NotNull BreakableCollection<E> other) Creates a breakable collection from an existing instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Implements the add method from theCollection
interface.boolean
addAll
(@NotNull Collection<? extends E> c) Implements the addAll method from theCollection
interface.protected void
checkArgument
(Object arg) Checks that the argument is valid for this collection.protected boolean
checkNewElement
(E e) Checks that the element is valid to add to this collection.void
clear()
Implements the clear method from theCollection
interface.static <E> @NotNull CollectionProvider
<E, BreakableCollection<E>> collectionProvider
(@NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances of BreakableCollection, given an element provider.static <E> @NotNull CollectionProvider
<E, BreakableCollection<E>> collectionProvider
(@NotNull ObjectProvider<E> elementProvider, @NotNull Set<Break> breaks) Creates a collection provider for instances ofBreakableCollection
, given an element provider and a set of breaks.boolean
Implements the contains method from theCollection
interface.boolean
containsAll
(@NotNull Collection<?> c) Implements the containsAll method from theCollection
interface.boolean
isEmpty()
Implements the isEmpty method from theCollection
interface.boolean
Indicates if the collection permits duplicate elements.boolean
Indicates if the collection permits elements with incompatible types as arguments.boolean
Indicates if the collection permits null values as elements.boolean
Implements the remove method from theCollection
interface.boolean
removeAll
(@NotNull Collection<?> c) Implements the removeAll method from theCollection
interface.boolean
Implements the removeIf method from theCollection
interface.boolean
retainAll
(@NotNull Collection<?> c) Implements the retainAll method from theCollection
interface.void
setPermitsDuplicates
(boolean permitsDuplicates) Sets how the collection handles duplicate elements.void
setPermitsIncompatibleTypes
(boolean permitsIncompatibleTypes) Sets how the collection handles elements with incompatible types as arguments.void
setPermitsNulls
(boolean permitsNulls) Sets how the collection handlesnull
elements.int
size()
Implements the size method from theCollection
interface.Object[]
toArray()
Implements the toArray method from theCollection
interface.<T> T @NotNull []
toArray
(T @NotNull [] a) Implements the toArray method from theCollection
interface.@NotNull Collection
<E> unbroken()
returns the elements as an unbroken instance of `Collection'Methods inherited from class org.soliscode.test.breakable.BreakableIterable
equals, forEach, hashCode, iterableProvider, iterableProvider, iterator, spliterator, toString
Methods inherited from class org.soliscode.test.breakable.AbstractBreakable
addBreaks, breaks, hasBreak
Methods inherited from class org.soliscode.test.OptionalMethodSupport
doesNotSupportMethod, supportsMethod, unsupportedMethods
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, iterator, parallelStream, spliterator, stream, toArray
-
Field Details
-
ADD_DOES_NOT_ADD_ELEMENT
-
ADD_ALWAYS_RETURNS_TRUE
-
ADD_ALWAYS_RETURNS_FALSE
-
ADD_ALWAYS_RETURNS_OPPOSITE_VALUE
-
ADD_ALL_DOES_NOT_ADD_ANY_ELEMENTS
-
ADD_ALL_ALWAYS_RETURNS_TRUE
-
ADD_ALL_ALWAYS_RETURNS_FALSE
-
ADD_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE
-
ADD_ALL_SKIPS_FIRST_ELEMENT
-
ADD_ALL_SKIPS_LAST_ELEMENT
-
CLEAR_DOES_NOT_REMOVE_ANY_ELEMENTS
-
CLEAR_SKIPS_FIRST_ELEMENT
-
CLEAR_SKIPS_LAST_ELEMENT
-
CONTAINS_ALWAYS_RETURNS_TRUE
Thecontains
method will always return a true.- See Also:
-
CONTAINS_ALWAYS_RETURNS_FALSE
Thecontains
method will always return a false.- See Also:
-
CONTAINS_RETURNS_OPPOSITE_VALUE
Thecontains
method will return the opposite value.- See Also:
-
CONTAINS_ALL_ALWAYS_RETURNS_TRUE
ThecontainsAll
method will always return a true.- See Also:
-
CONTAINS_ALL_ALWAYS_RETURNS_FALSE
ThecontainsAll
method will always return a false.- See Also:
-
CONTAINS_ALL_RETURNS_OPPOSITE_VALUE
ThecontainsAll
method will return the opposite value.- See Also:
-
IS_EMPTY_ALWAYS_RETURNS_TRUE
TheisEmpty
method will always return a true.- See Also:
-
IS_EMPTY_ALWAYS_RETURNS_FALSE
TheisEmpty
method will always return a false.- See Also:
-
IS_EMPTY_RETURNS_OPPOSITE_VALUE
TheisEmpty
method will return the opposite value.- See Also:
-
REMOVE_DOES_NOT_REMOVE_ELEMENT
Theremove
method will not remove an element to the collection- See Also:
-
REMOVE_ALWAYS_RETURNS_TRUE
Theremove
method always return a result oftrue
, even if the element is not removed.- See Also:
-
REMOVE_ALWAYS_RETURNS_FALSE
Theremove
method always return a result offalse
, even if the element is removed.- See Also:
-
REMOVE_ALWAYS_RETURNS_OPPOSITE_VALUE
Theremove
method always returns the opposite of the appropriate result.- See Also:
-
REMOVE_ALL_DOES_NOT_REMOVE_ANY_ELEMENTS
-
REMOVE_ALL_ALWAYS_RETURNS_TRUE
-
REMOVE_ALL_ALWAYS_RETURNS_FALSE
-
REMOVE_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE
-
REMOVE_ALL_SKIPS_FIRST_ELEMENT
-
REMOVE_ALL_SKIPS_LAST_ELEMENT
-
REMOVE_IF_DOES_NOT_REMOVE_ANY_ELEMENTS
-
REMOVE_IF_ALWAYS_RETURNS_TRUE
-
REMOVE_IF_ALWAYS_RETURNS_FALSE
-
REMOVE_IF_ALWAYS_RETURNS_OPPOSITE_VALUE
-
REMOVE_IF_SKIPS_FIRST_ELEMENT
-
REMOVE_IF_SKIPS_LAST_ELEMENT
-
RETAIN_ALL_DOES_NOT_RETAIN_ANY_ELEMENTS
-
RETAIN_ALL_ALWAYS_RETURNS_TRUE
-
RETAIN_ALL_ALWAYS_RETURNS_FALSE
-
RETAIN_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE
-
RETAIN_ALL_SKIPS_FIRST_ELEMENT
-
RETAIN_ALL_SKIPS_LAST_ELEMENT
-
SIZE_ALWAYS_RETURNS_ZERO
Thesize
method will always return zero.- See Also:
-
SIZE_ALWAYS_RETURNS_CONSTANT_VALUE
Thesize
method will always return a constant value.- See Also:
-
TO_ARRAY_RETURNS_EMPTY_ARRAY
The 'toArray' method will always return an empty array- See Also:
-
TO_ARRAY_RETURNS_NULL
The 'toArray' method will always returnnull
- See Also:
-
TO_ARRAY_MISSING_FIRST_ELEMENT
The 'toArray' method will always return an array missing the first element- See Also:
-
TO_ARRAY_MISSING_LAST_ELEMENT
The 'toArray' method will always return an array missing the last element- See Also:
-
TO_ARRAY_STORE_DOES_NOT_COPY_ELEMENTS
The 'toArray([])' method does not copy the elements into the array- See Also:
-
TO_ARRAY_STORE_RETURNS_EMPTY_ARRAY
The 'toArray' method will always return an empty array- See Also:
-
TO_ARRAY_STORE_RETURNS_NULL
The 'toArray' method will always returnnull
- See Also:
-
TO_ARRAY_STORE_MISSING_FIRST_ELEMENT
The 'toArray' method will always return an array missing the first element- See Also:
-
TO_ARRAY_STORE_MISSING_LAST_ELEMENT
The 'toArray' method will always return an array missing the last element- See Also:
-
-
Constructor Details
-
BreakableCollection
public BreakableCollection()Creates an empty collection that has no breaks. -
BreakableCollection
Creates a breakable collection from an existing instance.- Parameters:
other
- the breakable collection to copy.
-
BreakableCollection
Creates a breakable iterable from an iterable.- Parameters:
collection
- the iterator to use for the elements.
-
BreakableCollection
public BreakableCollection(@NotNull @NotNull Collection<E> c, @NotNull @NotNull Collection<Break> breaks, int characteristics) Creates aBreakableCollection
from en existing collection and specifying the breaks and collection characteristics. Rather than calling this constructor directly, consider using the builderBreakableCollection.Builder
.- Parameters:
c
- the initial elements for the breakable collection.breaks
- the breaks for the collection.characteristics
- the characteristics for the collection.- Throws:
NullPointerException
- if either thec
or thebreaks
parameters are null.
-
-
Method Details
-
permitsNulls
public boolean permitsNulls()Indicates if the collection permits null values as elements.- Returns:
true
if the collection permitsnull
elements,false
if it does not.
-
setPermitsNulls
public void setPermitsNulls(boolean permitsNulls) Sets how the collection handlesnull
elements.- Parameters:
permitsNulls
- specifies if the collection permits null values,true
if null values are permitted andfalse
if they are not.
-
permitsDuplicates
public boolean permitsDuplicates()Indicates if the collection permits duplicate elements.- Returns:
true
if the collection permits duplicate elements,false
if it does not.
-
setPermitsDuplicates
public void setPermitsDuplicates(boolean permitsDuplicates) Sets how the collection handles duplicate elements.- Parameters:
permitsDuplicates
- specifies if the collection permits duplicate values,true
if duplicate values are permitted andfalse
if they are not.
-
permitsIncompatibleTypes
public boolean permitsIncompatibleTypes()Indicates if the collection permits elements with incompatible types as arguments.- Returns:
true
if the collection permits elements with incompatible types,false
if it does not.
-
setPermitsIncompatibleTypes
public void setPermitsIncompatibleTypes(boolean permitsIncompatibleTypes) Sets how the collection handles elements with incompatible types as arguments.- Parameters:
permitsIncompatibleTypes
- specifies if the collection permits elements with incompatible types as arguments,true
if duplicate values are permitted andfalse
if they are not.
-
size
public int size()Implements the size method from the
Collection
interface. This method can be broken using the following collection breaks:A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(SIZE_ALWAYS_RETURNS_ZERO) .build();
- Specified by:
size
in interfaceCollection<E>
- Returns:
- The number of elements in the collection, or a different value if the collection has been broken.
- See Also:
-
isEmpty
public boolean isEmpty()Implements the isEmpty method from the
Collection
interface. This method can be broken using the following collection breaks:A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(IS_EMPTY_RETURNS_OPPOSITE_VALUE) .build();
- Specified by:
isEmpty
in interfaceCollection<E>
- Returns:
- The number of elements in the collection, or a different value if the collection has been broken.
- See Also:
-
contains
Implements the contains method from the
Collection
interface. This method can be broken using the following collection breaks:A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(CONTAINS_ALWAYS_RETURNS_FALSE) .build();
- Specified by:
contains
in interfaceCollection<E>
- Returns:
true
if this collection contains the specified element or false if it does not, or some other value if the collection is broken.- Throws:
NullPointerException
- if the argument isnull
and collection does not supportnull
values.ClassCastException
- if the argument is an incompatible type and the collection does not support incompatible types.- See Also:
-
toArray
Implements the toArray method from the
Collection
interface. This method can be broken using the following collection breaks:- TO_ARRAY_RETURNS_NULL
- TO_ARRAY_RETURNS_EMPTY_ARRAY
- TO_ARRAY_MISSING_FIRST_ELEMENT
- TO_ARRAY_MISSING_LAST_ELEMENT
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(TO_ARRAY_RETURNS_NULL) .build();
- Specified by:
toArray
in interfaceCollection<E>
- Returns:
- An array with the elements from the collection, or some other value if the collection is broken.
- See Also:
-
toArray
public <T> T @NotNull [] toArray(@NotNull T @NotNull [] a) Implements the toArray method from the
Collection
interface. This method can be broken using the following collection breaks:- TO_ARRAY_STORE_RETURNS_NULL
- TO_ARRAY_STORE_DOES_NOT_COPY_ELEMENTS
- TO_ARRAY_STORE_RETURNS_EMPTY_ARRAY
- TO_ARRAY_STORE_MISSING_FIRST_ELEMENT
- TO_ARRAY_STORE_MISSING_LAST_ELEMENT
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(TO_ARRAY_STORE_RETURNS_NULL) .build();
- Specified by:
toArray
in interfaceCollection<E>
- Returns:
- An array with the elements from the collection, or some other value if the collection is broken.
- See Also:
-
add
Implements the add method from the
Collection
interface. This method can be broken using the following collection breaks:- ADD_DOES_NOT_ADD_ELEMENT
- ADD_ALWAYS_RETURNS_TRUE
- ADD_ALWAYS_RETURNS_FALSE
- ADD_ALWAYS_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(ADD_DOES_NOT_ADD_ELEMENT) .build();
This is an optional method of the
Collection
interface. Support for this method can be removed using the optional method identifierCollectionMethods.Add
. A collection that does not support theadd
method can be constructed using the builder:Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .doesNotSupportsMethod(OptionalCollectionMethod.Add) .build();
- Specified by:
add
in interfaceCollection<E>
- Returns:
- 'true' if the element is added, 'false' if it isn't, or possibly a different value if the collection has been broken.
- Throws:
NullPointerException
- if the argument isnull
and collection does not supportnull
values.IllegalArgumentException
- if the argument is already contained in the collections, and it does not support duplicate values.ClassCastException
- if the argument is an incompatible type and the collection does not support incompatible types.UnsupportedOperationException
- if this collection does not support this method.
-
remove
Implements the remove method from the
Collection
interface. This method can be broken using the following collection breaks:- REMOVE_DOES_NOT_REMOVE_ELEMENT
- REMOVE_ALWAYS_RETURNS_TRUE
- REMOVE_ALWAYS_RETURNS_FALSE
- REMOVE_ALWAYS_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = BreakableCollection.of(1,2,3,4,5) .withBreak(REMOVE_DOES_NOT_REMOVE_ELEMENT) .build();
This is an optional method of the
Collection
interface. Support for this method can be removed using the optional method identifierCollectionMethods.Remove
. A collection that does not support theremove
method can be constructed using the builder:Collection<Integer> collection = BreakableCollection.of(1,2,3,4,5) .doesNotSupportsMethod(OptionalCollectionMethod.Remove) .build();
- Specified by:
remove
in interfaceCollection<E>
- Returns:
- 'true' if the element is removed, 'false' if it isn't, or possibly a different value if the collection has been broken.
- Throws:
NullPointerException
- if the argument isnull
and collection does not supportnull
values.ClassCastException
- if the argument is an incompatible type and the collection does not support incompatible types.
-
containsAll
Implements the containsAll method from the
Collection
interface. This method can b broken using the following collection breaks:- CONTAINS_ALL_ALWAYS_RETURNS_TRUE
- CONTAINS_ALL_ALWAYS_RETURNS_FALSE
- CONTAINS_ALL_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(CONTAINS_ALL_ALWAYS_RETURNS_FALSE) .build();
- Specified by:
containsAll
in interfaceCollection<E>
- Returns:
true
if this collection contains the specified elements or false if it does not, or some other value if the collection is broken.- Throws:
NullPointerException
- if the argument contains anull
and collection does not supportnull
values.ClassCastException
- if the argument is contains an incompatible type and the collection does not support incompatible types.- See Also:
-
addAll
Implements the addAll method from the
Collection
interface. This method can be broken using the following collection breaks:- ADD_ALL_DOES_NOT_ADD_ANY_ELEMENTS
- ADD_ALL_SKIPS_FIRST_ELEMENT
- ADD_ALL_SKIPS_LAST_ELEMENT
- ADD_ALL_ALWAYS_RETURNS_TRUE
- ADD_ALL_ALWAYS_RETURNS_FALSE
- ADD_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(ADD_ALL_DOES_NOT_ADD_ANY_ELEMENTS) .build();
This is an optional method of the
Collection
interface. Support for this method can be removed using the optional method identifierCollectionMethods.AddAll
. A collection that does not support theaddAll
method can be constructed using the builder:Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .doesNotSupportsMethod(OptionalCollectionMethod.AddAll) .build();
- Specified by:
addAll
in interfaceCollection<E>
- Returns:
- 'true' if all of the elements are added, 'false' otherwise, or possibly a different value if the collection has been broken.
- Throws:
NullPointerException
- if the argument contains anynull
values and collection does not supportnull
values.ClassCastException
- if the argument contains any elements an incompatible type and the collection does not support incompatible types.UnsupportedOperationException
- if this collection does not support this method.
-
removeAll
Implements the removeAll method from the
Collection
interface. This method can be broken using the following collection breaks:- REMOVE_ALL_DOES_NOT_REMOVE_ANY_ELEMENTS
- REMOVE_ALL_SKIPS_FIRST_ELEMENT
- REMOVE_ALL_SKIPS_LAST_ELEMENT
- REMOVE_ALL_ALWAYS_RETURNS_TRUE
- REMOVE_ALL_ALWAYS_RETURNS_FALSE
- REMOVE_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(REMOVE_ALL_DOES_NOT_ADD_ANY_ELEMENTS) .build();
This is an optional method of the
Collection
interface. Support for this method can be removed using the optional method identifierCollectionMethods.RemoveAll
. A collection that does not support theremoveAll
method can be constructed using the builder:Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .doesNotSupportsMethod(OptionalCollectionMethod.RemoveAll) .build();
- Specified by:
removeAll
in interfaceCollection<E>
- Returns:
- 'true' if all of the elements are removed, 'false' otherwise, or possibly a different value if the collection has been broken.
- Throws:
NullPointerException
- if the argument contains anynull
values and collection does not supportnull
values.ClassCastException
- if the argument contains any elements an incompatible type and the collection does not support incompatible types.UnsupportedOperationException
- if this collection does not support this method.
-
removeIf
Implements the removeIf method from the
Collection
interface. This method can be broken using the following collection breaks:- REMOVE_IF_DOES_NOT_REMOVE_ANY_ELEMENTS
- REMOVE_IF_SKIPS_FIRST_ELEMENT
- REMOVE_IF_SKIPS_LAST_ELEMENT
- REMOVE_IF_ALWAYS_RETURNS_TRUE
- REMOVE_IF_ALWAYS_RETURNS_FALSE
- REMOVE_IF_ALWAYS_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(REMOVE_IF_DOES_NOT_REMOVE_ANY_ELEMENTS) .build();
This is an optional method of the
Collection
interface. Support for this method can be removed using the optional method identifierCollectionMethods.RemoveIf
. A collection that does not support theremoveIf
method can be constructed using the builder:Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .doesNotSupportsMethod(OptionalCollectionMethod.RemoveIf) .build();
- Specified by:
removeIf
in interfaceCollection<E>
- Parameters:
filter
- a predicate which returnstrue
for elements to be removed- Returns:
true
if any elements were removed- Throws:
NullPointerException
- if the specified filter is nullUnsupportedOperationException
- if theremoveIf
operation is not supported by this collection
-
retainAll
Implements the retainAll method from the
Collection
interface. This method can be broken using the following collection breaks:- RETAIN_ALL_DOES_NOT_RETAIN_ANY_ELEMENTS
- RETAIN_ALL_SKIPS_FIRST_ELEMENT
- RETAIN_ALL_SKIPS_LAST_ELEMENT
- RETAIN_ALL_ALWAYS_RETURNS_TRUE
- RETAIN_ALL_ALWAYS_RETURNS_FALSE
- RETAIN_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(RETAIN_ALL_DOES_NOT_ADD_ANY_ELEMENTS) .build();
This is an optional method of the
Collection
interface. Support for this method can be removed using the optional method identifierCollectionMethods.RetainAll
. A collection that does not support theretainAll
method can be constructed using the builder:Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .doesNotSupportsMethod(OptionalCollectionMethod.RetainAll) .build();
- Specified by:
retainAll
in interfaceCollection<E>
- Returns:
- 'true' if the collection is modified, 'false' otherwise, or possibly a different value if the collection has been broken.
- Throws:
NullPointerException
- if the argument contains anynull
values and collection does not supportnull
values.ClassCastException
- if the argument contains any elements an incompatible type and the collection does not support incompatible types.UnsupportedOperationException
- if this collection does not support this method.
-
clear
public void clear()Implements the clear method from the
Collection
interface. This method can be broken using the following collection breaks:A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildCollection(1,2,3,4,5) .withBreak(CLEAR_DOES_NOT_REMOVE_ANY_ELEMENTS) .build();
- Specified by:
clear
in interfaceCollection<E>
- See Also:
-
unbroken
returns the elements as an unbroken instance of `Collection'- Overrides:
unbroken
in classBreakableIterable<E>
- Returns:
- an unbroken collection.
-
checkArgument
Checks that the argument is valid for this collection. This will check that:
- The argument is not null or the collection permits nulls
- The argument is a compatible type or the collection permits incompatible types.
- Parameters:
arg
- the argument to check.- Throws:
NullPointerException
- if the argument is 'null' and the collection does not permit nulls.ClassCastException
- if the argument is not compatible and the collection does not permit incompatible types.
-
checkNewElement
Checks that the element is valid to add to this collection. This will check that the element is not a duplicate, or the collection permits duplicate values.- Parameters:
e
- the element to check.- Throws:
NullPointerException
- if the argument is 'null' and the collection does not permit nulls.ClassCastException
- if the argument is not compatible and the collection does not permit incompatible types.
-
collectionProvider
@NotNull public static <E> @NotNull CollectionProvider<E,BreakableCollection<E>> collectionProvider(@NotNull @NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances of BreakableCollection, given an element provider.- Type Parameters:
E
- the element type.- Parameters:
elementProvider
- the element provider to use.- Returns:
- a collection provider for breakable collections.
-
collectionProvider
@NotNull public static <E> @NotNull CollectionProvider<E,BreakableCollection<E>> collectionProvider(@NotNull @NotNull ObjectProvider<E> elementProvider, @NotNull @NotNull Set<Break> breaks) Creates a collection provider for instances ofBreakableCollection
, given an element provider and a set of breaks.- Type Parameters:
E
- the element type.- Parameters:
elementProvider
- the element provider to use.breaks
- the breaks to apply to each instance ofBreakableCollection
.- Returns:
- a collection provider for breakable collections.
-