org.jwalk.gen
Class InterfaceGenerator

java.lang.Object
  extended by org.jwalk.gen.InterfaceGenerator
All Implemented Interfaces:
CustomGenerator, Generator

public class InterfaceGenerator
extends java.lang.Object
implements CustomGenerator

InterfaceGenerator is a custom generator of values for interface types. There is no general solution in Java to providing value synthesis for all interface types. This InterfaceGenerator is a partial work-around that synthesises values of suitable concrete object-types to satisfy a number of commonly-used interfaces. If the user needs to generate values for other interface-types, or more generally, for any abstract type, then a suitable custom generator must be provided to recognise these types and create instances of matching concrete types.

InterfaceGenerator synthesises values of the abstract collection types: CharSequence, Collection, List, Set and Map.

Version:
1.0
Author:
Anthony Simons

Constructor Summary
InterfaceGenerator()
           
 
Method Summary
 boolean canCreate(java.lang.Class<?> type)
          Reports whether this InterfaceGenerator can create a given type.
 java.lang.Object nextValue(java.lang.Class<?> type)
          Creates the next value in sequence for the requested interface.
 void setOwner(MasterGenerator generator)
          Sets the owner of this InterfaceGenerator to a MasterGenerator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterfaceGenerator

public InterfaceGenerator()
Method Detail

canCreate

public boolean canCreate(java.lang.Class<?> type)
Reports whether this InterfaceGenerator can create a given type. Although this generator cannot synthesise for every interface-type, it declares that it handles all interface-types, because of the need to trap interface types that have not otherwise been handled by a user-supplied CustomGenerator.

Specified by:
canCreate in interface Generator
Parameters:
type - the requested type.
Returns:
true if the type is any interface-type.

nextValue

public java.lang.Object nextValue(java.lang.Class<?> type)
                           throws GeneratorException
Creates the next value in sequence for the requested interface. This is an ad-hoc translation from a number of interface-types to concrete object-types. So far, we cover the collection-interfaces: {CharSequence, Collection, List, Set, Map}

Specified by:
nextValue in interface Generator
Parameters:
type - the requested type.
Returns:
the synthesised value.
Throws:
GeneratorException, - if no value of this type could be synthesised.
GeneratorException - if no value of this type could be synthesised.

setOwner

public void setOwner(MasterGenerator generator)
Sets the owner of this InterfaceGenerator to a MasterGenerator.

Specified by:
setOwner in interface CustomGenerator
Parameters:
generator - the MasterGenerator of this CustomGenerator.