org.jwalk.core
Class ArrayGenerator
java.lang.Object
org.jwalk.core.ValueGenerator
org.jwalk.core.ArrayGenerator
- All Implemented Interfaces:
- MasterGenerator, Generator
- Direct Known Subclasses:
- ObjectGenerator
public abstract class ArrayGenerator
- extends ValueGenerator
ArrayGenerator is an abstract generator of arrays and primitive values.
Since Generators can be quite complicated, the standard ObjectGenerator is
split into three parts, with ValueGenerator being the root of a hierarchy,
whose descendants are ArrayGenerator and finally ObjectGenerator.
ArrayGenerator provides the ability to synthesise values of all Java array
types. Being abstract, it cannot cannot be instantiated directly. The
methods canCreate
and nextValue
are still
abstract in ArrayGenerator. ObjectGenerator is the first MasterGenerator
which may be used directly by JWalkers.
ArrayGenerator is able to synthesise primitive Java arrays of any type,
including nested arrays, and arrays of different dimensions. It inherits
the ability to synthesise primitive element-types from ValueGenerator, but
defers handling general object element-types to ObjectGenerator.
- Version:
- 1.0
- Author:
- Anthony Simons
Constructor Summary |
protected |
ArrayGenerator()
Initialises the ArrayGenerator parent part of an ObjectGenerator. |
Method Summary |
protected java.lang.Object |
createArray(java.lang.Class<?> type)
Creates an instance of a Java array-type. |
protected boolean |
isArray(java.lang.Class<?> type)
Reports if a type is a primitive Array type. |
protected boolean |
isPrintable(java.lang.Class<?> type)
Reports whether a type is printable. |
java.lang.String |
oracleValue(java.lang.Object object)
Converts any synthesised object into its oracle value format. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ArrayGenerator
protected ArrayGenerator()
- Initialises the ArrayGenerator parent part of an ObjectGenerator.
This method is protected, since no instances of ArrayGenerator may be
created directly. In addition to the initialisation performed by
ValueGenerator, initialises the seed value controlling array lengths.
isArray
protected boolean isArray(java.lang.Class<?> type)
- Reports if a type is a primitive Array type.
- Parameters:
type
- the type to inspect.
- Returns:
- the result of type.isArray().
isPrintable
protected boolean isPrintable(java.lang.Class<?> type)
- Reports whether a type is printable. Some types have directly printable
instances, whereas others need to be encoded in some way before display.
Printable types include primitive, wrapped, enumerated, primitive array
and String types. The elements of an array may, or may not, be directly
printable (general object-types may be encoded); however, the structure
of the array is printable, using a conventional format.
- Overrides:
isPrintable
in class ValueGenerator
- Parameters:
type
- a type to be tested.
- Returns:
- true if the type is printable.
createArray
protected java.lang.Object createArray(java.lang.Class<?> type)
throws GeneratorException
- Creates an instance of a Java array-type. The requested type may be a
multi-dimensional array-type. Synthesises arrays of monotonically
increasing length, starting with a length of 1, and incrementing the
length on each call. For multi-dimensional arrays, all dimensions are
created to the same length. The elements of the array are populated by
requesting the nextValue() for the array component-type.
- Parameters:
type
- the type of the array to generate.
- Returns:
- a populated instance of the requested array-type.
- Throws:
GeneratorException
- if no array could be synthesised.
oracleValue
public java.lang.String oracleValue(java.lang.Object object)
- Converts any synthesised object into its oracle value format. If
the object is a primitive Java array, converts it into a conventional
format consisting of a list of comma-separated elements enclosed in
braces. Each array-element is converted recursively using the same
oracleValue()
method.
If the object is not an array, assumes that it was synthesised by
ValueGenerator and uses the super-method.
- Specified by:
oracleValue
in interface MasterGenerator
- Overrides:
oracleValue
in class ValueGenerator
- Parameters:
object
- an object created by this ArrayGenerator.
- Returns:
- the encoded oracle value format.