Class BreakableSequencedCollection<E>
- Type Parameters:
E
- The elements type for theSequencedCollection
.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,SequencedCollection<E>
,Breakable
,SupportedMethods
- Direct Known Subclasses:
BreakableList
A sequenced 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
, BreakableSpliterator
, and
BreakableCollection
classes. Any iterator or spliterator breaks that are added to this collection 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 BreakableSequencedCollection
,
but will not have any impact on how it functions.
Builder methods are provided to make declaring a broken sequenced collection easier, for example:
BreakableSequencedCollection<Integer> broken = Breakables.buildSequencedCollection(1, 2)
.withBreak(ADD_FIRST_ADDS_TO_END)
.build();
- Since:
- 1.0.0
- Author:
- evanbergstrom
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The builder for BreakableCollection objects.Nested classes/interfaces inherited from class org.soliscode.test.breakable.BreakableCollection
BreakableCollection.AbstractBuilder<B extends BreakableCollection.AbstractBuilder<B,
C, E>, C extends BreakableCollection<E>, E>, BreakableCollection.WithProvider<E> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Break
The addFirst method adds the element to the end of the collection.static final Break
The addFirst method does not add an element.static final Break
The addLast method adds the element to the front of the collection.static final Break
The addLast method does not add an element.static final Break
ThegetFirst
method always throws aNoSuchElementException
static final Break
ThegetFirst
method returns anull
value.static final Break
ThegetFirst
method returns the second element.static final Break
ThegetLast
method always throws aNoSuchElementException
static final Break
ThegetLast
method returns anull
value.static final Break
ThegetLast
method returns the second element.static final Break
The removeFirst method always throws aNoSuchElement
exception.static final Break
The removeFirst method does not remove the first element.static final Break
The removeFirst method returnsnull
static final Break
The removeLast method always throws aNoSuchElement
exception.static final Break
The removeLast method does not remove the last element.static final Break
The removeLast method returnsnull
static final Break
The reversed method does not reverse the collection.static final Break
The reversed method modifies the collection.Fields inherited from class org.soliscode.test.breakable.BreakableCollection
ADD_ALL_ALWAYS_RETURNS_FALSE, ADD_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE, ADD_ALL_ALWAYS_RETURNS_TRUE, ADD_ALL_DOES_NOT_ADD_ANY_ELEMENTS, ADD_ALL_SKIPS_FIRST_ELEMENT, ADD_ALL_SKIPS_LAST_ELEMENT, ADD_ALWAYS_RETURNS_FALSE, ADD_ALWAYS_RETURNS_OPPOSITE_VALUE, ADD_ALWAYS_RETURNS_TRUE, ADD_DOES_NOT_ADD_ELEMENT, CLEAR_DOES_NOT_REMOVE_ANY_ELEMENTS, CLEAR_SKIPS_FIRST_ELEMENT, CLEAR_SKIPS_LAST_ELEMENT, CONTAINS_ALL_ALWAYS_RETURNS_FALSE, CONTAINS_ALL_ALWAYS_RETURNS_TRUE, CONTAINS_ALL_RETURNS_OPPOSITE_VALUE, CONTAINS_ALWAYS_RETURNS_FALSE, CONTAINS_ALWAYS_RETURNS_TRUE, CONTAINS_RETURNS_OPPOSITE_VALUE, IS_EMPTY_ALWAYS_RETURNS_FALSE, IS_EMPTY_ALWAYS_RETURNS_TRUE, IS_EMPTY_RETURNS_OPPOSITE_VALUE, REMOVE_ALL_ALWAYS_RETURNS_FALSE, REMOVE_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE, REMOVE_ALL_ALWAYS_RETURNS_TRUE, REMOVE_ALL_DOES_NOT_REMOVE_ANY_ELEMENTS, REMOVE_ALL_SKIPS_FIRST_ELEMENT, REMOVE_ALL_SKIPS_LAST_ELEMENT, REMOVE_ALWAYS_RETURNS_FALSE, REMOVE_ALWAYS_RETURNS_OPPOSITE_VALUE, REMOVE_ALWAYS_RETURNS_TRUE, REMOVE_DOES_NOT_REMOVE_ELEMENT, REMOVE_IF_ALWAYS_RETURNS_FALSE, REMOVE_IF_ALWAYS_RETURNS_OPPOSITE_VALUE, REMOVE_IF_ALWAYS_RETURNS_TRUE, REMOVE_IF_DOES_NOT_REMOVE_ANY_ELEMENTS, REMOVE_IF_SKIPS_FIRST_ELEMENT, REMOVE_IF_SKIPS_LAST_ELEMENT, RETAIN_ALL_ALWAYS_RETURNS_FALSE, RETAIN_ALL_ALWAYS_RETURNS_OPPOSITE_VALUE, RETAIN_ALL_ALWAYS_RETURNS_TRUE, RETAIN_ALL_DOES_NOT_RETAIN_ANY_ELEMENTS, RETAIN_ALL_SKIPS_FIRST_ELEMENT, RETAIN_ALL_SKIPS_LAST_ELEMENT, SIZE_ALWAYS_RETURNS_CONSTANT_VALUE, SIZE_ALWAYS_RETURNS_ZERO, TO_ARRAY_MISSING_FIRST_ELEMENT, TO_ARRAY_MISSING_LAST_ELEMENT, TO_ARRAY_RETURNS_EMPTY_ARRAY, TO_ARRAY_RETURNS_NULL, TO_ARRAY_STORE_DOES_NOT_COPY_ELEMENTS, TO_ARRAY_STORE_MISSING_FIRST_ELEMENT, TO_ARRAY_STORE_MISSING_LAST_ELEMENT, TO_ARRAY_STORE_RETURNS_EMPTY_ARRAY, TO_ARRAY_STORE_RETURNS_NULL
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 sequenced collection that has no breaks.BreakableSequencedCollection
(@NotNull List<E> collection) Creates a breakable iterable from an iterable.BreakableSequencedCollection
(@NotNull List<E> c, @NotNull Collection<Break> breaks, int characteristics) Creates aBreakableSequencedCollection
from en existing collection and specifying the breaks and collection characteristics.BreakableSequencedCollection
(@NotNull BreakableSequencedCollection<E> other) Creates a breakable sequenced collection from an existing instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Implements the addFirst method from theSequencedCollection
interface.void
Implements the addLast method from theSequencedCollection
interface.getFirst()
Implements the getFirst method from theSequencedCollection
interface.getLast()
Implements the getLast method from theSequencedCollection
interface.Implements the removeFirst method from theSequencedCollection
interface.Implements the removeLast method from theSequencedCollection
interface.reversed()
Implements the reversed method from theSequencedCollection
interface.Methods inherited from class org.soliscode.test.breakable.BreakableCollection
add, addAll, checkArgument, checkNewElement, clear, collectionProvider, collectionProvider, contains, containsAll, isEmpty, permitsDuplicates, permitsIncompatibleTypes, permitsNulls, remove, removeAll, removeIf, retainAll, setPermitsDuplicates, setPermitsIncompatibleTypes, setPermitsNulls, size, toArray, toArray, unbroken
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
-
Field Details
-
ADD_FIRST_DOES_NOT_ADD_ELEMENT
-
ADD_FIRST_ADDS_TO_END
-
ADD_LAST_DOES_NOT_ADD_ELEMENT
-
ADD_LAST_ADDS_TO_FRONT
-
GET_FIRST_RETURNS_NULL
ThegetFirst
method returns anull
value.- See Also:
-
GET_FIRST_ALWAYS_THROWS
ThegetFirst
method always throws aNoSuchElementException
- See Also:
-
GET_FIRST_SKIPS_FIRST_ELEMENT
ThegetFirst
method returns the second element.- See Also:
-
GET_LAST_RETURNS_NULL
-
GET_LAST_ALWAYS_THROWS
ThegetLast
method always throws aNoSuchElementException
- See Also:
-
GET_LAST_SKIPS_LAST_ELEMENT
ThegetLast
method returns the second element.- See Also:
-
REMOVE_FIRST_DOES_NOT_REMOVE_ELEMENT
The removeFirst method does not remove the first element.- See Also:
-
REMOVE_FIRST_RETURNS_NULL
-
REMOVE_FIRST_ALWAYS_THROWS
The removeFirst method always throws aNoSuchElement
exception.- See Also:
-
REMOVE_LAST_DOES_NOT_REMOVE_ELEMENT
The removeLast method does not remove the last element.- See Also:
-
REMOVE_LAST_RETURNS_NULL
-
REMOVE_LAST_ALWAYS_THROWS
The removeLast method always throws aNoSuchElement
exception.- See Also:
-
REVERSED_DOES_NOT_REVERSE_COLLECTION
-
REVERSED_MODIFIES_THE_COLLECTION
-
-
Constructor Details
-
BreakableSequencedCollection
public BreakableSequencedCollection()Creates an empty sequenced collection that has no breaks. -
BreakableSequencedCollection
Creates a breakable sequenced collection from an existing instance.- Parameters:
other
- the breakable collection to copy.
-
BreakableSequencedCollection
-
BreakableSequencedCollection
public BreakableSequencedCollection(@NotNull @NotNull List<E> c, @NotNull @NotNull Collection<Break> breaks, int characteristics) Creates aBreakableSequencedCollection
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
-
reversed
Implements the reversed method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- REVERSED_DOES_NOT_REVERSE_COLLECTION
- REVERSED_MODIFIES_THE_COLLECTION
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.REVERSED_DOES_NOT_REVERSE_COLLECTION) .build();
- Specified by:
reversed
in interfaceSequencedCollection<E>
- Returns:
- a collection with the elements in the reverse order.
- See Also:
-
addFirst
Implements the addFirst method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- ADD_FIRST_DOES_NOT_ADD_ELEMENT
- ADD_FIRST_ADDS_TO_END
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.ADD_FIRST_DOES_NOT_ADD_ELEMENT) .build();
- Specified by:
addFirst
in interfaceSequencedCollection<E>
- Throws:
UnsupportedOperationException
- if this method is not supportedNullPointerException
- if the element is null and this collection does not permit null elements.- See Also:
-
addLast
Implements the addLast method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- ADD_LAST_DOES_NOT_ADD_ELEMENT
- ADD_LAST_ADDS_TO_FRONT
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.ADD_LAST_DOES_NOT_ADD_ELEMENT) .build();
- Specified by:
addLast
in interfaceSequencedCollection<E>
- Throws:
UnsupportedOperationException
- if this method is not supportedNullPointerException
- if the element is null and this collection does not permit null elements.- See Also:
-
getFirst
Implements the getFirst method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- GET_FIRST_RETURNS_NULL
- GET_FIRST_ALWAYS_THROWS
- GET_FIRST_SKIPS_FIRST_ELEMENT
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.GET_FIRST_RETURNS_NULL) .build();
- Specified by:
getFirst
in interfaceSequencedCollection<E>
- Throws:
UnsupportedOperationException
- if this method is not supportedNoSuchElementException
- if this collection is empty- See Also:
-
getLast
Implements the getLast method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- GET_LAST_RETURNS_NULL
- GET_LAST_ALWAYS_THROWS
- GET_LAST_SKIPS_FIRST_ELEMENT
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.GET_LAST_RETURNS_NULL) .build();
- Specified by:
getLast
in interfaceSequencedCollection<E>
- Throws:
UnsupportedOperationException
- if this method is not supported- See Also:
-
removeFirst
Implements the removeFirst method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- REMOVE_FIRST_DOES_NOT_REMOVE_ELEMENT
- REMOVE_FIRST_RETURNS_NULL
- REMOVE_FIRST_ALWAYS_THROWS
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.REMOVE_FIRST_RETURNS_NULL) .build();
- Specified by:
removeFirst
in interfaceSequencedCollection<E>
- Throws:
UnsupportedOperationException
- if this method is not supported- See Also:
-
removeLast
Implements the removeLast method from the
SequencedCollection
interface. This method can be broken using the following collection breaks:- REMOVE_LAST_DOES_NOT_REMOVE_ELEMENT
- REMOVE_LAST_RETURNS_NULL
- REMOVE_LAST_ALWAYS_THROWS
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakables.buildSequencedCollection(1,2,3,4,5) .withBreak(CollectionBreaks.REMOVE_LAST_RETURNS_NULL) .build();
- Specified by:
removeLast
in interfaceSequencedCollection<E>
- Throws:
UnsupportedOperationException
- if this method is not supported- See Also:
-