/* Sample solution to SE304 Lab 2
** Author: Margaret McGaley
** Ammended by: Gareth Carter
** Questions 4 & 5 can be found within
*/

package dbcvote;

public class Preference implements Comparable {
      private /*@ non_null @*/ String name;
      private /*@ spec_public @*/ int pref;

      /*@ invariant pref > 0; @*/

 //     private Preference() {};

      public Preference(String name, int pref) {
             this.name = name;
             this.pref = pref;
      }

      public /*@ pure non_null @*/String getName() {
             return name;
      }

      public /*@ pure @*/ int getPref() {
             return pref;
      }

      public /*@ pure @*/ int compareTo(Object o) {
             Preference p = (Preference) o;
             int p_pref = p.getPref();

             if (pref < p_pref) {
                return -1;
             }
             else if (pref == p_pref) {
                return 0;
             }
             else {
                return 1;
            }
      }

      public /*@ pure non_null @*/ String toString() {
             return name + " " + pref + "\n";
      }
}

