001    package jcolibri.extensions.recommendation.casesDisplay;
002    
003    import jcolibri.cbrcore.CBRCase;
004    import jcolibri.cbrcore.CBRQuery;
005    import 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     * @see jcolibri.extensions.recommendation.navigationByProposing.CriticalUserChoice
026     */
027    public class UserChoice
028    {
029        /** QUIT constant */
030        public static final int QUIT = -1;
031        /** REFINE_QUERY constant */
032        public static final int REFINE_QUERY = -2;
033        /** BUY constant */
034        public static final int BUY = -3;
035        
036        
037        /** Internal value that stores the choice */
038        int choice = -1;
039        
040        /** Internal value to store the selected case */
041        CBRCase selectedCase;
042        
043        /**
044         * Constructor
045         * @param choice is the user's choice
046         */
047        public UserChoice(int choice, CBRCase selectedCase)
048        {
049            this.choice = choice;
050            if(selectedCase != null)
051                this.selectedCase = CopyUtils.copyCBRCase(selectedCase);
052            else
053                selectedCase = null;
054        }
055        
056        /**
057         * Returns the user choice
058         */
059        public int getChoice()
060        {
061            return choice;
062        }
063        
064        /**
065         * Returns true if the choice is QUIT
066         */
067        public boolean isQuit()
068        {
069            return choice == QUIT;
070        }
071        
072        /**
073         * Returns true if the choice is REFINE_QUERY
074         */
075        public boolean isRefineQuery()
076        {
077            return choice == REFINE_QUERY;
078        }
079        
080        /**
081         * Returns true if the choice is a case
082         */
083        public boolean isBuy()
084        {
085            return choice == BUY;
086        }
087        
088        /**
089         * Returns the critiqued case as a CBRQuery object.
090         */
091        public CBRQuery getSelectedCaseAsQuery()
092        {
093            return this.selectedCase;
094        }
095        
096        /**
097         * Returns the critiqued case.
098         */
099        public CBRCase getSelectedCase()
100        {
101            return this.selectedCase;
102        }
103    }