Remove ByteBufUtils.macAddressToBytes() 09/92709/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Sep 2020 08:49:49 +0000 (10:49 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Sep 2020 15:19:33 +0000 (17:19 +0200)
With all callers migrated, remove the now-unused method.

Change-Id: I65412717a28c393d3e31d2cda19d8becb3278dd7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
openflowjava/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ByteBufUtils.java
openflowjava/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ByteBufUtilsTest.java

index 1454c72830b1abde0ff0d7305c74a09eb82d669b..35878eb7a14695a889f6c5b8eade98d27917763b 100644 (file)
@@ -221,66 +221,6 @@ public abstract class ByteBufUtils {
         return sb.toString().trim();
     }
 
-    private static int hexValue(final char ch) {
-        if (ch >= '0' && ch <= '9') {
-            return ch - '0';
-        }
-        if (ch >= 'a' && ch <= 'f') {
-            return ch - 'a' + 10;
-        }
-        if (ch >= 'A' && ch <= 'F') {
-            return ch - 'A' + 10;
-        }
-
-        throw new IllegalArgumentException(String.format("Invalid character '%s' encountered", ch));
-    }
-
-    /**
-     * Converts macAddress to byte array. See also {@link MacAddress}.
-     *
-     * @param macAddress the mac address to convert
-     * @return byte representation of mac address
-     *
-     * @deprecated Use IetfYangUtil.macAddressBytes(MacAddress) instead.
-     */
-    @Deprecated(forRemoval = true)
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public static byte[] macAddressToBytes(final String macAddress) {
-        final byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
-        final char[] mac = macAddress.toCharArray();
-
-        try {
-            int offset = 0;
-            for (int i = 0; i < EncodeConstants.MAC_ADDRESS_LENGTH - 1; ++i) {
-                if (mac[offset + Byte.BYTES] == ':') {
-                    result[i] = UnsignedBytes.checkedCast(hexValue(mac[offset]));
-                    offset++;
-                } else {
-                    result[i] = UnsignedBytes.checkedCast(
-                            hexValue(mac[offset]) << 4 | hexValue(mac[offset + 1]));
-                    offset += 2;
-                }
-                Preconditions.checkArgument(mac[offset] == ':', "Invalid value: %s", macAddress);
-                offset++;
-            }
-
-            if (offset == mac.length - 1) {
-                result[EncodeConstants.MAC_ADDRESS_LENGTH - 1] = UnsignedBytes.checkedCast(hexValue(mac[offset]));
-            } else {
-                result[EncodeConstants.MAC_ADDRESS_LENGTH - 1] =
-                        UnsignedBytes.checkedCast(hexValue(mac[offset]) << 4 | hexValue(mac[offset + 1]));
-                offset++;
-            }
-            if (offset != mac.length - 1) {
-                throw new IllegalArgumentException("Incorrect MAC address length");
-            }
-        } catch (RuntimeException e) {
-            throw new IllegalArgumentException("Unable to serialize MAC address for input: " + macAddress
-                    + ". \n" + e);
-        }
-        return result;
-    }
-
     private static void appendHexByte(final StringBuilder sb, final byte value) {
         final int v = UnsignedBytes.toInt(value);
         sb.append(HEX_CHARS[v >>> 4]);
index b0fe37a300374678ce103fbebd01134a5b44769a..321ea1dbed3dacbcef6f74d66ac5429c78f9247d 100644 (file)
@@ -216,96 +216,6 @@ public class ByteBufUtilsTest {
         Assert.assertEquals("Strings does not match", expectedBinaryString, bitmaskValueInBinarySytring);
     }
 
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test
-    public void testMacToBytes() {
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{0, 1, 2, 3, (byte) 255, 5},
-                ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05"));
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 2, 3, 4, (byte) 255, 5},
-                ByteBufUtils.macAddressToBytes("01:02:03:04:FF:05"));
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 2, 3, 4, (byte) 255, 5},
-                ByteBufUtils.macAddressToBytes("1:2:3:4:FF:5"));
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 2, 3, 4, 5, (byte) 255},
-                ByteBufUtils.macAddressToBytes("1:2:3:4:5:FF"));
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 15, 3, 4, 5, 6},
-                ByteBufUtils.macAddressToBytes("1:F:3:4:5:6"));
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytes2() {
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{0, 1, 2, 3, (byte) 255, 5},
-                ByteBufUtils.macAddressToBytes("00:01:02:03:FF:0G"));
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytesTooShort() {
-        ByteBufUtils.macAddressToBytes("00:01:02:03:FF");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytesTooShort2() {
-        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testIncorrectMacToBytes() {
-        ByteBufUtils.macAddressToBytes("00:01:02:03:FF::");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testIncorrectMacToBytes2() {
-        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:::");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytesTooLong() {
-        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05:85");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytesInvalidOctet() {
-        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05d");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytesInvalidOctet2() {
-        ByteBufUtils.macAddressToBytes("00:01:rr:03:FF:05");
-    }
-
-    /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
-     */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMacToBytesInvalidOctet3() {
-        ByteBufUtils.macAddressToBytes("00:01:05d:03:FF:02");
-    }
-
     /**
      * Test of {@link ByteBufUtils#macAddressToString(byte[])}.
      */