001package es.ucm.fdi.gaia.jcolibri.method.maintenance; 002 003 004import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 005import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery; 006 007/** 008 * Stores the query result information. It contains a <query, result> pair. 009 * The result is some double value related to the query. 010 * 011 * @author Lisa Cummins 012 */ 013public class QueryResult implements Comparable<QueryResult> 014{ 015 protected CBRQuery _case; 016 protected double result; 017 018 /** 019 * Sets up a <query, result> pair. 020 * @param _case The query case to be stored 021 * @param result The result associated with this case. 022 */ 023 public QueryResult(CBRQuery _case, double result) 024 { this._case = _case; 025 this.result = result; 026 } 027 028 /** 029 * Returns the case. 030 * @return the case. 031 */ 032 public CBRQuery getCase() 033 { return _case; 034 } 035 036 /** 037 * Set the given case to be the query case 038 * associated with this <query, result> pair. 039 * @param _case The case to set. 040 */ 041 public void setCase(CBRCase _case) 042 { this._case = _case; 043 } 044 045 /** 046 * Returns the result. 047 * @return the result. 048 */ 049 public double getResult() 050 { return result; 051 } 052 053 /** 054 * Set the given result to be the result 055 * associated with this <query, result> pair. 056 * @param result The result to set. 057 */ 058 public void setEval(double result) { 059 this.result = result; 060 } 061 062 /** 063 * Returns a String representation of this object. 064 * @return a String representation of this object. 065 */ 066 public String toString() 067 { return _case + " -> "+ result; 068 } 069 070 /** 071 * Returns the result of comparing this object to 072 * the given object. 073 * This returns 0 if the object is not of the same class 074 * as this object, -1 if the result of this object 075 * is less than the result of the given object, 0 if 076 * the result of this object is equal to the result of the 077 * given object and 1 if the result of this object is 078 * greater than the result of the given object. 079 * @return the result of comparing this object to 080 * the given object. 081 */ 082 public int compareTo(QueryResult o) 083 { if(!(o instanceof QueryResult)) 084 return 0; 085 086 QueryResult other = (QueryResult)o; 087 if(other.getResult() > result) 088 return -1; 089 else if(other.getResult() < result) 090 return 1; 091 else 092 return 0; 093 } 094 095 /** 096 * Sorts the given list of CaseResults in the given order and 097 * returns the sorted list. 098 * @param ascending The order in which to sort the elements. 099 * @param toSort The list of CaseResults to sort. 100 * @return the sorted list. 101 */ 102 //@SuppressWarnings("unchecked") 103 /*public static List<QueryResult> sortResults(boolean ascending, List<QueryResult> toSort) 104 { Collections.sort(toSort); 105 if(ascending) 106 { return toSort; 107 } 108 List<QueryResult> sorted = new LinkedList<QueryResult>(); 109 for(QueryResult res: toSort) 110 { sorted.add(0, res); 111 } 112 return sorted; 113 }*/ 114}