All Downloads are FREE. Search and download functionalities are using the official Maven repository.

toxgene.core.genes.trees.ToxAttribute Maven / Gradle / Ivy

The newest version!
/**
 * Holds an element attribute. It's value comes from a Gene.
 *
 * @author Denilson Barbosa
 * @version 01.
 */

package toxgene.core.genes.trees;

import toxgene.core.genes.Gene;
import toxgene.core.genes.VarQttyGene;
import toxgene.core.random.ToxRandom;

import java.util.Vector;
import java.io.PrintStream;

public class ToxAttribute implements TreeGene{
  private String name;
  private Gene contents;
  private int min_qtty, max_qtty;
  private boolean get_max_qtty;
  private char separator;
  /**
   * Pseudo-random number generator that gives the number of occurrences for
   * the attribute
   */
  private ToxRandom randomGenerator;

  public ToxAttribute(String name, int min, int max, Gene contents, 
											ToxRandom rand, boolean get_max_qtty, char separator){
		this.name = name;
		this.contents = contents;
		this.randomGenerator = rand;
		this.min_qtty = min;
		this.max_qtty = max;
		this.get_max_qtty = get_max_qtty;
		this.separator = (separator == 0 ? ',': separator);
		
		if (max_qtty == -1){
			get_max_qtty = true;
		}
		else{
			get_max_qtty = false;
		}
  }

  /**
   * Resets the gene.
   */
  public void reset(){
		contents.reset();
  }

  public void generate(PrintStream outStream){
		int times = getQtty();

		if (times > 0){
			if (contents instanceof ToxScan){
				((ToxScan)contents).update();
			}
			//add a space first
			outStream.print(" "+name+"=\"");
			contents.generate(outStream);
			for (int i=1; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy