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

de.invation.code.toval.misc.Allocation Maven / Gradle / Ivy

package de.invation.code.toval.misc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;

public class Allocation {
	
	private HashMap> exclusions = new HashMap>();
	private HashMap> mapping = new HashMap>();
	private HashMap insertStat = new HashMap();
	private Object[] subjects;
	private Object[] objects;
	private int allocationCount = 1;
	private Random rand = new Random();
	
	public Allocation(Object[] subjects, Object[] objects) {
		this.subjects = subjects;
		this.objects = objects;
	}
	
	public void addExclusion(Object key, Object value) {
		if(!exclusions.containsKey(key)){
			exclusions.put(key, new HashSet());
		}
		exclusions.get(key).add(value);
	}
	
	public void setAllocationCount(int count) {
		this.allocationCount = count;
	}
	
	private int getMappingSize() {
		int result = 0;
		for(Object a: subjects)
			if(mapping.get(a) != null)
				result += mapping.get(a).size();
		return result;
	}
	
	public Map> getMapping(){
		mapping.clear();
		insertStat.clear();
		Object nextObject;
		ArrayList possibleObjects = new ArrayList();
		while(getMappingSize() valueList = mapping.get(nextKey);
						if(valueList==null) {
							valueList = new ArrayList();
							mapping.put(nextKey, valueList);
						}
						if(valueList.size()