/** Class SortFilter
 *
 * This is the "main" class for our group.
 *
 * Takes a set of rules and applies them to message lists
 *
 * Some of the get and set methods may not be needed, but we are including them for now.  The
 * unneeded ones will be deleted during the implementation phase.
 * 
 * @author Chris Kern
 * @author Erin Nichols
 * @author Joe Simonson
 * @version 0.20 of Oct 1999
 */

public class SortFilter {

 
    /*+------------+
     *+   Fields   +
     *+------------+
     */

    //ConditionSet rules;
    
    /*+--------------+
     *+ Constructors +
     *+--------------+
     */

    public SortFilter() {

        /* Supply default rule set */

    }

    // public SortFilter(ConditionSet ruleset) {

//         /* Takes ruleset from home directory */

//     }


    /*+-----------+
     *|  Methods  |
     *+-----------+
     */
    
    // public void setConditionSet(ConditionSet newRules) {

//         rules = newRules;

//     }

    /** Purpose       - Return the list of rules as a string
     * Parameters     - none
     * Preconditions  - none
     * Postconditions - No fields are changed.
     * Produces       - A string containing all of the rules to sort by.
     * Problems       - none
     */

//     public String toString() {

//     }

    /** Purpose       - Returns a sorted messagelist, given an unsorted message list, 
     *                  by the rule set sortBy.
     * Parameters     - A MessageInfoList, A method by which to sort the messages by, A method of comparing.
     * Preconditions  - listOfMessages is a valid MessageInfoList.
     * Postconditions - No fields are altered, sorts the existing MessageInfoList.
     * Produces       - A list of messages sorted according to the rule set.
     * Problems       - none
     */

    public void sort(MailMessage[] messages, 
                                    String method, Comparator compare) 
        throws Exception {

        Quicksortable sorter = new Quicksortable(messages);

        if(method.equals("date"))
            sorter.sort(new DateComparator());

        if(method.equals("subject"))
            sorter.sort(new SubjectComparator());

        if(method.equals("sender"))
            sorter.sort(new SenderComparator());

        if(method.equals("priority"))
        sorter.sort(new PriorityComparator());

        if(method.equals("status"))
            sorter.sort(new StatusComparator());

        else throw new Exception();
    }

} // Class SortFilter

//   public AttachmentInfo getAttachmentInfo(int n) 
//     throws MessageException
// /* Write toString and sort. */

