Purge unused ByteBufWriteUtil methods 41/86741/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 14:57:49 +0000 (15:57 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:53:05 +0000 (16:53 +0100)
Most of these methods have an appropriate replacement in either
ByteBufUtils or ByteBuf, or are completely unused. Remove them
along with their tests.

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

index a788086fa36e09139201478bbddd705127e80838..28bfdac9696c01cf934e9165140fe573b0d0e249 100644 (file)
@@ -5,11 +5,9 @@
  * 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.util;
 
 import io.netty.buffer.ByteBuf;
-import java.math.BigInteger;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
@@ -18,10 +16,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
-import org.opendaylight.yangtools.yang.common.Uint16;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Utility class for ByteBuf's write methods.
@@ -62,171 +56,6 @@ public final class ByteBufWriteUtil {
         output.writeMedium(value != null ? value : 0);
     }
 
-    /**
-     * Writes 16-bit short <code>value</code> if not null, otherwise writes
-     * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 2.
-     *
-     * @param value
-     *            Short value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeShort(final Short value, final ByteBuf output) {
-        output.writeShort(value != null ? value : 0);
-    }
-
-    /**
-     * Writes 64-bit long <code>value</code> if not null, otherwise writes zeros
-     * to the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by
-     * 8.
-     *
-     * @param value
-     *            Long value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeLong(final Long value, final ByteBuf output) {
-        output.writeLong(value != null ? value : 0L);
-    }
-
-    /**
-     * Writes boolean <code>value</code> if not null, otherwise writes zero to
-     * the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 1.
-     *
-     * @param value
-     *            Boolean value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zero is written.
-     */
-    public static void writeBoolean(final Boolean value, final ByteBuf output) {
-        if (value != null) {
-            output.writeBoolean(value);
-        } else {
-            output.writeByte(0);
-        }
-    }
-
-    /**
-     * Writes unsigned byte <code>value</code> if not null, otherwise writes
-     * zero to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 1.
-     *
-     * @param value
-     *            Short value to be write to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     * @deprecated Use {@link #writeUnsignedByte(Uint8, ByteBuf)} instead.
-     */
-    @Deprecated(forRemoval = true)
-    public static void writeUnsignedByte(final Short value, final ByteBuf output) {
-        output.writeByte(value != null ? value : 0);
-    }
-
-    /**
-     * Writes unsigned byte <code>value</code> if not null, otherwise writes
-     * zero to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 1.
-     *
-     * @param value
-     *            Short value to be write to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeUnsignedByte(final Uint8 value, final ByteBuf output) {
-        output.writeByte(value != null ? value.byteValue() : 0);
-    }
-
-    /**
-     * Writes unsigned 16-bit short integer <code>value</code> if not null,
-     * otherwise writes zeros to the <code>output</code> ByteBuf. ByteBuf's
-     * writerIndex is increased by 2.
-     *
-     * @param value
-     *            Integer value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     * @deprecated Use {@link #writeUnsignedShort(Uint16, ByteBuf)} instead.
-     */
-    @Deprecated(forRemoval = true)
-    public static void writeUnsignedShort(final Integer value, final ByteBuf output) {
-        output.writeShort(value != null ? value.shortValue() : 0);
-    }
-
-    /**
-     * Writes unsigned 16-bit short integer <code>value</code> if not null,
-     * otherwise writes zeros to the <code>output</code> ByteBuf. ByteBuf's
-     * writerIndex is increased by 2.
-     *
-     * @param value
-     *            Integer value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeUnsignedShort(final Uint16 value, final ByteBuf output) {
-        output.writeShort(value != null ? value.shortValue() : 0);
-    }
-
-    /**
-     * Writes unsigned 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
-     *            Long value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     * @deprecated Use {@link #writeUnsignedInt(Uint32, ByteBuf)} instead.
-     */
-    @Deprecated(forRemoval = true)
-    public static void writeUnsignedInt(final Long value, final ByteBuf output) {
-        output.writeInt(value != null ? value.intValue() : 0);
-    }
-
-    /**
-     * Writes unsigned 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
-     *            Long value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeUnsignedInt(final Uint32 value, final ByteBuf output) {
-        output.writeInt(value != null ? value.intValue() : 0);
-    }
-
-    /**
-     * Writes unsigned 64-bit integer <code>value</code> if not null, otherwise
-     * writes zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 8.
-     *
-     * @param value
-     *            BigInteger value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     * @deprecated Use {@link #writeUnsignedLong(Uint64, ByteBuf)} instead.
-     */
-    @Deprecated(forRemoval = true)
-    public static void writeUnsignedLong(final BigInteger value, final ByteBuf output) {
-        output.writeLong(value != null ? value.longValue() : 0L);
-    }
-
-    /**
-     * Writes unsigned 64-bit integer <code>value</code> if not null, otherwise
-     * writes zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 8.
-     *
-     * @param value
-     *            BigInteger value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeUnsignedLong(final Uint64 value, final ByteBuf output) {
-        output.writeLong(value != null ? value.longValue() : 0L);
-    }
-
     /**
      * Writes IPv4 address if not null, otherwise writes zeros to the
      * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
index 6ca37cefa1d9d8b963177c0f810181b37647e70a..1ceee31bb94b01718ae6567a79b52da1094648bc 100644 (file)
@@ -5,24 +5,16 @@
  * 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.util;
 
 import static org.junit.Assert.assertArrayEquals;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
 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;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeLong;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeMedium;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedLong;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -32,20 +24,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
-import org.opendaylight.yangtools.yang.common.Uint16;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.opendaylight.yangtools.yang.common.Uint8;
 
 public class ByteBufWriteUtilTest {
-
-    private static final byte[] ONE_BYTE_ZERO = {0};
-
-    private static final byte[] TWO_BYTE_ZEROS = {0, 0};
-
-    private static final byte[] FOUR_BYTE_ZEROS = {0, 0, 0, 0};
-
-    private static final byte[] EIGHT_BYTE_ZEROS = { 0, 0, 0, 0, 0, 0, 0, 0 };
+    private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
 
     @Test
     public void testWriteIntegerValue() {
@@ -59,18 +40,6 @@ public class ByteBufWriteUtilTest {
         assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
     }
 
-    @Test
-    public void testWriteShortValue() {
-        final byte[] result = { 0, 5 };
-        final ByteBuf output = Unpooled.buffer(Short.BYTES);
-        writeShort((short) 5, output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeShort(null, output);
-        assertArrayEquals(TWO_BYTE_ZEROS, output.array());
-    }
-
     @Test
     public void testWriteMediumValue() {
         final byte[] result = { 0, 0, 5 };
@@ -84,78 +53,6 @@ public class ByteBufWriteUtilTest {
         assertArrayEquals(resultZero, output.array());
     }
 
-    @Test
-    public void testWriteLongValue() {
-        final byte[] result = { 0, 0, 0, 0, 0, 0, 0, 5 };
-        final ByteBuf output = Unpooled.buffer(Long.BYTES);
-        writeLong((long) 5, output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeLong(null, output);
-        assertArrayEquals(EIGHT_BYTE_ZEROS, output.array());
-    }
-
-    @Test
-    public void testWriteBooleanValue() {
-        final byte[] result = { 1 };
-        final ByteBuf output = Unpooled.buffer(Byte.BYTES);
-        writeBoolean(true, output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeBoolean(null, output);
-        assertArrayEquals(ONE_BYTE_ZERO, output.array());
-    }
-
-    @Test
-    public void testWriteUnsignedByteValue() {
-        final byte[] result = { 5 };
-        final ByteBuf output = Unpooled.buffer(Byte.BYTES);
-        writeUnsignedByte(Uint8.valueOf(5), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeUnsignedByte((Uint8) null, output);
-        assertArrayEquals(ONE_BYTE_ZERO, output.array());
-    }
-
-    @Test
-    public void testWriteUnsignedShortValue() {
-        final byte[] result = { 0, 5 };
-        final ByteBuf output = Unpooled.buffer(Short.BYTES);
-        writeUnsignedShort(Uint16.valueOf(5), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeUnsignedShort((Uint16) null, output);
-        assertArrayEquals(TWO_BYTE_ZEROS, output.array());
-    }
-
-    @Test
-    public void testWriteUnsignedIntValue() {
-        final byte[] result = { 0, 0, 0, 5 };
-        final ByteBuf output = Unpooled.buffer(Integer.BYTES);
-        ByteBufWriteUtil.writeUnsignedInt(Uint32.valueOf(5), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeUnsignedInt((Uint32) null, output);
-        assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
-    }
-
-    @Test
-    public void testWriteUnsignedLongValue() {
-        final byte[] result = { 0, 0, 0, 0, 0, 0, 0, 5 };
-        final ByteBuf output = Unpooled.buffer(Long.BYTES);
-        writeUnsignedLong(Uint64.valueOf(5), output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        writeUnsignedLong((Uint64) null, output);
-        assertArrayEquals(EIGHT_BYTE_ZEROS, output.array());
-    }
-
     @Test
     public void testWriteIpv4Address() {
         final byte[] result = { 127, 0, 0, 1 };