Eliminate ByteBufWriteUtil.writeMedium() 43/86743/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:06:43 +0000 (16:06 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 15:53:05 +0000 (16:53 +0100)
There are only two users of this method, both operating on primitive
type. Switch them to use ByteBuf.writeMedium() and eliminate the
now-unused method.

Change-Id: I22676f9a2e03f2f5603f46d59fb301b59fc34b29
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/extensions/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/esi/types/MacParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java
util/src/main/java/org/opendaylight/protocol/util/ByteBufWriteUtil.java
util/src/test/java/org/opendaylight/protocol/util/ByteBufWriteUtilTest.java

index 7633410c8af1987255f86754218dd8fc3478c822..100fbe49b293cb21b55143729506f879b6c2cdaf 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.bgp.evpn.impl.esi.types;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractSystmeMac;
 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractUint24LD;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ByteBufUtils;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
@@ -29,11 +27,11 @@ final class MacParser extends AbstractEsiType {
 
     @Override
     public ByteBuf serializeBody(final Esi esi, final ByteBuf body) {
-        Preconditions.checkArgument(esi instanceof MacAutoGeneratedCase,
-                "Unknown esi instance. Passed %s. Needed MacAutoGeneratedCase.", esi.getClass());
+        checkArgument(esi instanceof MacAutoGeneratedCase,
+            "Unknown esi instance. Passed %s. Needed MacAutoGeneratedCase.", esi.getClass());
         final MacAutoGenerated macAuto = ((MacAutoGeneratedCase) esi).getMacAutoGenerated();
         body.writeBytes(IetfYangUtil.INSTANCE.macAddressBytes(macAuto.getSystemMacAddress()));
-        ByteBufWriteUtil.writeMedium(macAuto.getLocalDiscriminator().getValue().intValue(), body);
+        body.writeMedium(macAuto.getLocalDiscriminator().getValue().intValue());
         return body;
     }
 
index 9e9447d8aeb1adbad227a202f651a36ee4525904..e164f5540baaf33a85ec7d40527caa5307ee991a 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeMedium;
 
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
@@ -116,8 +115,9 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
             object.getClass());
         final Lsp specObj = (Lsp) object;
         final ByteBuf body = Unpooled.buffer();
-        checkArgument(specObj.getPlspId() != null, "PLSP-ID not present");
-        writeMedium(specObj.getPlspId().getValue().intValue() << FOUR_BITS_SHIFT, body);
+        final PlspId plspId = specObj.getPlspId();
+        checkArgument(plspId != null, "PLSP-ID not present");
+        body.writeMedium(plspId.getValue().intValue() << FOUR_BITS_SHIFT);
         final BitArray flags = serializeFlags(specObj);
         byte op = 0;
         if (specObj.getOperational() != null) {
index a93d76021b750715d1378d1d6e88e72000adf65f..fd8e64e92f25efa91da744345397f38291cb2aaf 100644 (file)
@@ -28,20 +28,6 @@ public final class ByteBufWriteUtil {
         // Hidden on purpose
     }
 
-    /**
-     * Writes 24-bit integer <code>value</code> if not null, otherwise writes
-     * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
-     * increased by 3.
-     *
-     * @param value
-     *            Medium value to be written to the output.
-     * @param output
-     *            ByteBuf, where value or zeros are written.
-     */
-    public static void writeMedium(final Integer value, final ByteBuf output) {
-        output.writeMedium(value != null ? value : 0);
-    }
-
     /**
      * Writes IPv4 address if not null, otherwise writes zeros to the
      * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
index 68f6731c5fae36da6d9c52c9def3e5c8d97fdc1f..4213e99979d048b9ed52ef94233e9a88bf770aaf 100644 (file)
@@ -13,7 +13,6 @@ 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.writeMedium;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -27,19 +26,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 testWriteMediumValue() {
-        final byte[] result = { 0, 0, 5 };
-        final ByteBuf output = Unpooled.buffer(3);
-        writeMedium(5, output);
-        assertArrayEquals(result, output.array());
-
-        output.clear();
-        final byte[] resultZero = { 0, 0, 0 };
-        writeMedium(null, output);
-        assertArrayEquals(resultZero, output.array());
-    }
-
     @Test
     public void testWriteIpv4Address() {
         final byte[] result = { 127, 0, 0, 1 };