CoCoME System Tests

org.cocome.tradingsystem.systests.util
Class ProductGenerator

java.lang.Object
  extended by org.cocome.tradingsystem.systests.util.ProductGenerator

public class ProductGenerator
extends java.lang.Object

This class is used to generate random but reproducable products.

Version:
$Rev: 60 $
Author:
Benjamin Hummel, Christian Pfaller, $Author: pfaller $

Field Summary
private static java.lang.String ALPHA
          Available alphabet for product name generation.
private  IEnterprise enterprise
          The enterprise used for creating products.
private  java.util.List<GeneratedProduct> generatedProducts
          A list of all products generated so far.
private  java.util.Random rng
          The random number generator used.
private  java.util.Set<java.lang.Integer> usedBarcodes
          The set of used barcodes to avoid repetition.
private  java.util.Set<java.lang.String> usedNames
          The set of used names to avoid repetition.
 
Constructor Summary
ProductGenerator(long randomSeed, IEnterprise enterprise)
          Construct a new product generator.
 
Method Summary
 int generate()
          Generate a single random product.
 void generate(int n)
          Generate the given number of random products.
 GeneratedProduct getGeneratedProduct(int i)
          Returns the product generated when i products had been generated already.
 int getNumberOfProducts()
          Returns the number of products generated so far.
 int getUnusedBarcode()
          Returns a new barcode which is not already used for any product.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALPHA

private static final java.lang.String ALPHA
Available alphabet for product name generation.

See Also:
Constant Field Values

rng

private final java.util.Random rng
The random number generator used.


enterprise

private final IEnterprise enterprise
The enterprise used for creating products.


usedBarcodes

private final java.util.Set<java.lang.Integer> usedBarcodes
The set of used barcodes to avoid repetition.


usedNames

private final java.util.Set<java.lang.String> usedNames
The set of used names to avoid repetition.


generatedProducts

private final java.util.List<GeneratedProduct> generatedProducts
A list of all products generated so far.

Constructor Detail

ProductGenerator

public ProductGenerator(long randomSeed,
                        IEnterprise enterprise)
Construct a new product generator.

Parameters:
randomSeed - the random seed used for initializing the random number generator.
enterprise - the enterprise used for creating products.
Method Detail

getNumberOfProducts

public int getNumberOfProducts()
Returns the number of products generated so far.


getGeneratedProduct

public GeneratedProduct getGeneratedProduct(int i)
Returns the product generated when i products had been generated already.


generate

public void generate(int n)
              throws java.lang.Exception
Generate the given number of random products.

Throws:
java.lang.Exception

generate

public int generate()
             throws java.lang.Exception
Generate a single random product.

Returns:
index of new product
Throws:
java.lang.Exception

getUnusedBarcode

public int getUnusedBarcode()
Returns a new barcode which is not already used for any product.


CoCoME System Tests

CoCoME System Tests - 0.1