title: Deciding to use Comparable or Comparator
body: <p>My program implements a <code>Product</code> class whose objects contain the following instance variables: <code>name</code>, <code>priority</code>, <code>price</code>, and <code>amount</code>.</p>
  
  <p>I have a <code>LinkedList</code> of <code>Product</code> objects that I need to sort before doing any other operations on the <code>LinkedList</code>.</p>
  
  <p>I want to sort the list first by priority (from lowest to highest). If priority is the same, then look at the price (lowest to highest), then the name (alphabetical order).</p>
  
  <p>I have done a lot of reading about <code>Collections.sort</code>, <code>Comparable</code>, and <code>Comparator</code>. I believe I need to use the <code>Comparable</code> interface and implement a <code>compareTo</code> method. My thinking is that because both <code>priority</code>, <code>price</code>, and <code>name</code> have a "natural" ordering it makes more sense to use <code>Comparable</code>.</p>
  
  <pre><code>public class Product extends ProductBase implements PrintInterface, Comparable&lt;Product&gt;{
      private String name;
      private int priority; 
      private int cents;
      private int quantity;
  
      // setters and getters
  
      /**
      * Compare current Product object with compareToThis
      * return 0 if priority, price and name are the same for both  
      * return -1 if current Product is less than compareToThis
      * return 1 if current Product is greater than compareToThis
      */ 
  
      @override
      public int compareTo(Product compareToThis)
  }
  </code></pre>
  
  <p>Then when I want to sort my LinkedList I just call <code>Collections.sort(LinkedList)</code>. Before I start writing the code, can you tell me if I am I missing or forgetting anything?</p>
  
  <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>****</strong><em>UPDATE</em><strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em></strong></p>
  
  <p>I just created a separate class called ProductComparator with a compare method.</p>
  
  <p>This is part of the LinkedList class..</p>
  
  <pre><code>import java.util.Collections;
  
  public class LinkedList {
  
  private ListNode head; 
  
  public LinkedList() { 
      head = null;
  }
       // this method will sort the LinkedList using a ProductComparator
  public void sortList() {
      ListNode position = head;
      if (position != null) {
          Collections.sort(this, new ProductComparator());
      }
  }
  // ListNode inner class
  private class ListNode {
  
      private Product item;
      private ListNode link;
  
      // constructor
      public ListNode(Product newItem, ListNode newLink) {
          item= newItem;
          link = newLink;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am getting the following error from the IDE when I compile.  </p>
  
  <p>The method sort(List, Comparator) in the type Collections is not applicable for the arguments (LinkedList, ProductComparator). </p>
  
  <p>Does anyone know why I am getting this error and can point me in the right direction to resolve it?</p>