]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/types/Application.java
GITOLITE.txt
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / types / Application.java
1 package at.ac.tuwien.lsdc.types;
2
3 public class Application implements Comparable<Application> {
4   static private int nextid = 0;
5   private int id;
6   private long timestamp;
7   private int size;
8   private int ram;
9   private int cpu;
10   private int duration;
11
12   private VirtualMachine runningOn;;
13
14   public Application(long timestamp, int size, int ram, int cpu, int duration) {
15     id = ++nextid;
16     this.timestamp = timestamp;
17     this.size = size;
18     this.ram = ram;
19     this.cpu = cpu;
20     this.duration = duration;
21   }
22
23   public int getID() {
24     return id;
25   }
26
27   public long getTimestamp() {
28     return timestamp;
29   }
30
31   public int getSize() {
32     return size;
33   }
34
35   public int getRam() {
36     return ram;
37   }
38
39   public int getCpu() {
40     return cpu;
41   }
42
43   public int getDuration() {
44     return duration;
45   }
46
47   @Override
48   public String toString() {
49     return new String("App ID: " + id + " Timestamp: " + timestamp + " size: " + size + " ram: " + ram + " cpu: " + cpu
50         + " duration: " + duration);
51   }
52
53   public VirtualMachine getRunningOn() {
54     return runningOn;
55   }
56
57   public void setRunningOn(VirtualMachine vm) {
58     runningOn = vm;
59   }
60
61   @Override
62   public int compareTo(Application other) {
63     final int BEFORE = -1;
64     final int EQUAL = 0;
65     final int AFTER = 1;
66
67     // this optimization is usually worthwhile, and can
68     // always be added
69     if (this == other)
70       return EQUAL;
71     if (getTimestamp() == other.getTimestamp())
72       return EQUAL;
73     if (getTimestamp() < other.getTimestamp())
74       return BEFORE;
75     if (getTimestamp() > other.getTimestamp())
76       return AFTER;
77
78     return EQUAL;
79   }
80
81 }