Charles M.C. Chan
Committed by Pavlin Radoslavov

Refactor: Avoid using ternary operator. Remove unnecessary casting.

	* Apply suggestion in #2192 to previous implemented classes

Change-Id: I271d64202dd43968825600cd9afc49eb400371bf
......@@ -121,7 +121,10 @@ public class ICMP6 extends BasePacket {
payloadData = this.payload.serialize();
}
int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
int payloadLength = 0;
if (payloadData != null) {
payloadLength = payloadData.length;
}
final byte[] data = new byte[HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......
......@@ -218,7 +218,10 @@ public class IPv6 extends BasePacket implements IExtensionHeader {
payloadData = this.payload.serialize();
}
this.payloadLength = payloadData == null ? 0 : (short) payloadData.length;
this.payloadLength = 0;
if (payloadData != null) {
this.payloadLength = (short) payloadData.length;
}
final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......
......@@ -125,7 +125,10 @@ public class NeighborAdvertisement extends BasePacket {
payloadData = this.payload.serialize();
}
int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
int payloadLength = 0;
if (payloadData != null) {
payloadLength = payloadData.length;
}
final byte[] data = new byte[HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......
......@@ -62,7 +62,10 @@ public class NeighborSolicitation extends BasePacket {
payloadData = this.payload.serialize();
}
int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
int payloadLength = 0;
if (payloadData != null) {
payloadLength = payloadData.length;
}
final byte[] data = new byte[HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......
......@@ -83,7 +83,10 @@ public class Redirect extends BasePacket {
payloadData = this.payload.serialize();
}
int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
int payloadLength = 0;
if (payloadData != null) {
payloadLength = payloadData.length;
}
final byte[] data = new byte[HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......
......@@ -165,7 +165,10 @@ public class RouterAdvertisement extends BasePacket {
payloadData = this.payload.serialize();
}
int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
int payloadLength = 0;
if (payloadData != null) {
payloadLength = payloadData.length;
}
final byte[] data = new byte[HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......
......@@ -38,7 +38,10 @@ public class RouterSolicitation extends BasePacket {
payloadData = this.payload.serialize();
}
int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
int payloadLength = 0;
if (payloadData != null) {
payloadLength = payloadData.length;
}
final byte[] data = new byte[HEADER_LENGTH + payloadLength];
final ByteBuffer bb = ByteBuffer.wrap(data);
......