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

de.rpgframework.genericrpg.chargen.ai.RecommendationCache Maven / Gradle / Ivy

package de.rpgframework.genericrpg.chargen.ai;

import java.util.ArrayList;
import java.util.List;

public class RecommendationCache implements Comparable> {
	T data;
	Weight level;
	int count;
	List sources;
	
	public RecommendationCache(T data, Weight level) {
		this.data = data;
		this.level = level;
		sources = new ArrayList();
		count=1;
	}
	
	public void merge(RecommendationCache other) {
		if (data!=other.data)
			throw new IllegalArgumentException("does not match");
		if (other.level.ordinal()>level.ordinal()) {
			level = other.level;
			count = 1;
		} else if (other.level==level)
			count++;
	}
	
	public  String toString() { return data+"("+level+","+count+")"; }
	
	@Override
	public int compareTo(RecommendationCache other) {
		int cmp = level.compareTo(other.level);
		if (cmp!=0)
			return cmp;
		return ((Integer)count).compareTo(other.count);
	}
	
	public Weight getLevel() { return level; }
}