Template

Template

Template based generator. Specify your Java code between <getValue><![CDATA[ $INSERT_HERE ]]</getValue>
You are responsible for implementing the method body of:
public void getValue(bankmark.pdgf.util.random.AbstractPDGFRandom rng, bankmark.pdgf.core.dataGenerator.beans.FieldValueDTO fvdto, bankmark.pdgf.core.dataGenerator.beans.GenerationContext gc) throws Exception{
...

}

Attributes
Name Description Required Min Max Allowed Values
name (Class)Name of this element. Used to identify plugin Class. Full name is required. Example: com.en.myPluginPackage.myPuginClass no 0 1
id Identification String of this element. May be used to uniquely identify a field within the children of an Element. no 0 1
Nodes
Name Description Required Min Max Allowed Values
staticValue Content type: Java code
Here you can specify static values to be available to use. Especially useful if "heavy initalization" should be avoided for every generated dataset.
Example: <staticValue>new int{1,2,3,4,5}</staticValue>.
Default: <not set>
no 0 1
distribution Distribution to be used by a generator when calculating a value no 0 1
  • bankmark.pdgf.distribution.Logarithmic
  • bankmark.pdgf.distribution.Beta
  • bankmark.pdgf.distribution.Normal
  • bankmark.pdgf.distribution.Exponential
  • bankmark.pdgf.distribution.Zeta
  • bankmark.pdgf.distribution.Binomial
getValue Content type: Java code
The Java expression to evaluate. Example:
String test= (rng.nextDouble() > 0.5 ? (generator[0].toString() + " " + generator[1].toString()) : generator[1].toString());
fvdto.setBothValues(streetName);
Any number of sub-generator nodes may be specified within the Template which can be accessed in the template. If the template contains characters of the xml structure (like '<', '>', ...), the template has to be wrapped into '<![CDATA[ ... ]]'.
yes 1 1
gen Value Generator for this field no 0
Sub-Attributes
Parent Name Description Required Min Max Allowed Values
staticValue unlockFullAccess Content type: Boolean
Omits complexity restriction. This allows to enter ';' into the getValue and staticValue elements to be able to enter multiple commands into one line.
Default: true
no 0 1
  • true
  • false
  • 0
  • 1

Examples

  1. Run-length Encoding

    Generates random strings up to 20 characters long consisting of the characters 'A' and 'B'. The string is then run-length encoded using the algorithm specified in the Template 'getValue' tag.

    Schema config for Run-length Encoding
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!--
    /*******************************************************************************
    * Copyright (c) 2013, bankmark and/or its affiliates. All rights reserved.
    * bankmark UG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    ******************************************************************************/
    --><schema xmlns:doc="http://bankmark.de/pdgf/doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="demo" xsi:noNamespaceSchemaLocation="structure/pdgfSchema.xsd">
      <!-- All data is derived from this starting seed.
           If this seed is the same, the generated data will the same on each
           computer/node/platform.
           Change this seed to generate a different data set.-->
      <seed>1234567890L</seed>
    
      <rng name="PdgfDefaultRandom"/>
    
      <!--Default Scale factor for all tables -->
      <property name="SF" type="double">1</property>
    
      <table name="TEMPLATE">
        <!-- if tables should scale with -SF command line argument.
             Specify your scaling formula here: -->
        <size>10 * ${SF}</size>
    
        <!--Run-length Encoding-->
          <!--
            Generates random strings up to 20 characters long consisting of the characters 'A' and 'B'. The string is then
            run-length encoded using the algorithm specified in the Template 'getValue' tag.
          -->
          <field name="string" size="" type="VARCHAR">
            <gen_RandomString>
              <characters>AB</characters>
              <max>20</max>
            </gen_RandomString>
          </field>
          <field name="run_length_encoded" size="" type="NUMERIC">
            <gen_Template>
              <getValue><![CDATA[
                String inputStr = generator(0, rng, gc, fvdto).toString();
    
                // exit if input is empty
                if (inputStr.length() == 0) {
                    fvdto.setBothValues("");
                    return;
                }
    
                StringBuilder dest = new StringBuilder();
                for (int i = 0; i < inputStr.length(); i++) {
                    int runLength = 1;
                    while (i + 1 < inputStr.length() && inputStr.charAt(i) == inputStr.charAt(i + 1)) {
                        runLength++;
                        i++;
                    }
                    dest.append(runLength);
                    dest.append(inputStr.charAt(i));
                }
                fvdto.setBothValues(dest.toString());
              ]]></getValue>
              <gen_OtherFieldValue>
                <reference field="string"/>
              </gen_OtherFieldValue>
            </gen_Template>
          </field>
          </table>
    </schema>
    
    Output for Run-length Encoding
    BBBAABA|3B2A1B1A
    ABAAABABBABAAABBABBB|1A1B3A1B1A2B1A1B3A2B1A3B
    AAAAAAB|6A1B
    ABAAABBABAA|1A1B3A2B1A1B2A
    AAABABAAA|3A1B1A1B3A
    BABBBABBAABAAAA|1B1A3B1A2B2A1B4A
    AB|1A1B
    AABBAAABABABABABBB|2A2B3A1B1A1B1A1B1A1B1A3B
    BBBBABABABAA|4B1A1B1A1B1A1B2A
    ABAABBBABBBAA|1A1B2A3B1A3B2A
  2. Conditional Prefix

    Generates random strings with conditional prefixes. The generated random string is prefixed with '#PREFIX# - ' with a 50% chance.

    Schema config for Conditional Prefix
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!--
    /*******************************************************************************
    * Copyright (c) 2013, bankmark and/or its affiliates. All rights reserved.
    * bankmark UG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    ******************************************************************************/
    --><schema xmlns:doc="http://bankmark.de/pdgf/doc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="demo" xsi:noNamespaceSchemaLocation="structure/pdgfSchema.xsd">
      <!-- All data is derived from this starting seed.
           If this seed is the same, the generated data will the same on each
           computer/node/platform.
           Change this seed to generate a different data set.-->
      <seed>1234567890L</seed>
    
      <rng name="PdgfDefaultRandom"/>
    
      <!--Default Scale factor for all tables -->
      <property name="SF" type="double">1</property>
    
      <table name="TEMPLATE">
        <!-- if tables should scale with -SF command line argument.
             Specify your scaling formula here: -->
        <size>10 * ${SF}</size>
    
        <!--Conditional Prefix-->
          <!--
            Generates random strings with conditional prefixes. The generated random string is prefixed with '#PREFIX# - '
            with a 50% chance.
          -->
          <field name="conditional prefix" size="" type="NUMERIC">
            <gen_Template>
              <getValue><![CDATA[
                boolean hasPrefix = (rng.nextDouble() < 0.5) ? true : false;
                String prefix = generator[0].toString();
                String text = generator[1].toString();
                if (hasPrefix) {
                  fvdto.setBothValues(prefix + text);
                } else {
                  fvdto.setBothValues(text);
                }
              ]]></getValue>
              <gen_StaticValue>
                <value>#PREFIX# - </value>
              </gen_StaticValue>
              <gen_RandomString>
                <max>10</max>
              </gen_RandomString>
            </gen_Template>
          </field>
          </table>
    </schema>
    
    Output for Conditional Prefix
    rfFkKssdB
    #PREFIX# - VKbgG85p
    #PREFIX# - t
    Twsc7uc93
    #PREFIX# - K
    #PREFIX# - Kqfs
    xqX2
    #PREFIX# - wNAd2duhx
    YRmAYEyRSE
    zR
2.7-83fb0 | 2020-04-22