
toxgene.util.cdata.xmark.Emails Maven / Gradle / Ivy
package toxgene.util.cdata.xmark;
import java.util.Random;
import toxgene.interfaces.ToXgeneCdataGenerator;
/**
* This class implements a simple CDATA generator that produces
* random email addresses according to the rules specified by the
* XMark benchmark.
*
* This code is provided as part of ToXgene - (c) 2001 University of Toronto
* and IBM Corporation.
*
* @author Denilson Barbosa
* @version 1.0
*/
public class Emails implements ToXgeneCdataGenerator{
private static Random pick;
private static String result;
private static boolean loaded = false;
/**
* Constructor. The CDATA produced by an instance of this class uses
* the words stored in the FirstName, LastName and InetDomains
* classes.
*
* @see FirstNames
* @see LastNames
* @see InetDomains
*/
public Emails(){
init();
}
/**
* 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){
if (!loaded)
init();
result = FirstNames.data[pick.nextInt(FirstNames.len)];
result += ".";
result += LastNames.data[pick.nextInt(LastNames.len)];
result += "@";
result += InetDomains.data[pick.nextInt(InetDomains.len)];
//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;
}
/**
* The initialization consists of loading the data into the other
* classes. We do not initialize @see InetDomain because its
* constants are declared explicitly (there are not too many of
* them).
*/
private void init(){
FirstNames.init();
LastNames.init();
loaded = true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy