Applications now store their own nextID.
authorJan Vales <jan@jvales.net>
Thu, 13 Jun 2013 14:36:57 +0000 (16:36 +0200)
committerJan Vales <jan@jvales.net>
Thu, 13 Jun 2013 14:45:05 +0000 (16:45 +0200)
src/at/ac/tuwien/lsdc/types/Application.java

index 08d3334bfde23f27d8cf74b118fefdbdab473264..39119f0c13a4dd456c562d5ee22d010f48dc64eb 100644 (file)
@@ -1,81 +1,81 @@
 package at.ac.tuwien.lsdc.types;
 
 public class Application implements Comparable<Application> {
-
-       private int id;
-       private long timestamp;
-       private int size;
-       private int ram;
-       private int cpu;
-       private int duration;
-
-       private VirtualMachine runningOn;
-
-       public Application(int id, long timestamp, int size, int ram, int cpu, int duration) {
-               this.id = id;
-               this.timestamp = timestamp;
-               this.size = size;
-               this.ram = ram;
-               this.cpu = cpu;
-               this.duration = duration;
-       }
-
-       public int getID() {
-               return id;
-       }
-
-       public long getTimestamp() {
-               return timestamp;
-       }
-
-       public int getSize() {
-               return size;
-       }
-
-       public int getRam() {
-               return ram;
-       }
-
-       public int getCpu() {
-               return cpu;
-       }
-
-       public int getDuration() {
-               return duration;
-       }
-
-       @Override
-       public String toString() {
-               return new String("App ID: " + id + " Timestamp: " + timestamp + " size: " + size
-                               + " ram: " + ram + " cpu: " + cpu + " duration: " + duration);
-       }
-
-       public VirtualMachine getRunningOn() {
-               return runningOn;
-       }
-
-       public void setRunningOn(VirtualMachine vm) {
-               runningOn = vm;
-       }
-
-       @Override
-       public int compareTo(Application other) {
-               final int BEFORE = -1;
-               final int EQUAL = 0;
-               final int AFTER = 1;
-
-               // this optimization is usually worthwhile, and can
-               // always be added
-               if (this == other)
-                       return EQUAL;
-               if (this.getTimestamp() == other.getTimestamp())
-                       return EQUAL;
-               if (this.getTimestamp() < other.getTimestamp())
-                       return BEFORE;
-               if (this.getTimestamp() > other.getTimestamp())
-                       return AFTER;
-
-               return EQUAL;
-       }
+  static private int nextid = 0;
+  private int id;
+  private long timestamp;
+  private int size;
+  private int ram;
+  private int cpu;
+  private int duration;
+
+  private VirtualMachine runningOn;;
+
+  public Application(long timestamp, int size, int ram, int cpu, int duration) {
+    id = ++nextid;
+    this.timestamp = timestamp;
+    this.size = size;
+    this.ram = ram;
+    this.cpu = cpu;
+    this.duration = duration;
+  }
+
+  public int getID() {
+    return id;
+  }
+
+  public long getTimestamp() {
+    return timestamp;
+  }
+
+  public int getSize() {
+    return size;
+  }
+
+  public int getRam() {
+    return ram;
+  }
+
+  public int getCpu() {
+    return cpu;
+  }
+
+  public int getDuration() {
+    return duration;
+  }
+
+  @Override
+  public String toString() {
+    return new String("App ID: " + id + " Timestamp: " + timestamp + " size: " + size + " ram: " + ram + " cpu: " + cpu
+        + " duration: " + duration);
+  }
+
+  public VirtualMachine getRunningOn() {
+    return runningOn;
+  }
+
+  public void setRunningOn(VirtualMachine vm) {
+    runningOn = vm;
+  }
+
+  @Override
+  public int compareTo(Application other) {
+    final int BEFORE = -1;
+    final int EQUAL = 0;
+    final int AFTER = 1;
+
+    // this optimization is usually worthwhile, and can
+    // always be added
+    if (this == other)
+      return EQUAL;
+    if (getTimestamp() == other.getTimestamp())
+      return EQUAL;
+    if (getTimestamp() < other.getTimestamp())
+      return BEFORE;
+    if (getTimestamp() > other.getTimestamp())
+      return AFTER;
+
+    return EQUAL;
+  }
 
 }