001 package jcolibri.method.maintenance; 002 003 import java.util.Collections; 004 import java.util.LinkedList; 005 import java.util.List; 006 007 import 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 */ 015 public class CaseResult extends QueryResult 016 implements Comparable 017 { 018 /** 019 * Sets up a <case, result> pair. 020 * @param _case The case to be stored 021 * @param result The result associated with this case. 022 */ 023 public CaseResult(CBRCase _case, double result) 024 { super(_case, result); 025 } 026 027 /** 028 * Returns the case. 029 * @return the case. 030 */ 031 public CBRCase getCase() 032 { return (CBRCase)_case; 033 } 034 035 /** 036 * Sorts the given list of CaseResults in the given order and 037 * returns the sorted list. 038 * @param ascending The order in which to sort the elements. 039 * @param toSort The list of CaseResults to sort. 040 * @return the sorted list. 041 */ 042 @SuppressWarnings("unchecked") 043 public static List sortResults(boolean ascending, List<CaseResult> toSort) 044 { Collections.sort(toSort); 045 if(ascending) 046 { return toSort; 047 } 048 List<CaseResult> sorted = new LinkedList<CaseResult>(); 049 for(CaseResult res: toSort) 050 { sorted.add(0, res); 051 } 052 return sorted; 053 } 054 }