001package es.ucm.fdi.gaia.jcolibri.method.maintenance; 002 003import java.util.Collections; 004import java.util.LinkedList; 005import java.util.List; 006 007import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 008 009/** 010 * Stores the case result information. It contains a <case, result> pair. 011 * The result is some double value related to the case. 012 * 013 * @author Lisa Cummins 014 */ 015public class CaseResult extends QueryResult 016{ 017 /** 018 * Sets up a <case, result> pair. 019 * @param _case The case to be stored 020 * @param result The result associated with this case. 021 */ 022 public CaseResult(CBRCase _case, double result) 023 { super(_case, result); 024 } 025 026 /** 027 * Returns the case. 028 * @return the case. 029 */ 030 public CBRCase getCase() 031 { return (CBRCase) _case; 032 } 033 034 /** 035 * Sorts the given list of CaseResults in the given order and 036 * returns the sorted list. 037 * @param ascending The order in which to sort the elements. 038 * @param toSort The list of CaseResults to sort. 039 * @return the sorted list. 040 */ 041 public static List<CaseResult> sortResults(boolean ascending, List<CaseResult> toSort) 042 { Collections.sort(toSort); 043 if(ascending) 044 { return toSort; 045 } 046 List<CaseResult> sorted = new LinkedList<CaseResult>(); 047 for(CaseResult res: toSort) 048 { sorted.add(0, res); 049 } 050 return sorted; 051 } 052}