Previous detailUpNext detail
Step 2.2Step 2 overview

Step 2.3: Create frequency based generators

package net.sf.adatagenerator.ex.cdc1.util;

import net.sf.adatagenerator.api.FieldDependencyManager;
import net.sf.adatagenerator.api.FieldGenerator;
import net.sf.adatagenerator.core.DefaultFrequencyBasedGenerator;
import net.sf.adatagenerator.ex.cdc1.api.Cdc1Record;
import net.sf.adatagenerator.util.StringFrequencyFile;

public class Util {

  public static final String SEPARATOR = "/";

  public static final String HEALTH_REG_DATA_PACKLastName =
    "net/sf/adatagenerator/ex/healthreg/bean/data";
  //...

  public static final String RESOURCE_BASE_NAME_DOB = "DOB.csv";
  public static final String RESOURCE_BASE_NAME_FIRSTNAME = "FirstName.csv";
  // ...

  public static <B> FieldGenerator<B, String> createDOBGenerator(
      FieldDependencyManager<B> fdm) {
    return Util.createStringGenerator(fdm,
        Cdc1Record.RecordField.DOB.name(), Util.RESOURCE_BASE_NAME_DOB);
  }

  public static <B> FieldGenerator<B, String> createFirstNameGenerator(
      FieldDependencyManager<B> fdm) {
    return Util.createStringGenerator(fdm,
        Cdc1Record.RecordField.FirstName.name(),
        Util.RESOURCE_BASE_NAME_FIRSTNAME);
  }

  //...

  public static <B> FieldGenerator<B, String> createStringGenerator(
      FieldDependencyManager<B> fdm, String fieldName,
      String resourceBaseName) {
    ClassLoader cl = Util.class.getClassLoader();
    String fqrn = getFullyQualifiedDataName(resourceBaseName);
    StringFrequencyFile ff = new StringFrequencyFile(cl, fqrn);
    FieldGenerator<B, String> fg = new DefaultFrequencyBasedGenerator<B, String>(
        fieldName, fdm, ff);
    return fg;
  }

  public static String getFullyQualifiedDataName(String baseName) {
    return HEALTH_REG_DATA_PACKLastName + SEPARATOR + baseName;
  }

  //...

}

Previous detailUpNext detail
Step 2.2Step 2 overview