]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/types/ApplicationResourceComparator.java
Big changes: change EventMap, move the stop/stopOutsourced/delayed/start/startOutsour...
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / types / ApplicationResourceComparator.java
1 package at.ac.tuwien.lsdc.types;
2
3 import java.util.Comparator;
4
5 public class ApplicationResourceComparator implements Comparator<Application> {
6
7         final int BEFORE = -1;
8         final int EQUAL = 0;
9         final int AFTER = 1;
10
11         @Override
12         public int compare(Application a1, Application a2) {
13                 if (a1 == a2)
14                         return EQUAL;
15                 if (getResourceDifference(a1, a2) < 0)
16                         return BEFORE;
17                 else if (getResourceDifference(a1, a2) > 0)
18                         return AFTER;
19                 else
20                         return EQUAL;
21         }
22
23         public int getResourceDifference(Application a1, Application a2) {
24                 return a1.getSize() - a2.getSize() + a1.getRam() - a2.getRam() + a1.getCpu() - a2.getCpu();
25         }
26
27 }