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 */
009package es.ucm.fdi.gaia.jcolibri.extensions.recommendation.conditionals;
010
011import java.util.Collection;
012import java.util.List;
013
014import javax.swing.JOptionPane;
015
016import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
017
018/**
019 * Conditional method that returns true if the number of recieved cases
020 * is inside a range.<br>
021 * An optional value sets if a message should be displayed when the 
022 * number of cases is not in the range.
023 * 
024 * @author Juan A. Recio-Garcia
025 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge.
026 * @version 1.0
027 *
028 */
029public class DisplayCasesIfNumber
030{
031    /**
032     * Checks if the number of cases is inside a range.
033     * It shows a message if the number of cases is not in range.
034     * @param max allowed cases
035     * @param min allowed cases
036     * @param cases received cases
037     * @return true if the number of cases is in range.
038     */
039    public static boolean displayCasesWithMessage(int max, int min, Collection<CBRCase> cases)
040    {
041        return displayCases(max,min,cases,true);
042    }
043
044    /**
045     * Checks if the number of cases is inside a range.
046     * It does not show any message if the number of cases is not in range.
047     * @param max allowed cases
048     * @param min allowed cases
049     * @param cases received cases
050     * @return true if the number of cases is in range.
051     */
052    public static boolean displayCasesWithoutMessage(int max, int min, List<CBRCase> cases)
053    {
054        return displayCases(max,min,cases,false);       
055    }
056
057    /**
058     * Checks if the number of cases is inside a range.
059     * @param max allowed cases
060     * @param min allowed cases
061     * @param cases received cases
062     * @param showMessage indicates if messages should be shown.
063     * @return true if the number of cases is in range.
064     */
065    public static boolean displayCases(int max, int min, Collection<CBRCase> cases, boolean showMessage)
066    {
067        int size = cases.size();
068
069        if(size<min)
070        {
071            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);
072            return false;
073        }
074        else if(size>max)
075        {
076            if(showMessage)
077                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);
078            return false;
079        }
080        return true;
081
082    }
083}