Class BreakableIterable<E>
- Type Parameters:
E
- The elements type for theIterable
.
- All Implemented Interfaces:
Iterable<E>
,Breakable
,SupportedMethods
- Direct Known Subclasses:
BreakableCollection
An iterable 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 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 BreakableIterable
, but will
not have any impact on how it functions.
Builder
Builder methods are provided to make declaring a broken collection easier, for example:
BreakableIterator<Integer> broken = Breakable.iterableOf(1, 2)
.addBreak(FOR_EACH_DOES_NOT_CALL_ACTION)
.setCharacteristics(ORDERED | SIZED | SUBSIZED)
.build();
- Since:
- 1.0
- Author:
- evanbergstrom
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
BreakableIterable.AbstractBuilder<B extends BreakableIterable.AbstractBuilder<B,
C, E>, C extends BreakableIterable<E>, E> Utility class for use by subclasses ofBreakableIterator
to make implementing a builder class easier.static class
Builder class forBreakableIterator
.static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
static final Break
The methodforEach
does not call the action on any of the elements.static final Break
TheforEach
method does not call the action on the first element.static final Break
The methodforEach
does not call the action on the last element.static final Break
The methodforEach
throws the wrong exception when passes anull
action argument. -
Constructor Summary
ConstructorsConstructorDescriptionCreates and empty breakable iterable with no breaks.BreakableIterable
(@NotNull Iterable<E> i, @NotNull Collection<Break> breaks, int characteristics) Creates a breakable iterable from another iterable with a set of breaks and characteristics specified by the other arguments.BreakableIterable
(@NotNull Collection<E> collection) Creates a breakable iterable from an iterable.BreakableIterable
(@NotNull Set<Break> breaks) Creates a breakable iterable with a set of breaksBreakableIterable
(@NotNull BreakableIterable<E> other) Creates a breakable iterable from an existing instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
int
hashCode()
static <E> @NotNull CollectionProvider
<E, BreakableIterable<E>> iterableProvider
(@NotNull ObjectProvider<E> elementProvider) static <E> @NotNull CollectionProvider
<E, BreakableIterable<E>> iterableProvider
(@NotNull ObjectProvider<E> elementProvider, @NotNull Set<Break> breaks) iterator()
toString()
unbroken()
returns the elements as an unbroken instance of `Iterable'Methods inherited from class org.soliscode.test.breakable.AbstractBreakable
addBreaks, breaks, hasBreak
Methods inherited from class org.soliscode.test.OptionalMethodSupport
doesNotSupportMethod, supportsMethod, unsupportedMethods
-
Field Details
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY- See Also:
-
FOR_EACH_DOES_NOT_CALL_ACTION
The methodforEach
does not call the action on any of the elements.- See Also:
-
FOR_EACH_SKIPS_FIRST_ELEMENT
TheforEach
method does not call the action on the first element.- See Also:
-
FOR_EACH_SKIPS_LAST_ELEMENT
The methodforEach
does not call the action on the last element.- See Also:
-
FOR_EACH_THROWS_WRONG_EXCEPTION_FOR_NULL_ARGUMENT
The methodforEach
throws the wrong exception when passes anull
action argument.- See Also:
-
-
Constructor Details
-
BreakableIterable
public BreakableIterable()Creates and empty breakable iterable with no breaks. The spliterator for this iterable will have no characteristics set. -
BreakableIterable
Creates a breakable iterable from an existing instance.- Parameters:
other
- the breakable iterator to copy.
-
BreakableIterable
Creates a breakable iterable from an iterable.- Parameters:
collection
- the iterator to use for the elements.
-
BreakableIterable
-
BreakableIterable
public BreakableIterable(@NotNull @NotNull Iterable<E> i, @NotNull @NotNull Collection<Break> breaks, int characteristics) Creates a breakable iterable from another iterable with a set of breaks and characteristics specified by the other arguments.- Parameters:
i
- the iterable to use for the elements.breaks
- the set of breaks to include.characteristics
- the characteristics of the iterable.
-
-
Method Details
-
equals
-
hashCode
-
toString
-
iterator
Implements the iterator method from the
Iterable
interface.#Breaks This method can be broken using any of the breaks found in the
BreakableIterator
class.A collection that has any of these breaks can be constructed using the builder:
Iterable<Integer> iterable = Breakable.iterableOf(1,2,3,4,5) .withBreak(BreakableIterator.ITERATOR_IS_ALWAYS_EMPTY) .build();
-
forEach
Implements the forEach method from the
Iterable
interface. This method can be broken using the following collection breaks:- FOR_EACH_DOES_NOT_CALL_ACTION
- FOR_EACH_SKIPS_FIRST_ELEMENT
- FOR_EACH_SKIPS_LAST_ELEMENT
- FOR_EACH_THROWS_WRONG_EXCEPTION_FOR_NULL_ARGUMENT
A collection that has any of these breaks can be constructed using the builder:
Collection<Integer> collection = Breakable.iterableOf(1,2,3,4,5) .withBreak(FOR_EACH_DOES_NOT_CALL_ACTION) .build();
- Specified by:
forEach
in interfaceIterable<E>
- Parameters:
action
- The action to be performed for each element- Throws:
NullPointerException
- if the specified action is null
-
spliterator
Implements the iterator method from the
Iterable
interface. This method can be broken using the following collection breaks:#Breaks This method can be broken using any of the breaks found in the
BreakableSpliterator
class.A iterable that has any of these breaks can be constructed using the builder:
Iterable<Integer> iterable = Breakable.iterableOf() .addElements(1,2,3,4,5) .withBreak(SPLITERATOR_IS_ALWAYS_EMPTY) .build();
- Specified by:
spliterator
in interfaceIterable<E>
- Returns:
- a
Spliterator
over the elements in this collection.Ø
-
unbroken
-
iterableProvider
@NotNull public static <E> @NotNull CollectionProvider<E,BreakableIterable<E>> iterableProvider(@NotNull @NotNull ObjectProvider<E> elementProvider) -
iterableProvider
@NotNull public static <E> @NotNull CollectionProvider<E,BreakableIterable<E>> iterableProvider(@NotNull @NotNull ObjectProvider<E> elementProvider, @NotNull @NotNull Set<Break> breaks)
-