Top Description Inners Fields Constructors Methods
com.openhtmltopdf.util

public Class DescendantBoxSpliterator

extends Object
implements Spliterator<Box>
Class Inheritance
All Implemented Interfaces
java.util.Spliterator
Imports
java.util.ArrayDeque, .Deque, .List, .Spliterator, java.util.function.Consumer, com.openhtmltopdf.render.BlockBox, .Box, .InlineLayoutBox

A spliterator that can be used to create a stream of descendant boxes in breadth first order.

Note

This is likely slower than simply creating a box list recursively for small number of descendants but gets relatively faster (and uses less memory) as the list of descendants increases in size.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private int
private DescendantBoxSpliterator.State
private final Deque<Box>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
add(Box bx)

public int
characteristics()

Implements java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements.

private Box
public long
estimateSize()

Implements java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

private Box
private Box
getNextInlineChild(List<? extends Object> inlineChilds)

private boolean
private boolean
private void
next()

private void
public boolean
tryAdvance(Consumer<? super Box>
The action whose operation is performed at-most once
action
)

Implements java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false.

public Spliterator<Box>
trySplit()

Implements java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

childIndexback to summary
private int childIndex
curStateback to summary
private DescendantBoxSpliterator.State curState
unprocessedback to summary
private final Deque<Box> unprocessed

Constructor Detail

DescendantBoxSpliteratorback to summary
public DescendantBoxSpliterator(Box parent)

Method Detail

addback to summary
private void add(Box bx)
characteristicsback to summary
public int characteristics()

Implements java.util.Spliterator.characteristics.

Doc from java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements. The result is represented as ORed values from ORDERED, DISTINCT, SORTED, SIZED, NONNULL, IMMUTABLE, CONCURRENT, SUBSIZED. Repeated calls to characteristics() on a given spliterator, prior to or in-between calls to trySplit, should always return the same result.

If a Spliterator reports an inconsistent set of characteristics (either those returned from a single invocation or across multiple invocations), no guarantees can be made about any computation using this Spliterator.

Returns:int

a representation of characteristics

Annotations
@Override
currentback to summary
private Box current()
estimateSizeback to summary
public long estimateSize()

Implements java.util.Spliterator.estimateSize.

Doc from java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

If this Spliterator is SIZED and has not yet been partially traversed or split, or this Spliterator is SUBSIZED and has not yet been partially traversed, this estimate must be an accurate count of elements that would be encountered by a complete traversal. Otherwise, this estimate may be arbitrarily inaccurate, but must decrease as specified across invocations of trySplit.

Returns:long

the estimated size, or Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

Annotations
@Override
getNextback to summary
private Box getNext()
getNextInlineChildback to summary
private Box getNextInlineChild(List<? extends Object> inlineChilds)
hasChildrenback to summary
private boolean hasChildren(Box bx)
hasNextback to summary
private boolean hasNext()
nextback to summary
private void next()
setStateback to summary
private void setState(DescendantBoxSpliterator.State newState)
tryAdvanceback to summary
public boolean tryAdvance(Consumer<? super Box> action)

Implements java.util.Spliterator.tryAdvance.

Doc from java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false. If this Spliterator is ORDERED the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action:Consumer<? super Box>

The action whose operation is performed at-most once

Returns:boolean

false if no remaining elements existed upon entry to this method, else true.

Annotations
@Override
trySplitback to summary
public Spliterator<Box> trySplit()

Implements java.util.Spliterator.trySplit.

Doc from java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

If this Spliterator is ORDERED, the returned Spliterator must cover a strict prefix of the elements.

Unless this Spliterator covers an infinite number of elements, repeated calls to trySplit() must eventually return null. Upon non-null return:

  • the value reported for estimateSize() before splitting, must, after splitting, be greater than or equal to estimateSize() for this and the returned Spliterator; and
  • if this Spliterator is SUBSIZED, then estimateSize() for this spliterator before splitting must be equal to the sum of estimateSize() for this and the returned Spliterator after splitting.

This method may return null for any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.

Returns:Spliterator<Box>

a Spliterator covering some portion of the elements, or null if this spliterator cannot be split

Annotations
@Override
com.openhtmltopdf.util back to summary

private final Enum DescendantBoxSpliterator.State

extends Enum<DescendantBoxSpliterator.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final DescendantBoxSpliterator.State
public static final DescendantBoxSpliterator.State
public static final DescendantBoxSpliterator.State
public static final DescendantBoxSpliterator.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static DescendantBoxSpliterator.State
public static DescendantBoxSpliterator.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BLOCK_INLINE_CONTENTback to summary
public static final DescendantBoxSpliterator.State BLOCK_INLINE_CONTENT
BOX_CHILDRENback to summary
public static final DescendantBoxSpliterator.State BOX_CHILDREN
DONEback to summary
public static final DescendantBoxSpliterator.State DONE
ILB_INLINE_CHILDRENback to summary
public static final DescendantBoxSpliterator.State ILB_INLINE_CHILDREN

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static DescendantBoxSpliterator.State valueOf(String name)
valuesback to summary
public static DescendantBoxSpliterator.State[] values()