Remove ByteBufWriteUtil.writeInt() 42/86742/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:01:15 +0000 (16:01 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:53:05 +0000 (16:53 +0100)
This method has only one user, which is using primitive int. Migrate
the user to ByteBuf.writeInt() and remove the now-unused method.

Change-Id: I9981e7f54d306ce18f2b8b693998b26e6a464f54
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bmp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpMessageParser.java
util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java
util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java

index 531b92cf590fd163b95ecd3179d1de6b6d1da7cd..9443d796a2ef7801e9b8ddd08c8d7d241fe21ff1 100644 (file)
@@ -5,17 +5,15 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bmp.spi.parser;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.bmp.spi.parser.BmpMessageConstants.BMP_VERSION;
 import static org.opendaylight.protocol.bmp.spi.parser.BmpMessageConstants.COMMON_HEADER_LENGTH;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,7 +24,7 @@ public abstract class AbstractBmpMessageParser implements BmpMessageParser, BmpM
 
     @Override
     public final void serializeMessage(final Notification message, final ByteBuf buffer) {
-        Preconditions.checkArgument(message != null, "BMP message is mandatory.");
+        checkArgument(message != null, "BMP message is mandatory.");
         final ByteBuf bodyBuffer = Unpooled.buffer();
         serializeMessageBody(message, bodyBuffer);
         formatMessage(bodyBuffer, buffer);
@@ -35,7 +33,7 @@ public abstract class AbstractBmpMessageParser implements BmpMessageParser, BmpM
 
     @Override
     public final Notification parseMessage(final ByteBuf bytes) throws BmpDeserializationException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable());
+        checkArgument(bytes != null && bytes.isReadable());
         final Notification parsedMessage = parseMessageBody(bytes);
         LOG.trace("Parsed BMP message: {}", parsedMessage);
         return parsedMessage;
@@ -43,7 +41,7 @@ public abstract class AbstractBmpMessageParser implements BmpMessageParser, BmpM
 
     private void formatMessage(final ByteBuf body, final ByteBuf output) {
         output.writeByte(BMP_VERSION);
-        ByteBufWriteUtil.writeInt(body.writerIndex() + COMMON_HEADER_LENGTH, output);
+        output.writeInt(body.writerIndex() + COMMON_HEADER_LENGTH);
         output.writeByte(getBmpMessageType());
         output.writeBytes(body);
     }
index 28bfdac9696c01cf934e9165140fe573b0d0e249..a93d76021b750715d1378d1d6e88e72000adf65f 100644 (file)
@@ -28,20 +28,6 @@ public final class ByteBufWriteUtil {
         // Hidden on purpose
     }
 
-    /**
-     * Writes 32-bit integer <code>value</code> if not null, otherwise writes
-     * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 4.
-     *
-     * @param value
-     *            Integer value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeInt(final Integer value, final ByteBuf output) {
-        output.writeInt(value != null ? value : 0);
-    }
-
     /**
      * Writes 24-bit integer <code>value</code> if not null, otherwise writes
      * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
index 1ceee31bb94b01718ae6567a79b52da1094648bc..68f6731c5fae36da6d9c52c9def3e5c8d97fdc1f 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.util;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeInt;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
@@ -28,18 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.
 public class ByteBufWriteUtilTest {
     private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
 
-    @Test
-    public void testWriteIntegerValue() {
-        final byte[] result = { 0, 0, 0, 5 };
-        final ByteBuf output = Unpooled.buffer(Integer.BYTES);
-        writeInt(5, output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeInt(null, output);
-        assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
-    }
-
     @Test
     public void testWriteMediumValue() {
         final byte[] result = { 0, 0, 5 };