org.fuzzydb.random.AbstractRandomGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.fuzzydb.util Show documentation
Show all versions of org.fuzzydb.util Show documentation
Contains classes not specific to fuzzydb implementation which
could be used in any implementation of fuzzy matching, or as
general utility classes such as those in the geo package.
The newest version!
package org.fuzzydb.random;
import org.fuzzydb.dto.attributes.Attribute;
import org.fuzzydb.dto.attributes.RandomGenerator;
import org.fuzzydb.util.MTRandom;
public abstract class AbstractRandomGenerator> implements RandomGenerator {
private final float nullProportion;
public AbstractRandomGenerator() {
nullProportion = 0f;
}
/**
*
* @param nullProportion - the proportion of results for which to return null
* i.e. 0.01, will result in 1% of the random values being null
*/
public AbstractRandomGenerator(float nullProportion) {
this.nullProportion = nullProportion;
}
public final RESULT next(String attrName) {
float rand = MTRandom.getInstance().nextFloat();
if (rand < nullProportion) {
return null;
}
return randomResult(attrName);
}
abstract protected RESULT randomResult(String attrName);
}