From 63a226dd22df257713865a01c9aa73a4208e3582 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 6 Jan 2020 16:01:15 +0100 Subject: [PATCH] Remove ByteBufWriteUtil.writeInt() 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 --- .../bmp/spi/parser/AbstractBmpMessageParser.java | 10 ++++------ .../protocol/util/ByteBufWriteUtil.java | 14 -------------- .../protocol/util/ByteBufWriteUtilTest.java | 13 ------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/bmp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpMessageParser.java b/bmp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpMessageParser.java index 531b92cf59..9443d796a2 100644 --- a/bmp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpMessageParser.java +++ b/bmp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpMessageParser.java @@ -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); } diff --git a/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java b/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java index 28bfdac969..a93d76021b 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java +++ b/util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java @@ -28,20 +28,6 @@ public final class ByteBufWriteUtil { // Hidden on purpose } - /** - * Writes 32-bit integer value if not null, otherwise writes - * zeros to the output 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 value if not null, otherwise writes * zeros to the output ByteBuf. ByteBuf's writerIndex is diff --git a/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java b/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java index 1ceee31bb9..68f6731c5f 100644 --- a/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java +++ b/util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java @@ -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 }; -- 2.36.6