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

toxgene.util.cdata.xmark.GPA Maven / Gradle / Ivy

The newest version!
package toxgene.util.cdata.xmark;
import java.util.Random;
import toxgene.interfaces.ToXgeneCdataGenerator;

/**
 * This class implements a simple CDATA generator that produces
 * random GPAs. 
 * 

* This code is provided as part of ToXgene - (c) 2001 University of Toronto * and IBM Corporation. * * @author Denilson Barbosa * @version 1.0 */ public class GPA implements ToXgeneCdataGenerator { private static Random pick; private static String result; /** * Specifies a seed for the random generator so that repeated * executions always produce the same content, if the same seed is * provided. * * @param seed random seed to initialize the random generator */ public void setRandomSeed(int seed){ pick = new Random(seed); } /** * Generates random text whose length is determined by the parameter * length. A value of -1 determines that a string of any length can * be returned; a positive value means that a string must be * truncated if necessary. * * @param length specifies the length of the CDATA value to be returned. */ public String getCdata(int length){ int first = pick.nextInt(5); if (first == 4) { result = first + ".00"; } else { result = first + "." + String.format("%02d", pick.nextInt(100)); } //length == -1 means that the string should not be trimmed if (length == -1){ return result; } if (result.length() > length) return result.substring(0,length); else return result; } //my own testing purposes: public static void main(String[] args) { System.out.println(generateGPA()); } public static String generateGPA() { pick = new Random(); int first = pick.nextInt(5); if (first == 4) { result = first + ".00"; } else { result = first + "." + String.format("%02d", pick.nextInt(100)); } return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy