001    /**
002     * DisplayCasesIfNumber.java
003     * jCOLIBRI2 framework. 
004     * @author Juan A. Recio-García.
005     * GAIA - Group for Artificial Intelligence Applications
006     * http://gaia.fdi.ucm.es
007     * 28/10/2007
008     */
009    package jcolibri.extensions.recommendation.conditionals;
010    
011    import java.util.Collection;
012    
013    import javax.swing.JOptionPane;
014    
015    import jcolibri.cbrcore.CBRCase;
016    
017    /**
018     * Conditional method that returns true if the number of recieved cases
019     * is inside a range.<br>
020     * An optional value sets if a message should be displayed when the 
021     * number of cases is not in the range.
022     * 
023     * @author Juan A. Recio-Garcia
024     * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge.
025     * @version 1.0
026     *
027     */
028    public class DisplayCasesIfNumber
029    {
030        /**
031         * Checks if the number of cases is inside a range.
032         * It shows a message if the number of cases is not in range.
033         * @param max allowed cases
034         * @param min allowed cases
035         * @param cases received cases
036         * @return true if the number of cases is in range.
037         */
038        public static boolean displayCasesWithMessage(int max, int min, Collection<CBRCase> cases)
039        {
040            return displayCases(max,min,cases,true);
041        }
042    
043        /**
044         * Checks if the number of cases is inside a range.
045         * It does not show any message if the number of cases is not in range.
046         * @param max allowed cases
047         * @param min allowed cases
048         * @param cases received cases
049         * @return true if the number of cases is in range.
050         */
051        public static boolean displayCasesWithoutMessage(int max, int min, Collection<CBRCase> cases)
052        {
053            return displayCases(max,min,cases,false);       
054        }
055    
056        /**
057         * Checks if the number of cases is inside a range.
058         * @param max allowed cases
059         * @param min allowed cases
060         * @param cases received cases
061         * @param showMessage indicates if messages should be shown.
062         * @return true if the number of cases is in range.
063         */
064        public static boolean displayCases(int max, int min, Collection<CBRCase> cases, boolean showMessage)
065        {
066            int size = cases.size();
067    
068            if(size<min)
069            {
070                JOptionPane.showMessageDialog(null, "There are not enough cases that correspond with the query. Please use a more general query.","Not cases found",JOptionPane.INFORMATION_MESSAGE);
071                return false;
072            }
073            else if(size>max)
074            {
075                if(showMessage)
076                    JOptionPane.showMessageDialog(null, "There are too many cases that correspond with the query. Please use a more specific query.","Too many cases found",JOptionPane.INFORMATION_MESSAGE);
077                return false;
078            }
079            return true;
080    
081        }
082    }