Module org.refcodes.generator
Package org.refcodes.generator
Class ThreadBufferedGeneratorDecorator<T>
- java.lang.Object
-
- org.refcodes.generator.ThreadBufferedGeneratorDecorator<T>
-
- Type Parameters:
T
- the generic type of the elements being generated.
- All Implemented Interfaces:
Iterator<T>
,Generator<T>
,org.refcodes.mixin.DecorateeAccessor<Generator<T>>
public class ThreadBufferedGeneratorDecorator<T> extends Object implements Generator<T>, org.refcodes.mixin.DecorateeAccessor<Generator<T>>
TheThreadBufferedGeneratorDecorator
decorates aGenerator
with read-ahead functionality by buffering generated IDs on a perThread
basis: The resultingGenerator
is thread safe!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.DecorateeAccessor
org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE extends Object,B extends org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE,B>>, org.refcodes.mixin.DecorateeAccessor.DecorateeMutator<DECORATEE extends Object>, org.refcodes.mixin.DecorateeAccessor.DecorateeProperty<DECORATEE extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description ThreadBufferedGeneratorDecorator(Generator<T> aDecoratee)
Constructs theThreadBufferedGeneratorDecorator
decorating the providedGenerator
using theDEFAULT_BUFFER_SIZE
for the per thread read-ahead buffer.ThreadBufferedGeneratorDecorator(Generator<T> aDecoratee, int aBufferSize)
Constructs theThreadBufferedGeneratorDecorator
decorating the providedGenerator
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
enableBufferRefill()
Enables or resumes the creation of new(!)Generator<T>
getDecoratee()
boolean
hasNext()
Tests whether theGenerator
is capable of generating aGenerator.next()
item.T
next()
Generates a next item.void
pauseBufferRefill()
Pauses the creation of new(!)void
remove()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ThreadBufferedGeneratorDecorator
public ThreadBufferedGeneratorDecorator(Generator<T> aDecoratee)
Constructs theThreadBufferedGeneratorDecorator
decorating the providedGenerator
using theDEFAULT_BUFFER_SIZE
for the per thread read-ahead buffer.- Parameters:
aDecoratee
- TheGenerator
to be decorated.
-
ThreadBufferedGeneratorDecorator
public ThreadBufferedGeneratorDecorator(Generator<T> aDecoratee, int aBufferSize)
Constructs theThreadBufferedGeneratorDecorator
decorating the providedGenerator
.- Parameters:
aDecoratee
- TheGenerator
to be decorated.aBufferSize
- The size of the read-ahead buffer
-
-
Method Detail
-
hasNext
public boolean hasNext()
Tests whether theGenerator
is capable of generating aGenerator.next()
item.
-
next
public T next()
Generates a next item.
-
pauseBufferRefill
public void pauseBufferRefill()
Pauses the creation of new(!) IDs, any IDs already created are still available for consumption vianext()
.
-
enableBufferRefill
public void enableBufferRefill()
-
-