From cbbeff857ca3a08dd6892979cfc70935e8fa4c8c Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Wed, 15 May 2013 21:33:49 +0200 Subject: [PATCH] Application now implements Comparable (compares timestamp of two apps) and SchedSimulator sorts the Application list --- src/at/ac/tuwien/lsdc/SchedSimulator.java | 2 ++ src/at/ac/tuwien/lsdc/types/Application.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/at/ac/tuwien/lsdc/SchedSimulator.java b/src/at/ac/tuwien/lsdc/SchedSimulator.java index aa59cef..83af4ee 100644 --- a/src/at/ac/tuwien/lsdc/SchedSimulator.java +++ b/src/at/ac/tuwien/lsdc/SchedSimulator.java @@ -2,6 +2,7 @@ package at.ac.tuwien.lsdc; import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.LinkedList; import org.slf4j.Logger; @@ -46,6 +47,7 @@ public class SchedSimulator { } } LinkedList apps = CSVParser.parseFile(inputFile); + Collections.sort(apps); AbstractScheduler scheduler; switch (schedulerType) { case A: diff --git a/src/at/ac/tuwien/lsdc/types/Application.java b/src/at/ac/tuwien/lsdc/types/Application.java index 8f465b4..b5ead0a 100644 --- a/src/at/ac/tuwien/lsdc/types/Application.java +++ b/src/at/ac/tuwien/lsdc/types/Application.java @@ -1,6 +1,6 @@ package at.ac.tuwien.lsdc.types; -public class Application { +public class Application implements Comparable { private int id; private long timestamp; @@ -46,4 +46,20 @@ public class Application { return new String("App ID: " + id + " Timestamp: " + timestamp + " size: " + size + " ram: " + ram + " cpu: " + cpu + " duration: " + duration); } + @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; + } + } -- 2.43.0