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

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

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
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()