From 2056201f1ac3be542788b4b34f439d5eed78f3df Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Thu, 13 Jun 2013 16:36:57 +0200 Subject: [PATCH] Applications now store their own nextID. --- src/at/ac/tuwien/lsdc/types/Application.java | 152 +++++++++---------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/types/Application.java b/src/at/ac/tuwien/lsdc/types/Application.java index 08d3334..39119f0 100644 --- a/src/at/ac/tuwien/lsdc/types/Application.java +++ b/src/at/ac/tuwien/lsdc/types/Application.java @@ -1,81 +1,81 @@ package at.ac.tuwien.lsdc.types; public class Application implements Comparable { - - 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; + } } -- 2.43.0