001package es.ucm.fdi.gaia.jcolibri.extensions.recommendation.casesDisplay; 002 003import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 004import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery; 005import es.ucm.fdi.gaia.jcolibri.util.CopyUtils; 006 007/** 008 * Object that encapsulates the user answer when cases are shown.<br> 009 * This object keeps an internal integer with posible values: 010 * <ul> 011 * <li>QUIT 012 * <li>REFINE QUERY 013 * <li>BUY 014 * </ul> 015 * It also contains the chosen case from the list.<br> 016 * If the answer is BUY, the selected case is the final result.<br> 017 * If the answer is REFINE QUERY, the selected case can be used in Navigation 018 * by Proposing to elicit the query.<br> 019 * The subclass CriticalUserChoice is an extension that also contains 020 * the critiques to the chosen case. 021 * 022 * @author Juan A. Recio-Garcia 023 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge. 024 * @version 1.0 025 */ 026public class UserChoice 027{ 028 /** QUIT constant */ 029 public static final int QUIT = -1; 030 /** REFINE_QUERY constant */ 031 public static final int REFINE_QUERY = -2; 032 /** BUY constant */ 033 public static final int BUY = -3; 034 035 036 /** Internal value that stores the choice */ 037 int choice = -1; 038 039 /** Internal value to store the selected case */ 040 CBRCase selectedCase; 041 042 /** 043 * Constructor 044 * @param choice is the user's choice 045 */ 046 public UserChoice(int choice, CBRCase selectedCase) 047 { 048 this.choice = choice; 049 if(selectedCase != null) 050 this.selectedCase = CopyUtils.copyCBRCase(selectedCase); 051 else 052 selectedCase = null; 053 } 054 055 /** 056 * Returns the user choice 057 */ 058 public int getChoice() 059 { 060 return choice; 061 } 062 063 /** 064 * Returns true if the choice is QUIT 065 */ 066 public boolean isQuit() 067 { 068 return choice == QUIT; 069 } 070 071 /** 072 * Returns true if the choice is REFINE_QUERY 073 */ 074 public boolean isRefineQuery() 075 { 076 return choice == REFINE_QUERY; 077 } 078 079 /** 080 * Returns true if the choice is a case 081 */ 082 public boolean isBuy() 083 { 084 return choice == BUY; 085 } 086 087 /** 088 * Returns the critiqued case as a CBRQuery object. 089 */ 090 public CBRQuery getSelectedCaseAsQuery() 091 { 092 return this.selectedCase; 093 } 094 095 /** 096 * Returns the critiqued case. 097 */ 098 public CBRCase getSelectedCase() 099 { 100 return this.selectedCase; 101 } 102}