001package algs25;
002//import stdlib.*;
003import algs13.Queue;
004
005/* ***********************************************************************
006 *  Compilation:  javac Processor.java
007 *  Execution:    java Processor
008 *
009 *  XProcessor data type represents a processor with a list of
010 *  jobs, each of integer length. Its load is the total amount
011 *  of processing time.
012 *
013 *  The client program finds an approximate solution to the load balancing
014 *  problem using the LPT (longest processing time first) rule.
015 *
016 *************************************************************************/
017
018public class XProcessor implements Comparable<XProcessor> {
019        private double load = 0;
020        private final Queue<XJob> list = new Queue<>();
021
022        public void add(XJob job) {
023                list.enqueue(job);
024                load += job.time();
025        }
026
027        public int compareTo(XProcessor that) {
028                if (this.load < that.load) return -1;
029                if (this.load > that.load) return +1;
030                return 0;
031        }
032
033        public String toString() {
034                String s = load + ": ";
035                for (XJob x : list)
036                        s += x + " ";
037                return s;
038        }
039
040}