Conversation.java: make Direction enum public, and add toCompactString method.
authorJanus Varmarken <varmarken@gmail.com>
Sun, 19 Aug 2018 04:34:14 +0000 (21:34 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Sun, 19 Aug 2018 07:07:34 +0000 (00:07 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Conversation.java

index c227ce7f5f53ce9ea463d8a331abefda1ea5b48b..e7ebf3b13ede9e8799825d2b1a23dd9b4dbfe1e1 100644 (file)
@@ -442,11 +442,13 @@ public class Conversation {
     }
 
     /**
-     * Determine the direction of {@code packet}.
+     * Determine the direction of {@code packet}. An {@link IllegalArgumentException} is thrown if {@code packet} does
+     * not pertain to this conversation.
+     *
      * @param packet The packet whose direction is to be determined.
      * @return A {@link Direction} indicating the direction of the packet.
      */
-    private Direction getDirection(PcapPacket packet) {
+    public Direction getDirection(PcapPacket packet) {
         IpV4Packet ipPacket = packet.get(IpV4Packet.class);
         String ipSrc = ipPacket.getHeader().getSrcAddr().getHostAddress();
         String ipDst = ipPacket.getHeader().getDstAddr().getHostAddress();
@@ -465,8 +467,28 @@ public class Conversation {
     /**
      * Utility enum for expressing the direction of a packet pertaining to this {@code Conversation}.
      */
-    private enum Direction {
-        CLIENT_TO_SERVER, SERVER_TO_CLIENT
+    public enum Direction {
+
+        CLIENT_TO_SERVER {
+            @Override
+            public String toCompactString() {
+                return "C->S";
+            }
+        },
+        SERVER_TO_CLIENT {
+            @Override
+            public String toCompactString() {
+                return "S->C";
+            }
+        };
+
+
+        /**
+         * Get a compact string representation of this {@code Direction}.
+         * @return a compact string representation of this {@code Direction}.
+         */
+        abstract public String toCompactString();
+
     }
 
-}
\ No newline at end of file
+}