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

org.fuzzydb.random.AbstractRandomGenerator Maven / Gradle / Ivy

Go to download

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);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy