]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/types/SortedApplication.java
move outsourced event handling from SchedulerB to AbstractScheduler
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / types / SortedApplication.java
1 package at.ac.tuwien.lsdc.types;
2
3 public class SortedApplication implements Comparable<SortedApplication> {
4
5         
6         private Application app;
7         final int BEFORE = -1;
8         final int EQUAL = 0;
9         final int AFTER = 1;
10         
11         public SortedApplication(Application app) {
12                 this.app = app;
13         }
14
15         @Override
16         public int compareTo(SortedApplication other) {
17                 if (this == other)
18                         return EQUAL;
19                 
20                 if(getResourceDifference(other) < 0)
21                         return BEFORE;
22                 else if(getResourceDifference(other) > 0)
23                         return AFTER;
24                 else
25                         return EQUAL;
26         }
27         
28         public Application getApp() {
29                 return app;
30         }
31         
32         public int getResourceDifference(SortedApplication other) {
33                 return  app.getSize() - other.getApp().getSize()  +
34                                 app.getRam() - other.getApp().getRam()  +
35                                 app.getCpu() - other.getApp().getCpu();
36         }
37         
38 }