package dataBase.search;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * A List of data objects.
 * Can be sorted and limited in length.
 * 
 * @author Krisi
 */
public class Best1List<T> {
	
	//public static int DefaultTolerance=150;
	
	//public ArrayList<T> dataList = new ArrayList<T>(DefaultTolerance);
	public T best;
	//private boolean sortAndLimit;
	private Comparator<T> comparator;
	//public int lengthLimit, tolerance = DefaultTolerance;
	
	/**
	 * Constructor, full
	 */
	public Best1List(Comparator<T> c){
		this.comparator = c;
	}
	
	/**
	 * Change comparator
	 * @param c - new comparator
	 */
	public void setComparator(Comparator<T> c){
		this.comparator = c;
	}
	
	/**
	 * Add a single element.
	 * @param data
	 */
	public void add(T data){
		if(best==null || comparator.compare(best, data)>0)
			best = data;
	}
	
	/**
	 * Sort and shorten list to lengthLimit.
	 */
	public void sortAndLimit(){
		//
	}
	
	/**
	 * Delete entries next to each other from same object
	 * // comparator sees as equal.
	 */
	public void sortAndLimitWithoutDoubleEntries(){
		//
	}
	
	public ArrayList<T> getList(){
		ArrayList<T> dataList = new ArrayList<T>(1);
		dataList.add(best);
		return dataList;
	}
	
	@Override
	public String toString(){
		return "Best: " + best.toString();
	}
}

