Class BreakableSpliterator<E>
- Type Parameters:
E
- the element type.
- All Implemented Interfaces:
Spliterator<E>
,Breakable
,SupportedMethods
An Spliterator 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.
Any breaks that are not listed in this class can be added to an instance of BreakableSpliterator
, but will
not have any impact on how it functions.
- Since:
- 1.0
- Author:
- evanbergstrom
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,
T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Break
Thecharacteristics
method always returns zero (0).static final Break
TheestimateSize
method always returns the max value.static final Break
TheestimateSize
method always returns zero.static final Break
The 'forEachRemaining' method on the spliterator does not call the action.static final Break
ThegetComparator
method always returnnull
.static final Break
ThegetExactSizeIfKnown
method always returns negative one (-1).static final Break
ThehasCharacteristics
method always returnsfalse
.static final Break
ThehasCharacteristics
method always returnstrue
.static final Break
The spliterator always has no elements.static final Break
The spliterator that skips the first element.static final Break
The 'tryAdvance' method always returns false.static final Break
The 'tryAdvance' method always returns true.static final Break
The 'tryAdvance' method on the spliterator does not call the action.static final Break
The 'trySplit' method on the spliterator always returnsnull
.Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
-
Constructor Summary
ConstructorsConstructorDescriptionBreakableSpliterator
(Spliterator<E> iterator, Collection<Break> breaks, int characteristics) Constructs a breakable spliterator from a spliterator that will provide the implementation. -
Method Summary
Modifier and TypeMethodDescriptionint
Implements the characteristics method from theSpliterator
interface.long
Implements the estimateSize method from theSpliterator
interface.void
forEachRemaining
(Consumer<? super E> action) Implements the forEachRemaining method from theSpliterator
interface.Comparator
<? super E> long
Implements the getExactSizeIfKnown method from theSpliterator
interface.boolean
hasCharacteristics
(int characteristics) Implements the hasCharacteristics method from theSpliterator
interface.boolean
tryAdvance
(Consumer<? super E> action) Implements the tryAdvance method from theSpliterator
interface.trySplit()
Implements the forEachRemaining method from theSpliterator
interface.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
-
SPLITERATOR_IS_ALWAYS_EMPTY
The spliterator always has no elements. -
SPLITERATOR_SKIPS_FIRST_ELEMENT
The spliterator that skips the first element. -
SPLITERATOR_FOR_EACH_REMAINING_DOES_NOT_CALL_ACTION
The 'forEachRemaining' method on the spliterator does not call the action.- See Also:
-
SPLITERATOR_TRY_SPLIT_ALWAYS_RETURNS_NULL
The 'trySplit' method on the spliterator always returnsnull
.- See Also:
-
SPLITERATOR_TRY_ADVANCE_DOES_NOT_CALL_ACTION
The 'tryAdvance' method on the spliterator does not call the action.- See Also:
-
SPLITERATOR_TRY_ADVANCE_ALWAYS_RETURNS_TRUE
The 'tryAdvance' method always returns true.- See Also:
-
SPLITERATOR_TRY_ADVANCE_ALWAYS_RETURNS_FALSE
The 'tryAdvance' method always returns false.- See Also:
-
SPLITERATOR_ESTIMATE_SIZE_ALWAYS_RETURNS_MAX_VALUE
TheestimateSize
method always returns the max value.- See Also:
-
SPLITERATOR_ESTIMATE_SIZE_ALWAYS_RETURNS_ZERO
TheestimateSize
method always returns zero.- See Also:
-
SPLITERATOR_GET_EXACT_SIZE_IF_KNOWN_ALWAYS_RETURNS_NEGATIVE_ONE
ThegetExactSizeIfKnown
method always returns negative one (-1).- See Also:
-
SPLITERATOR_CHARACTERISTICS_ALWAYS_RETURNS_ZERO
Thecharacteristics
method always returns zero (0).- See Also:
-
SPLITERATOR_HAS_CHARACTERISTIC_ALWAYS_RETURNS_TRUE
ThehasCharacteristics
method always returnstrue
.- See Also:
-
SPLITERATOR_HAS_CHARACTERISTIC_ALWAYS_RETURNS_FALSE
ThehasCharacteristics
method always returnsfalse
.- See Also:
-
SPLITERATOR_GET_COMPARATOR_ALWAYS_RETURNS_NULL
ThegetComparator
method always returnnull
.- See Also:
-
-
Constructor Details
-
BreakableSpliterator
Constructs a breakable spliterator from a spliterator that will provide the implementation.- Parameters:
iterator
- The spliterator that will provide the implementationbreaks
- The breaks that define how the iterator is broken.characteristics
- A mask that indicates the characteristics of the iterator.
-
-
Method Details
-
forEachRemaining
Implements the forEachRemaining method from the
Spliterator
interface.Breaks
This method can be broken using the following collection breaks:
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_FOR_EACH_REMAINING_DOES_NOT_CALL_ACTION) .build().spliterator();
- Specified by:
forEachRemaining
in interfaceSpliterator<E>
- Parameters:
action
- The action to run on the remaining elements.
-
trySplit
Implements the forEachRemaining method from the
Spliterator
interface.Breaks
This method can be broken using the following collection breaks:
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_TRY_SPLIT_ALWAYS_RETURNS_NULL) .build().spliterator();
- Specified by:
trySplit
in interfaceSpliterator<E>
-
tryAdvance
Implements the tryAdvance method from the
Spliterator
interface.Breaks
This method can be broken using the following collection breaks:
- SPLITERATOR_IS_ALWAYS_EMPTY
- SPLITERATOR_TRY_ADVANCE_DOES_NOT_CALL_ACTION
- SPLITERATOR_TRY_ADVANCE_ALWAYS_RETURNS_TRUE
- SPLITERATOR_TRY_ADVANCE_ALWAYS_RETURNS_FALSE
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_TRY_ADVANCE_DOES_NOT_CALL_ACTION) .build().spliterator();
- Specified by:
tryAdvance
in interfaceSpliterator<E>
- Parameters:
action
- The action to perform on the element- Returns:
false
if no remaining elements existed upon entry to this method, elsetrue
.
-
estimateSize
public long estimateSize()Implements the estimateSize method from the
Spliterator
interface.Breaks
This method can be broken using the following collection breaks:
- SPLITERATOR_IS_ALWAYS_EMPTY
- SPLITERATOR_ESTIMATE_SIZE_ALWAYS_RETURNS_MAX_VALUE
- SPLITERATOR_ESTIMATE_SIZE_ALWAYS_RETURNS_ZERO
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_ESTIMATE_SIZE_ALWAYS_RETURNS_MAX_VALUE) .build().spliterator();
- Specified by:
estimateSize
in interfaceSpliterator<E>
- Returns:
- the estimated size, or zero if iut is broken, or Long. MAX_VALUE if infinite, unknown, too expensive to compute or broken.
-
getExactSizeIfKnown
public long getExactSizeIfKnown()Implements the getExactSizeIfKnown method from the
Spliterator
interface.Breaks
This method can be broken using the following collection breaks:
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_GET_EXACT_SIZE_IF_KNOWN_ALWAYS_RETURNS_NEGATIVE_ONE) .build().spliterator();
- Specified by:
getExactSizeIfKnown
in interfaceSpliterator<E>
- Returns:
- the exact size, if known, else -1, or another value if it is broken.
-
characteristics
public int characteristics()Implements the characteristics method from the
Spliterator
interface.Breaks
This method can be broken using the following breaks:
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_CHARACTERISTICS_ALWAYS_RETURNS_ZERO) .build().spliterator();
- Specified by:
characteristics
in interfaceSpliterator<E>
- Returns:
- a representation of characteristics, or possibly zero if the spliterator is broken.
-
hasCharacteristics
public boolean hasCharacteristics(int characteristics) Implements the hasCharacteristics method from the
Spliterator
interface.Breaks
This method can be broken using the following collection breaks:
Example
A spliterator that has any of these breaks can be constructed using the iterable builder:
Spliterator<Integer> iterator = Breakable.iterableOf(1,2,3,4,5) .withBreak(SPLITERATOR_CHARACTERISTICS_ALWAYS_RETURNS_ZERO) .build().spliterator();
- Specified by:
hasCharacteristics
in interfaceSpliterator<E>
- Returns:
- a representation of characteristics, or possibly zero if the spliterator is broken.
-
getComparator
- Specified by:
getComparator
in interfaceSpliterator<E>
-