/**
 * 
         -------- Copyright (C) [2012]  [Kristofer SCHWEIGER & Niklas FLORIAN1]---------

    This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
 *  or (at your option) any later version.
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 * 
    You should have received a copy of the GNU General Public License along with this program; if not, 
 *  write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA

 * 
 * For any licening issues you can contact us under following adress: Mosaik.Projekt.2012@gmail.com
 */


package dataBase.search;

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

/**
 * Keeps the best(lowest) entry.
 * 
 * @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();
	}
}

