Committed by
Pavlin Radoslavov
Refactor: Avoid using ternary operator. Remove unnecessary casting.
* Apply suggestion in #2192 to previous implemented classes Change-Id: I271d64202dd43968825600cd9afc49eb400371bf
Showing
7 changed files
with
28 additions
and
7 deletions
... | @@ -121,7 +121,10 @@ public class ICMP6 extends BasePacket { | ... | @@ -121,7 +121,10 @@ public class ICMP6 extends BasePacket { |
121 | payloadData = this.payload.serialize(); | 121 | payloadData = this.payload.serialize(); |
122 | } | 122 | } |
123 | 123 | ||
124 | - int payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 124 | + int payloadLength = 0; |
125 | + if (payloadData != null) { | ||
126 | + payloadLength = payloadData.length; | ||
127 | + } | ||
125 | 128 | ||
126 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; | 129 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; |
127 | final ByteBuffer bb = ByteBuffer.wrap(data); | 130 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
... | @@ -218,7 +218,10 @@ public class IPv6 extends BasePacket implements IExtensionHeader { | ... | @@ -218,7 +218,10 @@ public class IPv6 extends BasePacket implements IExtensionHeader { |
218 | payloadData = this.payload.serialize(); | 218 | payloadData = this.payload.serialize(); |
219 | } | 219 | } |
220 | 220 | ||
221 | - this.payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 221 | + this.payloadLength = 0; |
222 | + if (payloadData != null) { | ||
223 | + this.payloadLength = (short) payloadData.length; | ||
224 | + } | ||
222 | 225 | ||
223 | final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; | 226 | final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; |
224 | final ByteBuffer bb = ByteBuffer.wrap(data); | 227 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
... | @@ -125,7 +125,10 @@ public class NeighborAdvertisement extends BasePacket { | ... | @@ -125,7 +125,10 @@ public class NeighborAdvertisement extends BasePacket { |
125 | payloadData = this.payload.serialize(); | 125 | payloadData = this.payload.serialize(); |
126 | } | 126 | } |
127 | 127 | ||
128 | - int payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 128 | + int payloadLength = 0; |
129 | + if (payloadData != null) { | ||
130 | + payloadLength = payloadData.length; | ||
131 | + } | ||
129 | 132 | ||
130 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; | 133 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; |
131 | final ByteBuffer bb = ByteBuffer.wrap(data); | 134 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
... | @@ -62,7 +62,10 @@ public class NeighborSolicitation extends BasePacket { | ... | @@ -62,7 +62,10 @@ public class NeighborSolicitation extends BasePacket { |
62 | payloadData = this.payload.serialize(); | 62 | payloadData = this.payload.serialize(); |
63 | } | 63 | } |
64 | 64 | ||
65 | - int payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 65 | + int payloadLength = 0; |
66 | + if (payloadData != null) { | ||
67 | + payloadLength = payloadData.length; | ||
68 | + } | ||
66 | 69 | ||
67 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; | 70 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; |
68 | final ByteBuffer bb = ByteBuffer.wrap(data); | 71 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
... | @@ -83,7 +83,10 @@ public class Redirect extends BasePacket { | ... | @@ -83,7 +83,10 @@ public class Redirect extends BasePacket { |
83 | payloadData = this.payload.serialize(); | 83 | payloadData = this.payload.serialize(); |
84 | } | 84 | } |
85 | 85 | ||
86 | - int payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 86 | + int payloadLength = 0; |
87 | + if (payloadData != null) { | ||
88 | + payloadLength = payloadData.length; | ||
89 | + } | ||
87 | 90 | ||
88 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; | 91 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; |
89 | final ByteBuffer bb = ByteBuffer.wrap(data); | 92 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
... | @@ -165,7 +165,10 @@ public class RouterAdvertisement extends BasePacket { | ... | @@ -165,7 +165,10 @@ public class RouterAdvertisement extends BasePacket { |
165 | payloadData = this.payload.serialize(); | 165 | payloadData = this.payload.serialize(); |
166 | } | 166 | } |
167 | 167 | ||
168 | - int payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 168 | + int payloadLength = 0; |
169 | + if (payloadData != null) { | ||
170 | + payloadLength = payloadData.length; | ||
171 | + } | ||
169 | 172 | ||
170 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; | 173 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; |
171 | final ByteBuffer bb = ByteBuffer.wrap(data); | 174 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
... | @@ -38,7 +38,10 @@ public class RouterSolicitation extends BasePacket { | ... | @@ -38,7 +38,10 @@ public class RouterSolicitation extends BasePacket { |
38 | payloadData = this.payload.serialize(); | 38 | payloadData = this.payload.serialize(); |
39 | } | 39 | } |
40 | 40 | ||
41 | - int payloadLength = payloadData == null ? 0 : (short) payloadData.length; | 41 | + int payloadLength = 0; |
42 | + if (payloadData != null) { | ||
43 | + payloadLength = payloadData.length; | ||
44 | + } | ||
42 | 45 | ||
43 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; | 46 | final byte[] data = new byte[HEADER_LENGTH + payloadLength]; |
44 | final ByteBuffer bb = ByteBuffer.wrap(data); | 47 | final ByteBuffer bb = ByteBuffer.wrap(data); | ... | ... |
-
Please register or login to post a comment