pcap: use NonNullUtils.equalsNullable in packet equals
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 2 Apr 2015 19:35:47 +0000 (15:35 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 2 Apr 2015 23:54:22 +0000 (19:54 -0400)
Change-Id: Ie1e96a72b378d3ad2f9b3f90000acf201bd4a2c2
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/45173
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/ethernet2/EthernetIIPacket.java
org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/ipv4/IPv4Packet.java
org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/pcap/PcapPacket.java
org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/tcp/TCPPacket.java
org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/udp/UDPPacket.java
org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/unknown/UnknownPacket.java

index f2957b593698909c4b9e4f09a4c9a88b56134df7..24e35d154a8e6141d9956eb1b7d9fca9a8e11479 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
 import org.eclipse.tracecompass.internal.pcap.core.packet.Packet;
 import org.eclipse.tracecompass.internal.pcap.core.protocol.PcapProtocol;
@@ -262,41 +263,16 @@ public class EthernetIIPacket extends Packet {
             return false;
         }
         EthernetIIPacket other = (EthernetIIPacket) obj;
-        if (fChildPacket == null) {
-            if (other.fChildPacket != null) {
-                return false;
-            }
-        } else {
-            final Packet child = fChildPacket;
-            if (child != null) {
-                if (!child.equals(other.fChildPacket)) {
-                    return false;
-                }
-            } else {
-                if (other.fChildPacket != null) {
-                    return false;
-                }
-            }
+        if(!NonNullUtils.equalsNullable(fChildPacket, other.fChildPacket)) {
+            return false;
         }
         if (!Arrays.equals(fDestinationMacAddress, other.fDestinationMacAddress)) {
             return false;
         }
-        if (fPayload == null) {
-            if (other.fPayload != null) {
-                return false;
-            }
-        } else {
-            final ByteBuffer payload = fPayload;
-            if (payload != null) {
-                if (!payload.equals(other.fPayload)) {
-                    return false;
-                }
-            } else {
-                if (other.fPayload != null) {
-                    return false;
-                }
-            }
+        if(!NonNullUtils.equalsNullable(fPayload, other.fPayload)) {
+            return false;
         }
+
         if (!Arrays.equals(fSourceMacAddress, other.fSourceMacAddress)) {
             return false;
         }
index 365004c56b330bfb11fc9c4f5eeca53edf4c178c..0a8fa38a55cec1ced8fae07a3dd180d528f5f192 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
 import org.eclipse.tracecompass.internal.pcap.core.packet.Packet;
 import org.eclipse.tracecompass.internal.pcap.core.protocol.PcapProtocol;
@@ -570,17 +571,9 @@ public class IPv4Packet extends Packet {
             return false;
         }
         IPv4Packet other = (IPv4Packet) obj;
-        final Packet child = fChildPacket;
-        if (child != null) {
-            if (!child.equals(other.fChildPacket)) {
-                return false;
-            }
-        } else {
-            if (other.fChildPacket != null) {
-                return false;
-            }
+        if (!NonNullUtils.equalsNullable(fChildPacket, other.fChildPacket)) {
+            return false;
         }
-
         if (fDSCP != other.fDSCP) {
             return false;
         }
@@ -614,15 +607,8 @@ public class IPv4Packet extends Packet {
         if (!Arrays.equals(fOptions, other.fOptions)) {
             return false;
         }
-        final ByteBuffer payload = fPayload;
-        if (payload != null) {
-            if (!payload.equals(other.fPayload)) {
-                return false;
-            }
-        } else {
-            if (other.fPayload != null) {
-                return false;
-            }
+        if (!NonNullUtils.equalsNullable(fPayload, other.fPayload)) {
+            return false;
         }
         if (fReservedFlag != other.fReservedFlag) {
             return false;
@@ -641,5 +627,4 @@ public class IPv4Packet extends Packet {
         }
         return true;
     }
-
 }
index 237a7c07588410d89b7bb1e062989b50ecb71e46..be6ae08961efa94dbc239fac63753581e528cce8 100644 (file)
@@ -323,17 +323,9 @@ public class PcapPacket extends Packet {
             return false;
         }
         PcapPacket other = (PcapPacket) obj;
-        final Packet child = fChildPacket;
-        if (child != null) {
-            if (!child.equals(other.fChildPacket)) {
-                return false;
-            }
-        } else {
-            if (other.fChildPacket != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fChildPacket, other.fChildPacket)){
+            return false;
         }
-
         if (fIncludedLength != other.fIncludedLength) {
             return false;
         }
@@ -343,17 +335,9 @@ public class PcapPacket extends Packet {
         if (fPacketIndex != other.fPacketIndex) {
             return false;
         }
-        final ByteBuffer payload = fPayload;
-        if (payload != null) {
-            if (!payload.equals(other.fPayload)) {
-                return false;
-            }
-        } else {
-            if (other.fPayload != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fPayload, other.fPayload)) {
+            return false;
         }
-
         if (fTimestamp != other.fTimestamp) {
             return false;
         }
index bcf86b36b7a55c6775b843301aa46f25e5c0c591..a068700c77b2bf58aa3a2c941cedf481d14ae922 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.pcap.core.packet.BadPacketException;
 import org.eclipse.tracecompass.internal.pcap.core.packet.Packet;
 import org.eclipse.tracecompass.internal.pcap.core.protocol.PcapProtocol;
@@ -629,17 +630,9 @@ public class TCPPacket extends Packet {
         if (fChecksum != other.fChecksum) {
             return false;
         }
-        final Packet child = fChildPacket;
-        if (child != null) {
-            if (!child.equals(other.fChildPacket)) {
-                return false;
-            }
-        } else {
-            if (other.fChildPacket != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fChildPacket, other.fChildPacket)){
+            return false;
         }
-
         if (fDataOffset != other.fDataOffset) {
             return false;
         }
@@ -661,15 +654,8 @@ public class TCPPacket extends Packet {
         if (fPSHFlag != other.fPSHFlag) {
             return false;
         }
-        final ByteBuffer fPayload2 = fPayload;
-        if (fPayload2 != null) {
-            if (!fPayload2.equals(other.fPayload)) {
-                return false;
-            }
-        } else {
-            if (other.fPayload != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fPayload, other.fPayload)){
+            return false;
         }
         if (fRSTFlag != other.fRSTFlag) {
             return false;
index a0507de11f40986bba5f42231b8ca3e29e01bfcb..1abbf0a166122c830add5d4db33ffd37691389eb 100644 (file)
@@ -265,28 +265,14 @@ public class UDPPacket extends Packet {
         if (fChecksum != other.fChecksum) {
             return false;
         }
-        final Packet child = fChildPacket;
-        if (child != null) {
-            if (!child.equals(other.fChildPacket)) {
-                return false;
-            }
-        } else {
-            if (other.fChildPacket != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fChildPacket, other.fChildPacket)){
+            return false;
         }
         if (fDestinationPort != other.fDestinationPort) {
             return false;
         }
-        final ByteBuffer payload = fPayload;
-        if (payload != null) {
-            if (!payload.equals(other.fPayload)) {
-                return false;
-            }
-        } else {
-            if (other.fPayload != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fPayload, other.fPayload)){
+            return false;
         }
         if (fSourcePort != other.fSourcePort) {
             return false;
index 645484f46845cfa9b601f80d9ed2dbca5134cbf4..bc48eab9f25c5d27a2f4405efd5abe34a3f2b135 100644 (file)
@@ -19,6 +19,7 @@ import java.nio.ByteBuffer;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.pcap.core.packet.Packet;
 import org.eclipse.tracecompass.internal.pcap.core.protocol.PcapProtocol;
 import org.eclipse.tracecompass.internal.pcap.core.trace.PcapFile;
@@ -190,17 +191,9 @@ public class UnknownPacket extends Packet {
             return false;
         }
         UnknownPacket other = (UnknownPacket) obj;
-        final Packet child = fChildPacket;
-        if (child != null) {
-            if (!child.equals(other.fChildPacket)) {
-                return false;
-            }
-        } else {
-            if (other.fChildPacket != null) {
-                return false;
-            }
+        if(!NonNullUtils.equalsNullable(fChildPacket, other.fChildPacket)){
+            return false;
         }
-
         if (!fPayload.equals(other.fPayload)) {
             return false;
         }
This page took 0.044329 seconds and 5 git commands to generate.