Switch

Switch

Generates a value based on the output of a sub-generator. Either specify a sub-generator or run another generator using a Sequential before this one to provide a value. After that, add case-elements (with 'value' attributes) to check the generated value and run the case's specified sub-generator to get a final result.

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
case Content type: Sub-generator
A specific case to check. A case element has to specify an attribute 'value' which is matched against the result of the initial sub-generator. If the result matches the specified value, the sub-generator defined within the current case element is run.
yes 1
default Content type: Sub-generator
If none of the specified cases match, this generator is run to get a result.
Default: <not set>
no 0 1
gen Value Generator for this field no 0 1
Sub-Attributes
Parent Name Description Required Min Max Allowed Values
case value yes 1 1
Sub-Parameters
Parent Name Description Required Min Max Allowed Values
case gen Value Generator for this field yes 1 1

Examples

  1. Static Values based on Numbers

    Generates either "Cat", "Dog", or "Turtle" based on the output of the underlying LongNumber generator. The generator produces "Cat" if the underlying long number is 1, "Dog" if it is 2, and "Turtle" if it is 3.

    Schema config for Static Values based on Numbers
    <?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>-->
      <seed>87467532L</seed>
    
      <rng name="PdgfDefaultRandom"/>
    
      <!--Default Scale factor for all tables -->
      <property name="SF" type="double">1</property>
    
      <table name="SWITCH">
        <!-- if tables should scale with -SF command line argument.
             Specify your scaling formula here: -->
        <size>10 * ${SF}</size>
    
        <!--Static Values based on Numbers-->
          <!--
            Generates either "Cat", "Dog", or "Turtle" based on the output of the underlying LongNumber generator. The
            generator produces "Cat" if the underlying long number is 1, "Dog" if it is 2, and "Turtle" if it is 3.
          -->
          <field name="pet" size="" type="VARCHAR">
            <gen_Switch>
              <gen_LongNumber>
                <min>1</min>
                <max>3</max>
              </gen_LongNumber>
              <case value="1">
                <gen_StaticValue>
                  <value>Cat</value>
                </gen_StaticValue>
              </case>
              <case value="2">
                <gen_StaticValue>
                  <value>Dog</value>
                </gen_StaticValue>
              </case>
              <case value="3">
                <gen_StaticValue>
                  <value>Turtle</value>
                </gen_StaticValue>
              </case>
            </gen_Switch>
          </field>
          </table>
    </schema>
    
    Output for Static Values based on Numbers
    Turtle
    Dog
    Turtle
    Turtle
    Cat
    Dog
    Turtle
    Cat
    Turtle
    Turtle
  2. Static Values based on Numbers with Default Case

    Generates either "Cat", "Dog", "Turtle", or "UNKNOWN" based on the output of the underlying LongNumber generator. The default case is "UNKNOWN" for all numbers other than 1, 2, and 3.

    Schema config for Static Values based on Numbers with Default Case
    <?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>-->
      <seed>87467532L</seed>
    
      <rng name="PdgfDefaultRandom"/>
    
      <!--Default Scale factor for all tables -->
      <property name="SF" type="double">1</property>
    
      <table name="SWITCH">
        <!-- if tables should scale with -SF command line argument.
             Specify your scaling formula here: -->
        <size>10 * ${SF}</size>
    
        <!--Static Values based on Numbers with Default Case-->
          <!--
            Generates either "Cat", "Dog", "Turtle", or "UNKNOWN" based on the output of the underlying LongNumber
            generator. The default case is "UNKNOWN" for all numbers other than 1, 2, and 3.
          -->
          <field name="pet_default" size="" type="VARCHAR">
            <gen_Switch>
              <gen_LongNumber>
                <min>1</min>
                <max>4</max>
              </gen_LongNumber>
              <default>
                <gen_StaticValue>
                  <value>UNKNOWN</value>
                </gen_StaticValue>
              </default>
              <case value="1">
                <gen_StaticValue>
                  <value>Cat</value>
                </gen_StaticValue>
              </case>
              <case value="2">
                <gen_StaticValue>
                  <value>Dog</value>
                </gen_StaticValue>
              </case>
              <case value="3">
                <gen_StaticValue>
                  <value>Turtle</value>
                </gen_StaticValue>
              </case>
            </gen_Switch>
          </field>
          </table>
    </schema>
    
    Output for Static Values based on Numbers with Default Case
    Cat
    Dog
    Dog
    UNKNOWN
    UNKNOWN
    Dog
    Cat
    UNKNOWN
    Turtle
    Turtle
2.7-83fb0 | 2020-04-22