Advertisement
binibiningtinamoran

Process

Nov 18th, 2019
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.51 KB | None | 0 0
  1. import java.util.Comparator;
  2.  
  3. public class Process {
  4.  
  5.     private int timeOfArrival;
  6.     private int timeToProcess;
  7.  
  8.     public Process() {
  9.         //default
  10.         this.timeOfArrival = 0;
  11.         this.timeToProcess = 0;
  12.     }
  13.     public Process(int arrival, int processing) {
  14.  
  15.         this.timeOfArrival = arrival;
  16.         this.timeToProcess = processing;
  17.     }
  18.  
  19.     public void setArrival(int arrival) {
  20.  
  21.         this.timeOfArrival = arrival;
  22.     }
  23.  
  24.     public int getArrival() {
  25.         return timeOfArrival;
  26.     }
  27.  
  28.     public int getTimeToProcess() {
  29.         return timeToProcess;
  30.     }
  31.  
  32.     public void setTimeToProcess(int processing) {
  33.         this.timeToProcess = processing;
  34.     }
  35.  
  36.     public static final Comparator<Process> ARRIVAL_TIME_COMPARATOR = new ArrivalTimeComparator();
  37.     public static final Comparator<Process> PROCESS_TIME_COMPARATOR = new ProcessTimeComparator();
  38.  
  39.     private static class ArrivalTimeComparator implements Comparator<Process> {
  40.         public int compare(Process a, Process b) {
  41.             return Integer.compare(a.getArrival(),b.getArrival());
  42.         }
  43.     }
  44.  
  45.  
  46.     private static class ProcessTimeComparator implements Comparator<Process> {
  47.         public int compare(Process x, Process y) {
  48.             return Integer.compare(x.getTimeToProcess(), y.getTimeToProcess());
  49.         }
  50.     }
  51.  
  52.     @Override
  53.     public String toString() {
  54.         return "Arrival Time: " + timeOfArrival +
  55.                 "\nTime to Process: " + timeToProcess;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement