gt:     return (String[]) result.toArray(new String[result.size()]);
context: /*
   *   This program is free software: you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation, either version 3 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  /*
   * BayesNet.java
   * Copyright (C) 2005-2012 University of Waikato, Hamilton, New Zealand
   *
   */
  
  package weka.datagenerators.classifiers.classification;
  
  import java.util.Enumeration;
  import java.util.Vector;
  
  import weka.classifiers.bayes.net.BayesNetGenerator;
  import weka.core.Instance;
  import weka.core.Instances;
  import weka.core.Option;
  import weka.core.RevisionUtils;
  import weka.core.Utils;
  import weka.datagenerators.ClassificationGenerator;
  
  /**
   <!-- globalinfo-start -->
   * Generates random instances based on a Bayes network.
   * <p/>
   <!-- globalinfo-end -->
   *
   <!-- options-start -->
   * Valid options are: <p/>
   * 
   * <pre> -h
   *  Prints this help.</pre>
   * 
   * <pre> -o &lt;file&gt;
   *  The name of the output file, otherwise the generated data is
   *  printed to stdout.</pre>
   * 
   * <pre> -r &lt;name&gt;
   *  The name of the relation.</pre>
   * 
   * <pre> -d
   *  Whether to print debug informations.</pre>
   * 
   * <pre> -S
   *  The seed for random function (default 1)</pre>
   * 
   * <pre> -n &lt;num&gt;
   *  The number of examples to generate (default 100)</pre>
   * 
   * <pre> -A &lt;num&gt;
   *  The number of arcs to use. (default 20)</pre>
   * 
   * <pre> -C &lt;num&gt;
   *  The cardinality of the attributes and the class. (default 2)</pre>
   * 
   <!-- options-end -->
   *
   * @author FracPete (fracpete at waikato dot ac dot nz)
   * @version $Revision: 8034 $
   * @see BayesNetGenerator
   */
  
  public class BayesNet
    extends ClassificationGenerator {
    
    /** for serialization */
    static final long serialVersionUID = -796118162379901512L;
    
    /** the bayesian net generator, that produces the actual data */
    protected BayesNetGenerator m_Generator;
  
    /**
     * initializes the generator
     */
    public BayesNet() {
      super();
  
      setNumAttributes(defaultNumAttributes());
      setNumArcs(defaultNumArcs());
      setCardinality(defaultCardinality());
    }
    
    /**
     * Returns a string describing this data generator.
     *
     * @return a description of the data generator suitable for
     * displaying in the explorer/experimenter gui
     */
    public String globalInfo() {
      return 
          "Generates random instances based on a Bayes network.";
    }
  
   /**
     * Returns an enumeration describing the available options.
     *
     * @return an enumeration of all the available options
     */
    public Enumeration listOptions() {
      Vector result = enumToVector(super.listOptions());
  
      result.add(new Option(
                "\tThe number of arcs to use. (default " 
                + defaultNumArcs() + ")",
                "A", 1, "-A <num>"));
  
      result.add(new Option(
                "\tThe cardinality of the attributes and the class. (default " 
                + defaultCardinality() + ")",
                "C", 1, "-C <num>"));
  
      return result.elements();
    }
  
    /**
     * Parses a list of options for this object. <p/>
     *
     <!-- options-start -->
     * Valid options are: <p/>
     * 
     * <pre> -h
     *  Prints this help.</pre>
     * 
     * <pre> -o &lt;file&gt;
     *  The name of the output file, otherwise the generated data is
     *  printed to stdout.</pre>
     * 
     * <pre> -r &lt;name&gt;
     *  The name of the relation.</pre>
     * 
     * <pre> -d
     *  Whether to print debug informations.</pre>
     * 
     * <pre> -S
     *  The seed for random function (default 1)</pre>
     * 
     * <pre> -n &lt;num&gt;
     *  The number of examples to generate (default 100)</pre>
     * 
     * <pre> -A &lt;num&gt;
     *  The number of arcs to use. (default 20)</pre>
     * 
     * <pre> -C &lt;num&gt;
     *  The cardinality of the attributes and the class. (default 2)</pre>
     * 
     <!-- options-end -->
     *
     * @param options the list of options as an array of strings
     * @throws Exception if an option is not supported
     */
    public void setOptions(String[] options) throws Exception {
      String        tmpStr;
      Vector        list;
  
      super.setOptions(options);
  
      list = new Vector();
  
      list.add("-N");
      list.add("" + getNumAttributes());
  
      list.add("-M");
      list.add("" + getNumExamples());
      
      list.add("-S");
      list.add("" + getSeed());
      
      list.add("-A");
      tmpStr = Utils.getOption('A', options);
      if (tmpStr.length() != 0)
        list.add(tmpStr);
      else
        list.add("" + defaultNumArcs());
  
      list.add("-C");
      tmpStr = Utils.getOption('C', options);
      if (tmpStr.length() != 0)
        list.add(tmpStr);
      else
        list.add("" + defaultCardinality());
  
      setGeneratorOptions(list);
    }
  
    /**
     * Gets the current settings of the datagenerator.
     *
     * @return an array of strings suitable for passing to setOptions
     */
    public String[] getOptions() {
      Vector        result;
      String[]      options;
      int           i;
      
      result  = new Vector();
      options = removeBlacklist(super.getOptions());
      for (i = 0; i < options.length; i++)
        result.add(options[i]);
  
      // determine options from generator
      options = getGenerator().getOptions();
  
      try {
        result.add("-A");
        result.add(Utils.getOption('A', options));
      }
      catch (Exception e) {
        e.printStackTrace();
      }
  
      try {
        result.add("-C");
        result.add(Utils.getOption('C', options));
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      
  