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

toxgene.core.genes.literals.ToxDate Maven / Gradle / Ivy

/**
 * Implements a gene for date literals
 *
 * @author Denilson Barbosa
 * @version 0.1
 */

package toxgene.core.genes.literals;

import java.io.PrintStream;
import java.text.SimpleDateFormat;

import toxgene.core.random.ToxRandom;
import toxgene.util.Date;

public class ToxDate extends LiteralGene{
  private Date startDate;
  /**
   * Pseudo-random number generator
   */
  private ToxRandom randomGenerator;

  private boolean format;

  private SimpleDateFormat dateFormat;

  public ToxDate(Date start, ToxRandom rand, String pattern){
	startDate = start;
	randomGenerator = rand;
	if (pattern.length() != 0){
	  format = true;
	  dateFormat = new SimpleDateFormat(pattern);
	}
	else{
	  format = false;
	}
  }
  
  /**
   * Returns the base type for literals of this gene.
   */
  public String baseType(){
	return("date");
  }

  /**
   * Outputs a random literal.
   */
  public void generate(PrintStream outStream){
	Date temp = new Date(startDate);
	temp.add((int)randomGenerator.nextInt());
	
	if (format){
	  outStream.print(dateFormat.format(temp.getTime()));
	}
	else{
	  outStream.print(temp.toString());
	}
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy