瀏覽代碼

Adds PacketComparator for timestamp comparison

Andreas T. Meyer-Berg 6 年之前
父節點
當前提交
80f4e8359e

+ 9 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/ConnectionPrecision.java

@@ -5,6 +5,8 @@ import java.util.Comparator;
 import java.util.LinkedList;
 import java.util.ListIterator;
 
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.PacketComparator;
+
 /**
  * Implementation of the Connection Interface, with focus on precision
  *
@@ -114,9 +116,15 @@ public class ConnectionPrecision extends ConnectionPerformance {
 		/**
 		 * Sort and return packages
 		 */
-		returnPackets.sort((a,b)->(Long.compare(a.getTimestamp(),b.getTimestamp())));
+		returnPackets.sort(new PacketComparator());
 		return returnPackets;
 	}
+	
+	/**
+	 * Comparator for comparing the next trigger time of two ports, the lower one should trigger first
+	 *
+	 * @author Andreas T. Meyer-Berg
+	 */
 	private class PortComparator implements Comparator<Port>{
 
 		@Override

+ 18 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/util/PacketComparator.java

@@ -0,0 +1,18 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util;
+
+import java.util.Comparator;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+
+/**
+ * Comparator of Packet Timestamps for sorting packages
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class PacketComparator implements Comparator<Packet> {
+
+	@Override
+	public int compare(Packet o1, Packet o2) {
+		return Long.compare(o1.getTimestamp(),o2.getTimestamp());
+	}
+}