/**
 * 
 */
package vtools.dataModel.types;

import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @author lord_pretzel
 *
 */
public class DataTypeHandler {
	
	private List<DataType> types;
	private Map<String,DataType> nameToDTMap;
	private float[] percentages;
	private int numDTs;
	
	private static DataTypeHandler inst = new DataTypeHandler();
	
	public static DataTypeHandler getInst () {
		return inst;
	}
	
	private DataTypeHandler () {
		
	}
	
	public Atomic getRandomDT (Random randGen) {
		float r = randGen.nextFloat();
		
		for(int i = 0; i < getNumDTs(); i++) {
			if (r < getPercentages()[i])
				return getTypes().get(i);
		}
		return Atomic.STRING;
	}

	public List<DataType> getTypes() {
		return types;
	}

	public void setTypes(List<DataType> types) {
		this.types = types;
	}

	public Map<String,DataType> getNameToDTMap() {
		return nameToDTMap;
	}

	public void setNameToDTMap(Map<String,DataType> nameToDTMap) {
		this.nameToDTMap = nameToDTMap;
	}

	public float[] getPercentages() {
		return percentages;
	}

	public void setPercentages(float[] percentages) {
		this.percentages = percentages;
	}

	public int getNumDTs() {
		return numDTs;
	}

	public void setNumDTs(int numDTs) {
		this.numDTs = numDTs;
	}
	
	
	
}

@@ -302,18 +302,50 @@
 numDTs;%0A
+%09private float%5B%5D probabilities;%0A
 %09%0A
-
 %09private
@@ -502,16 +502,200 @@
 %09%09%0A%09%7D%0A%09%0A
+%09public void setProbabilities() %7B%0A%09%09probabilities%5B0%5D = percentages%5B0%5D/100;%0A%09%09for (int k = 0; k %3C numDTs; k++) %7B%0A%09%09%09probabilities%5Bk%5D = probabilities%5Bk-1%5D + percentages%5Bk%5D/100;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09public 
@@ -732,16 +732,38 @@
 dGen) %7B%0A
+%09%09setProbabilities();%0A
 %09%09float 
@@ -787,19 +787,16 @@
 loat();%0A
-%09%09%0A
 %09%09for(in
@@ -808,27 +808,36 @@
  0; i %3C 
-getNumDTs()
+probabilities.length
 ; i++) %7B
@@ -848,32 +848,29 @@
 if (r %3C 
-getPercentages()
+probabilities
 %5Bi%5D)%0A%09%09%09

set percentages as probabilities