S
- The class of the StructuredArray that is to be instantiated by the builderT
- The class of the elements in the StructuredArray that is to be instantiated the builderpublic class StructuredArrayBuilder<S extends StructuredArray<T>,T>
extends java.lang.Object
StructuredArray
<T>
StructuredArrayBuilder
follows the commonly used builder pattern, and is useful for
capturing the instantiation parameters of StructuredArray
s.
StructuredArrayBuilder
s can be created for "flat" and "nested" StructuredArray
constructs, and can range from the simplest forms used when default constructors are employed, to forms that
supply customized per-element construction arguments that can take construction context (such as index,
containing array, and arbitrary data passed in a contextCookie) into account.
StructuredArrayBuilder
to instantiate a StructuredArray is:
StructuredArray<MyElementClass> array = new StructuredArrayBuilder(StructuredArray.class, MyElementClass.class, length). build();
An example of passing specific (but identical) construction arguments to element constructors is:
Some examples of providing per-element construction parameters that depend on construction context include:Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(int.Class, int.Class); StructuredArray<MyElementClass> array = new StructuredArrayBuilder( StructuredArray.class, MyElementClass.class, length). elementCtorAndArgs(constructor, initArg1, initArg2). build();
Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(long.Class, long.Class); // Using a pre-constructed elementCtorAndArgsProvider: StructuredArray<MyElementClass> array = new StructuredArrayBuilder( StructuredArray.class, MyElementClass.class, length). elementCtorAndArgsProvider(myCtorAndArgsProvider). build(); // Using a Lambda expression for elementCtorAndArgsProvider: StructuredArray<MyElementClass> array2 = new StructuredArrayBuilder( StructuredArray.class, MyElementClass.class, length). elementCtorAndArgsProvider( context -> new CtorAndArgs<MyElementClass>( constructor, context.getIndex(), context.getIndex() * 2) ). build(); // Using an anonymous class for elementCtorAndArgsProvider: StructuredArray<MyElementClass> array3 = new StructuredArrayBuilder( StructuredArray.class, MyElementClass.class, length). elementCtorAndArgsProvider( new CtorAndArgsProvider() { @Override public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { return new CtorAndArgs(constructor, context.getIndex(), context.getIndex() * 2); } } ). build();
Constructor and Description |
---|
StructuredArrayBuilder(java.lang.Class<S> arrayClass,
java.lang.Class<T> elementClass,
long length)
Constructs a new
StructuredArrayBuilder object for creating arrays of type S with
elements of type T, and the given length. |
StructuredArrayBuilder(java.lang.Class<S> arrayClass,
PrimitiveArrayBuilder<A> subArrayBuilder,
long length)
Constructs a new
StructuredArrayBuilder object for creating an array of type S with
elements of type T, and the given length. |
StructuredArrayBuilder(java.lang.Class<S> arrayClass,
StructuredArrayBuilder<A,E> subArrayBuilder,
long length)
Constructs a new
StructuredArrayBuilder object for creating an array of type S with
elements of type T, and the given length. |
StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.Class<S> arrayClass,
java.lang.Class<T> elementClass,
long length)
Constructs a new
StructuredArrayBuilder object for creating arrays of type S with
elements of type T, and the given length. |
StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.Class<S> arrayClass,
PrimitiveArrayBuilder<A> subArrayBuilder,
long length)
Constructs a new
StructuredArrayBuilder object for creating an array of type S with
elements of type T, and the given length. |
StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.Class<S> arrayClass,
StructuredArrayBuilder<A,E> subArrayBuilder,
long length)
Constructs a new
StructuredArrayBuilder object for creating an array of type S with
elements of type T, and the given length. |
StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup,
StructuredArrayModel<S,T> arrayModel)
Constructs a new
StructuredArrayBuilder object for creating arrays of the given array model. |
StructuredArrayBuilder(StructuredArrayModel<S,T> arrayModel)
Constructs a new
StructuredArrayBuilder object for creating arrays of the given array model. |
Modifier and Type | Method and Description |
---|---|
StructuredArrayBuilder<S,T> |
arrayCtorAndArgs(java.lang.reflect.Constructor<S> constructor,
java.lang.Object... args)
Set the
Constructor and construction arguments to be used in constructing arrays. |
StructuredArrayBuilder<S,T> |
arrayCtorAndArgs(CtorAndArgs<S> arrayCtorAndArgs)
Set the
CtorAndArgs to be used in constructing arrays. |
S |
build()
Build a
StructuredArray according to the information captured in this builder |
StructuredArrayBuilder<S,T> |
contextCookie(java.lang.Object contextCookie)
Set the (opaque) contextCookie object associated with this builder.
|
StructuredArrayBuilder<S,T> |
elementCtorAndArgs(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... args)
Set the
Constructor and construction arguments to be used for all elements in the array. |
StructuredArrayBuilder<S,T> |
elementCtorAndArgs(CtorAndArgs<T> ctorAndArgs)
Set the
CtorAndArgs to be used for all elements in the array. |
StructuredArrayBuilder<S,T> |
elementCtorAndArgsProvider(CtorAndArgsProvider<T> ctorAndArgsProvider)
Set the
CtorAndArgsProvider used for determining the constructor and construction
arguments used for each element in the array. |
CtorAndArgs<S> |
getArrayCtorAndArgs()
Get the
CtorAndArgs describing the constructor and arguments used to instantiate arrays with
this builder. |
StructuredArrayModel<S,T> |
getArrayModel()
Get the
StructuredArrayModel that describes the arrays built by this builder |
java.lang.Object |
getContextCookie()
Get the (opaque) contextCookie object associated with this builder.
|
CtorAndArgsProvider<T> |
getElementCtorAndArgsProvider()
Get the
CtorAndArgsProvider which provides the constructor and arguments used to construct
individual elements of arrays instantiated with this builder. |
PrimitiveArrayBuilder |
getPrimitiveSubArrayBuilder()
Get the
StructuredArrayBuilder for the elements of the arrays built by
this builder. |
StructuredArrayBuilder |
getStructuredSubArrayBuilder()
Get the
StructuredArrayBuilder for the elements of the arrays built by
this builder. |
StructuredArrayBuilder<S,T> |
resolve()
Resolve any not-yet-resolved constructor information needed by this builder.
|
public StructuredArrayBuilder(java.lang.Class<S> arrayClass, java.lang.Class<T> elementClass, long length)
StructuredArrayBuilder
object for creating arrays of type S with
elements of type T, and the given length.
Note: This constructor form cannot be used with an element type T that extends StructuredArray. Use the
constructor form StructuredArrayBuilder(Class, StructuredArrayBuilder, long)
to create builders that instantiate nested StructuredArrays.arrayClass
- The class of the array to be built by this builderelementClass
- The class of elements in the array to be built by this builderlength
- The length of the array to be build by this builderpublic StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<S> arrayClass, java.lang.Class<T> elementClass, long length)
StructuredArrayBuilder
object for creating arrays of type S with
elements of type T, and the given length.
Note: This constructor form cannot be used with an element type T that extends StructuredArray. Use the
constructor form StructuredArrayBuilder(Class, StructuredArrayBuilder, long)
to create builders that instantiate nested StructuredArrays.lookup
- The lookup object to use for accessing constructors when resolving this builderarrayClass
- The class of the array to be built by this builderelementClass
- The class of elements in the array to be built by this builderlength
- The length of the array to be build by this builderpublic StructuredArrayBuilder(StructuredArrayModel<S,T> arrayModel)
StructuredArrayBuilder
object for creating arrays of the given array model.arrayModel
- The model of the array to be built by this builderpublic StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup, StructuredArrayModel<S,T> arrayModel)
StructuredArrayBuilder
object for creating arrays of the given array model.lookup
- The lookup object to use for accessing constructors when resolving this builderarrayModel
- The model of the array to be built by this builderpublic StructuredArrayBuilder(java.lang.Class<S> arrayClass, StructuredArrayBuilder<A,E> subArrayBuilder, long length)
StructuredArrayBuilder
object for creating an array of type S with
elements of type T, and the given length. Used when T extends StructuredArray, such that the
arrays instantiated by this builder would include nested StructuredArrays.A
- The class or the subArray (should match T for the StructuredArrayBuilder)E
- The element class in the subArray.arrayClass
- The class of the array to be built by this buildersubArrayBuilder
- The builder used for creating individual array elements (which are themselves
StructuredArrays)length
- The length of the array to be build by this builderpublic StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<S> arrayClass, StructuredArrayBuilder<A,E> subArrayBuilder, long length)
StructuredArrayBuilder
object for creating an array of type S with
elements of type T, and the given length. Used when T extends StructuredArray, such that the
arrays instantiated by this builder would include nested StructuredArrays.A
- The class or the subArray (should match T for the StructuredArrayBuilder)E
- The element class in the subArray.lookup
- The lookup object to use for accessing constructors when resolving this builderarrayClass
- The class of the array to be built by this buildersubArrayBuilder
- The builder used for creating individual array elements (which are themselves
StructuredArrays)length
- The length of the array to be build by this builderpublic StructuredArrayBuilder(java.lang.Class<S> arrayClass, PrimitiveArrayBuilder<A> subArrayBuilder, long length)
StructuredArrayBuilder
object for creating an array of type S with
elements of type T, and the given length. Used when T extends PrimitiveArray, such that the
arrays instantiated by this builder would include elements that are PrimitiveArrays.A
- The class in the subArray (should match T for the StructuredArrayBuilder)arrayClass
- The class of the array to be built by this buildersubArrayBuilder
- The builder used for creating individual array elements (which are themselves
subclassable PrimitiveArrays)length
- The length of the array to be build by this builderpublic StructuredArrayBuilder(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<S> arrayClass, PrimitiveArrayBuilder<A> subArrayBuilder, long length)
StructuredArrayBuilder
object for creating an array of type S with
elements of type T, and the given length. Used when T extends PrimitiveArray, such that the
arrays instantiated by this builder would include elements that are PrimitiveArrays.A
- The class in the subArray (should match T for the StructuredArrayBuilder)lookup
- The lookup object to use for accessing constructors when resolving this builderarrayClass
- The class of the array to be built by this buildersubArrayBuilder
- The builder used for creating individual array elements (which are themselves
subclassable PrimitiveArrays)length
- The length of the array to be build by this builderpublic StructuredArrayBuilder<S,T> elementCtorAndArgsProvider(CtorAndArgsProvider<T> ctorAndArgsProvider)
CtorAndArgsProvider
used for determining the constructor and construction
arguments used for each element in the array. The provider may use the specific element's
construction context in determining the construction parameters.
Note: This method overlaps in purpose with the alternate methods for controlling element
construction. Namely elementCtorAndArgs(CtorAndArgs)
and
elementCtorAndArgs(Constructor, Object...)
.ctorAndArgsProvider
- The provider used for determining the constructor and construction
arguments used for each element in instantiated arrayspublic StructuredArrayBuilder<S,T> elementCtorAndArgs(CtorAndArgs<T> ctorAndArgs)
CtorAndArgs
to be used for all elements in the array. All elements will be constructed with
the same constructor and the same arguments.
Note: This method overlaps in purpose with the alternate methods for controlling element
construction. Namely elementCtorAndArgsProvider(CtorAndArgsProvider)
and
elementCtorAndArgs(Constructor, Object...)
.ctorAndArgs
- The constructor and arguments used for all elements in arrayspublic StructuredArrayBuilder<S,T> elementCtorAndArgs(java.lang.reflect.Constructor<T> constructor, java.lang.Object... args)
Constructor
and construction arguments to be used for all elements in the array.
All elements will be constructed with the same constructor and the same arguments.
Note: This method overlaps in purpose with the alternate methods for controlling element
construction. Namely elementCtorAndArgsProvider(CtorAndArgsProvider)
and
elementCtorAndArgs(CtorAndArgs)
.constructor
- The constructor used for all elements in arraysargs
- The construction arguments supplied for the constructor, used for all elements in the arraypublic StructuredArrayBuilder<S,T> arrayCtorAndArgs(CtorAndArgs<S> arrayCtorAndArgs)
CtorAndArgs
to be used in constructing arrays.
Setting the means for array construction is Required if the array class (S) does not support a
default constructor, or if a non-default construction of the array instance is needed.arrayCtorAndArgs
- The constructor and arguments used for constructing arrayspublic StructuredArrayBuilder<S,T> arrayCtorAndArgs(java.lang.reflect.Constructor<S> constructor, java.lang.Object... args)
Constructor
and construction arguments to be used in constructing arrays.
Setting the means for array construction is Required if the array class (S) does not support a
default constructor, or if a non-default construction of the array instance is needed.constructor
- The constructor used for constructing arraysargs
- The construction arguments supplied for the constructorpublic StructuredArrayBuilder<S,T> contextCookie(java.lang.Object contextCookie)
ConstructionContext
object passed to the element
CtorAndArgsProvider
provider for each element in instantiated arrays.contextCookie
- the contextCookie objectpublic StructuredArrayBuilder<S,T> resolve()
java.lang.IllegalArgumentException
- if the array constructor or element constructor fail to resolve given
the current information in the builderpublic S build() throws java.lang.IllegalArgumentException
StructuredArray
according to the information captured in this builderStructuredArray
java.lang.IllegalArgumentException
- if the array constructor or element constructor fail to resolve given
the current information in the builderpublic StructuredArrayModel<S,T> getArrayModel()
StructuredArrayModel
that describes the arrays built by this builderStructuredArrayModel
that describes the arrays built by this builderpublic StructuredArrayBuilder getStructuredSubArrayBuilder()
StructuredArrayBuilder
for the elements of the arrays built by
this builder. NullStructuredArrayBuilder
for the elements of the arrays built by
this builder. Null if the array element type T does not extend StructuredArray
.public PrimitiveArrayBuilder getPrimitiveSubArrayBuilder()
StructuredArrayBuilder
for the elements of the arrays built by
this builder. NullStructuredArrayBuilder
for the elements of the arrays built by
this builder. Null if the array element type T does not extend StructuredArray
.public CtorAndArgs<S> getArrayCtorAndArgs()
CtorAndArgs
describing the constructor and arguments used to instantiate arrays with
this builder. May be null if non of arrayCtorAndArgs
,
resolve()
or
build()
have been called yet.CtorAndArgs
describing the constructor and arguments used to instantiate arrays with
this builder.public CtorAndArgsProvider<T> getElementCtorAndArgsProvider()
CtorAndArgsProvider
which provides the constructor and arguments used to construct
individual elements of arrays instantiated with this builder. May be null if non of
elementCtorAndArgsProvider
,
elementCtorAndArgs(org.ObjectLayout.CtorAndArgs<T>)
,
resolve(boolean)
or
build()
have been called yet.CtorAndArgsProvider
which provides the constructor and arguments used to construct
individual elements of arrays instantiated with this builderpublic java.lang.Object getContextCookie()
ConstructionContext
object passed to the element
CtorAndArgsProvider
provider for each element in instantiated arrays.