Fix checkstyle violations in openflowjava-util 81/67381/1
authorTom Pantelis <tompantelis@gmail.com>
Sat, 20 Jan 2018 18:38:58 +0000 (13:38 -0500)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 20 Jan 2018 18:38:58 +0000 (13:38 -0500)
Change-Id: Iac5a02900711a36c79481f0ee19be06c20bbd879
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
openflowjava/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ByteBufUtils.java
openflowjava/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterDeserializerKeyFactory.java
openflowjava/openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactory.java
openflowjava/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ByteBufUtilsTest.java
openflowjava/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterDeserializerKeyFactoryTest.java
openflowjava/openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterSerializerKeyFactoryTest.java

index e3923c69350ad7c4c53e4e8f9ee94e29f0113fb7..79ccb1704789ff73c4278964b8e544772abcc815 100644 (file)
@@ -6,7 +6,6 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-
 package org.opendaylight.openflowjava.util;
 
 import com.google.common.base.Preconditions;
@@ -28,7 +27,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 
-/** Class for common operations on ByteBuf
+/**
+ *  Class for common operations on ByteBuf.
+ *
  * @author michal.polkorab
  * @author timotej.kubas
  */
@@ -44,20 +45,22 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Converts ByteBuf into String
+     * Converts ByteBuf into String.
+     *
      * @param bb input ByteBuf
      * @return String
      */
     public static String byteBufToHexString(final ByteBuf bb) {
         StringBuilder sb = new StringBuilder();
-        for (int i = bb.readerIndex(); i < (bb.readerIndex() + bb.readableBytes()); i++) {
+        for (int i = bb.readerIndex(); i < bb.readerIndex() + bb.readableBytes(); i++) {
             sb.append(String.format(" %02x", bb.getUnsignedByte(i)));
         }
         return sb.toString().trim();
     }
 
     /**
-     * Converts String into byte[]
+     * Converts String into byte[].
+     *
      * @param hexSrc input String
      * @return byte[] filled with input data
      */
@@ -66,7 +69,8 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Converts String into byte[]
+     * Converts String into byte[].
+     *
      * @param hexSrc input String
      * @param withSpaces if there are spaces in string
      * @return byte[] filled with input data
@@ -75,16 +79,17 @@ public abstract class ByteBufUtils {
         final Splitter splitter = withSpaces ? HEXSTRING_SPLITTER : HEXSTRING_NOSPACE_SPLITTER;
         List<String> byteChips = Lists.newArrayList(splitter.split(hexSrc));
         byte[] result = new byte[byteChips.size()];
-        int i = 0;
+        int index = 0;
         for (String chip : byteChips) {
-            result[i] = (byte) Short.parseShort(chip, 16);
-            i++;
+            result[index] = (byte) Short.parseShort(chip, 16);
+            index++;
         }
         return result;
     }
 
     /**
-     * Creates ByteBuf filled with specified data
+     * Creates ByteBuf filled with specified data.
+     *
      * @param hexSrc input String of bytes in hex format
      * @return ByteBuf with specified hexString converted
      */
@@ -95,7 +100,8 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Creates ByteBuf filled with specified data
+     * Creates ByteBuf filled with specified data.
+     *
      * @param hexSrc input String of bytes in hex format
      * @param out ByteBuf with specified hexString converted
      */
@@ -104,8 +110,9 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding
-     * @param length
+     * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding.
+     *
+     * @param length the desired length
      * @param out ByteBuf to be padded
      * @deprecated Use {@link ByteBuf#writeZero(int)} directly.
      */
@@ -115,13 +122,15 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Create standard OF header
+     * Create standard OF header.
+     *
      * @param msgType message code
      * @param message POJO
      * @param out writing buffer
      * @param length ofheader length
      */
-    public static <E extends OfHeader> void writeOFHeader(final byte msgType, final E message, final ByteBuf out, final int length) {
+    public static <E extends OfHeader> void writeOFHeader(final byte msgType, final E message, final ByteBuf out,
+            final int length) {
         out.writeByte(message.getVersion());
         out.writeByte(msgType);
         out.writeShort(length);
@@ -129,7 +138,8 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Write length standard OF header
+     * Write length standard OF header.
+     *
      * @param out writing buffer
      */
     public static void updateOFHeaderLength(final ByteBuf out) {
@@ -137,7 +147,8 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Write length OF header
+     * Write length OF header.
+     *
      * @param out writing buffer
      * @param index writing index
      */
@@ -146,7 +157,8 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Fills the bitmask from boolean map where key is bit position
+     * Fills the bitmask from boolean map where key is bit position.
+     *
      * @param booleanMap bit to boolean mapping
      * @return bit mask
      */
@@ -171,19 +183,20 @@ public abstract class ByteBufUtils {
     public static int fillBitMask(final int offset, final boolean... values) {
         int bitmask = 0;
 
-        int i = offset;
+        int index = offset;
         for (boolean v : values) {
             if (v) {
-                bitmask |= 1 << i;
+                bitmask |= 1 << index;
             }
-            ++i;
+            ++index;
         }
 
         return bitmask;
     }
 
     /**
-     * Fills the bitmask from boolean list where key is bit position
+     * Fills the bitmask from boolean list where key is bit position.
+     *
      * @param booleanList bit to boolean mapping
      * @return bit mask
      */
@@ -191,7 +204,7 @@ public abstract class ByteBufUtils {
         int[] bitmask;
         int index = 0;
         int arrayIndex = 0;
-        if ((booleanList.size() % Integer.SIZE) != 0) {
+        if (booleanList.size() % Integer.SIZE != 0) {
             bitmask = new int[booleanList.size() / Integer.SIZE + 1];
         } else {
             bitmask = new int[booleanList.size() / Integer.SIZE];
@@ -207,7 +220,8 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Converts byte array into String
+     * Converts byte array into String.
+     *
      * @param array input byte array
      * @return String
      */
@@ -219,27 +233,28 @@ public abstract class ByteBufUtils {
         return sb.toString().trim();
     }
 
-    private static int hexValue(final char c) {
-        if (c >= '0' && c <= '9') {
-            return c - '0';
+    private static int hexValue(final char ch) {
+        if (ch >= '0' && ch <= '9') {
+            return ch - '0';
         }
-        if (c >= 'a' && c <= 'f') {
-            return c - 'a' + 10;
+        if (ch >= 'a' && ch <= 'f') {
+            return ch - 'a' + 10;
         }
-        if (c >= 'A' && c <= 'F') {
-            return c - 'A' + 10;
+        if (ch >= 'A' && ch <= 'F') {
+            return ch - 'A' + 10;
         }
 
-        throw new IllegalArgumentException(String.format("Invalid character '%s' encountered", c));
+        throw new IllegalArgumentException(String.format("Invalid character '%s' encountered", ch));
     }
 
     /**
      * Converts macAddress to byte array.
      * See also {@link org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress}.
      *
-     * @param macAddress
+     * @param macAddress the mac address to convert
      * @return byte representation of mac address
      */
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public static byte[] macAddressToBytes(final String macAddress) {
         final byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
         final char[] mac = macAddress.toCharArray();
@@ -252,40 +267,40 @@ public abstract class ByteBufUtils {
                     offset++;
                 } else {
                     result[i] = UnsignedBytes.checkedCast(
-                            (hexValue(mac[offset]) << 4) | hexValue(mac[offset +1]));
+                            hexValue(mac[offset]) << 4 | hexValue(mac[offset + 1]));
                     offset += 2;
                 }
                 Preconditions.checkArgument(mac[offset] == ':', "Invalid value: %s", macAddress);
                 offset++;
             }
 
-            if (offset == (mac.length - 1)) {
+            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]));
+                        UnsignedBytes.checkedCast(hexValue(mac[offset]) << 4 | hexValue(mac[offset + 1]));
                 offset++;
             }
-            if (offset != (mac.length -1)) {
+            if (offset != mac.length - 1) {
                 throw new IllegalArgumentException("Incorrect MAC address length");
             }
-        } catch (Exception e) {
+        } catch (RuntimeException e) {
             throw new IllegalArgumentException("Unable to serialize MAC address for input: " + macAddress
                     + ". \n" + e);
         }
         return result;
     }
 
-    private static final void appendHexByte(final StringBuilder sb, final byte b) {
-        final int v = UnsignedBytes.toInt(b);
+    private static void appendHexByte(final StringBuilder sb, final byte value) {
+        final int v = UnsignedBytes.toInt(value);
         sb.append(HEX_CHARS[v >>> 4]);
         sb.append(HEX_CHARS[v &  15]);
     }
 
     private static void appendHexUnsignedShort(final StringBuilder sb, final int val) {
-        sb.append(ByteBufUtils.HEX_CHARS[(val >>> 12) & 15]);
-        sb.append(ByteBufUtils.HEX_CHARS[(val >>>  8) & 15]);
-        sb.append(ByteBufUtils.HEX_CHARS[(val >>>  4) & 15]);
+        sb.append(ByteBufUtils.HEX_CHARS[val >>> 12 & 15]);
+        sb.append(ByteBufUtils.HEX_CHARS[val >>>  8 & 15]);
+        sb.append(ByteBufUtils.HEX_CHARS[val >>>  4 & 15]);
         sb.append(ByteBufUtils.HEX_CHARS[ val         & 15]);
     }
 
@@ -293,7 +308,7 @@ public abstract class ByteBufUtils {
      * Converts a MAC address represented in bytes to String.
      * See also {@link org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress}.
      *
-     * @param address
+     * @param address the MAC address to convert
      * @return String representation of a MAC address
      */
     public static String macAddressToString(final byte[] address) {
@@ -311,8 +326,9 @@ public abstract class ByteBufUtils {
     }
 
     /**
-     * Reads and parses null-terminated string from ByteBuf
-     * @param rawMessage
+     * Reads and parses null-terminated string from ByteBuf.
+     *
+     * @param rawMessage the message to parse
      * @param length maximal length of String
      * @return String with name of port
      */
@@ -378,10 +394,10 @@ public abstract class ByteBufUtils {
         return IetfYangUtil.INSTANCE.macAddressFor(tmp);
     }
 
-    public static byte[] serializeList(final List<Short> list) throws IOException{
+    public static byte[] serializeList(final List<Short> list) throws IOException {
         ByteBuffer byteBuffer = ByteBuffer.allocate(list.size() * 2);
-        for (Short aShort : list) {
-            byteBuffer.putShort(aShort);
+        for (Short shortValue : list) {
+            byteBuffer.putShort(shortValue);
         }
         return byteBuffer.array();
     }
index 6e285f958b78ee69e3587c8b8a2ca2cc615c7287..a4c6bebd6e79982e8ccff89fce8b6d2c9845472d 100644 (file)
@@ -17,15 +17,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
 /**
+ * Factory for creating experimenter deserializer keys.
+ *
  * @author michal.polkorab
  */
-public abstract class ExperimenterDeserializerKeyFactory {
+public final class ExperimenterDeserializerKeyFactory {
 
     private ExperimenterDeserializerKeyFactory() {
         //not called
     }
 
     /**
+     * Creates an experimenter error deserializer key.
+     *
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
@@ -36,6 +40,8 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
+     * Creates an experimenter message deserializer key.
+     *
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @param type experimenter type according to vendor implementation
@@ -47,7 +53,9 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
-     * @param version        openflow wire version
+     * Creates a vendor message deserializer key.
+     *
+     * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
      */
@@ -57,9 +65,11 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
+     * Creates a multi-part reply message deserializer key.
+     *
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
-     * @param type
+     * @param type the type
      * @return key instance
      */
     public static ExperimenterIdTypeDeserializerKey createMultipartReplyMessageDeserializerKey(
@@ -68,7 +78,9 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
-     * @param version        openflow wire version
+     * Creates a multi-part reply vendor message deserializer key.
+     *
+     * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
      */
@@ -78,6 +90,8 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
+     * Creates a multi-part reply TF deserializer key.
+     *
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
@@ -88,6 +102,8 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
+     * Creates a queue property deserializer key.
+     *
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
@@ -98,6 +114,8 @@ public abstract class ExperimenterDeserializerKeyFactory {
     }
 
     /**
+     * Creates a meter band deserializer key.
+     *
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
@@ -106,5 +124,4 @@ public abstract class ExperimenterDeserializerKeyFactory {
             short version, Long experimenterId) {
         return new ExperimenterIdDeserializerKey(version, experimenterId, MeterBandExperimenterCase.class);
     }
-
-}
\ No newline at end of file
+}
index ea0a69ce43a7a4cc76bc8d4a145f0f1d3a22aa32..a96e0cc2240096fc06d5d5a2ab7dfd682cb21f8b 100755 (executable)
@@ -17,11 +17,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
 /**
+ * Factory for creating experimenter serializer keys.
+ *
  * @author michal.polkorab
  */
 public abstract class ExperimenterSerializerKeyFactory {
 
     /**
+     * Creates an experimenter message serializer key.
+     *
      * @param msgVersion openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @param type experimenter type according to vendor implementation
@@ -33,6 +37,8 @@ public abstract class ExperimenterSerializerKeyFactory {
     }
 
     /**
+     * Creates a multi-part request serializer key.
+     *
      * @param msgVersion openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @param type experimenter type according to vendor implementation
@@ -44,6 +50,8 @@ public abstract class ExperimenterSerializerKeyFactory {
     }
 
     /**
+     * Creates a multi-part request TF serializer key.
+     *
      * @param msgVersion openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
@@ -54,18 +62,21 @@ public abstract class ExperimenterSerializerKeyFactory {
     }
 
     /**
+     * Creates a meter band serializer key.
+     *
      * @param msgVersion openflow wire version
      * @param experimenterId experimenter / vendor ID
      * @return key instance
      */
     public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
             short msgVersion, long experimenterId) {
-        return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, null);
+        return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId,
+                MeterBandExperimenterCase.class, null);
     }
 
     public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
             short msgVersion, long experimenterId, Class<? extends ExperimenterMeterBandSubType> meterSubType) {
-        return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, meterSubType);
+        return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId,
+                MeterBandExperimenterCase.class, meterSubType);
     }
-
-}
\ No newline at end of file
+}
index b7f0f593caed035f5481f86576537c4c7979c42a..35589bf2b1b80762561b419a43af6e2e8abd2a4f 100644 (file)
@@ -23,16 +23,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;
 
 /**
- * @author michal.polkorab
+ * Unit tests for ByteBufUtils.
  *
+ * @author michal.polkorab
  */
 public class ByteBufUtilsTest {
 
-    private final byte[] EXPECTED = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff};
-    private final byte[] EXPECTEDVALUES1AND255 = new byte[]{0x00, 0x01, 0x00, (byte) 0xff};
+    private static final byte[] EXPECTED = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff};
+    private static final byte[] EXPECTEDVALUES1AND255 = new byte[]{0x00, 0x01, 0x00, (byte) 0xff};
 
     /**
-     * Test of {@link org.opendaylight.openflowjava.util.ByteBufUtils#hexStringToBytes(String)}
+     * Test of {@link org.opendaylight.openflowjava.util.ByteBufUtils#hexStringToBytes(String)}.
      */
     @Test
     public void testHexStringToBytes() {
@@ -42,7 +43,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)}
+     * Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)}.
      */
     @Test
     public void testHexStringToBytes2() {
@@ -52,7 +53,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#hexStringToByteBuf(String)}
+     * Test of {@link ByteBufUtils#hexStringToByteBuf(String)}.
      */
     @Test
     public void testHexStringToByteBuf() {
@@ -62,7 +63,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)}
+     * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)}.
      */
     @Test
     public void testHexStringToGivenByteBuf() {
@@ -79,7 +80,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
      */
     @Test
     public void testFillBitmaskByEmptyMap() {
@@ -92,18 +93,18 @@ public class ByteBufUtilsTest {
 
     private static String toBinaryString(Map<Integer, Boolean> emptyMap, int length) {
         String binaryString = Integer.toBinaryString(ByteBufUtils.fillBitMaskFromMap(emptyMap));
-        return String.format("%"+length+"s", binaryString).replaceAll(" ", "0");
+        return String.format("%" + length + "s", binaryString).replaceAll(" ", "0");
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
      */
     @Test
     public void testFillBitmaskByFullMap() {
         Map<Integer, Boolean> fullMap = new HashMap<>();
         String expectedBinaryString = "11111111111111111111111111111111";
         String bitmaskValueInBinarySytring;
-        for(Integer i=0;i<=31;i++) {
+        for (Integer i = 0; i <= 31; i++) {
             fullMap.put(i, true);
         }
         bitmaskValueInBinarySytring = toBinaryString(fullMap, 32);
@@ -111,14 +112,14 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
      */
     @Test
     public void testFillBitmaskByZeroMap() {
         Map<Integer, Boolean> zeroMap = new HashMap<>();
         String expectedBinaryString = "00000000000000000000000000000000";
         String bitmaskValueInBinarySytring;
-        for(Integer i=0;i<=31;i++) {
+        for (Integer i = 0; i <= 31; i++) {
             zeroMap.put(i, false);
         }
         bitmaskValueInBinarySytring = toBinaryString(zeroMap, 32);
@@ -126,7 +127,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromMap(java.util.Map)}.
      */
     @Test
     public void testFillBitmaskByRandomSet() {
@@ -134,9 +135,9 @@ public class ByteBufUtilsTest {
         String expectedBinaryString = "00000000000000000111100000000000";
         String bitmaskValueInBinarySytring;
         Boolean mapValue;
-        for(Integer i=0;i<=31;i++) {
+        for (Integer i = 0; i <= 31; i++) {
             mapValue = false;
-            if(i>=11 && i<=14) {
+            if (i >= 11 && i <= 14) {
                 mapValue = true;
             }
             randomMap.put(i, mapValue);
@@ -146,7 +147,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
      */
     @Test
     public void testFillBitmaskByEmptyList() {
@@ -162,18 +163,18 @@ public class ByteBufUtilsTest {
         int[] bitMaskArray;
         bitMaskArray = ByteBufUtils.fillBitMaskFromList(emptyList);
         String binaryString = Integer.toBinaryString(bitMaskArray[0]);
-        return String.format("%"+length+"s", binaryString).replaceAll(" ", "0");
+        return String.format("%" + length + "s", binaryString).replaceAll(" ", "0");
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
      */
     @Test
     public void testFillBitmaskByFullList() {
         List<Boolean> fullList = new ArrayList<>();
         String expectedBinaryString = "11111111111111111111111111111111";
         String bitmaskValueInBinarySytring;
-        for(Integer i=0;i<=31;i++) {
+        for (Integer i = 0; i <= 31; i++) {
             fullList.add(true);
         }
         bitmaskValueInBinarySytring = listToBinaryString(fullList, 32);
@@ -181,14 +182,14 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
      */
     @Test
     public void testFillBitmaskByZeroList() {
         List<Boolean> zeroList = new ArrayList<>();
         String expectedBinaryString = "00000000000000000000000000000000";
         String bitmaskValueInBinarySytring;
-        for(Integer i=0;i<=31;i++) {
+        for (Integer i = 0; i <= 31; i++) {
             zeroList.add(false);
         }
         bitmaskValueInBinarySytring = listToBinaryString(zeroList, 32);
@@ -196,7 +197,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}
+     * Test of {@link ByteBufUtils#fillBitMaskFromList(List)}.
      */
     @Test
     public void testFillBitmaskFromRandomList() {
@@ -204,9 +205,9 @@ public class ByteBufUtilsTest {
         String expectedBinaryString = "00000000000000000111100000000000";
         String bitmaskValueInBinarySytring;
         Boolean listValue;
-        for(Integer i=0;i<=31;i++) {
+        for (Integer i = 0; i <= 31; i++) {
             listValue = false;
-            if(i>=11 && i<=14) {
+            if (i >= 11 && i <= 14) {
                 listValue = true;
             }
             randomList.add(listValue);
@@ -216,7 +217,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
     @Test
     public void testMacToBytes() {
@@ -233,82 +234,82 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @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 of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToBytesTooShort() {
         ByteBufUtils.macAddressToBytes("00:01:02:03:FF");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToBytesTooShort2() {
         ByteBufUtils.macAddressToBytes("00:01:02:03:FF:");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testIncorrectMacToBytes() {
         ByteBufUtils.macAddressToBytes("00:01:02:03:FF::");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testIncorrectMacToBytes2() {
         ByteBufUtils.macAddressToBytes("00:01:02:03:FF:::");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToBytesTooLong() {
         ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05:85");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToBytesInvalidOctet() {
         ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05d");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToBytesInvalidOctet2() {
         ByteBufUtils.macAddressToBytes("00:01:rr:03:FF:05");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToBytesInvalidOctet3() {
         ByteBufUtils.macAddressToBytes("00:01:05d:03:FF:02");
     }
 
     /**
-     * Test of {@link ByteBufUtils#macAddressToString(byte[])}
+     * Test of {@link ByteBufUtils#macAddressToString(byte[])}.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testMacToString() {
         Assert.assertEquals("Wrong string decoded", "00:01:02:03:FF:05",
                 ByteBufUtils.macAddressToString(new byte[]{0, 1, 2, 3, (byte) 255, 5}));
@@ -316,7 +317,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#decodeNullTerminatedString(ByteBuf, int)}
+     * Test of {@link ByteBufUtils#decodeNullTerminatedString(ByteBuf, int)}.
      */
     @Test
     public void testDecodeString() {
@@ -328,7 +329,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test of {@link ByteBufUtils#byteBufToHexString(ByteBuf)}
+     * Test of {@link ByteBufUtils#byteBufToHexString(ByteBuf)}.
      */
     @Test
     public void testByteBufToHexString() {
@@ -338,7 +339,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Buffer padding test
+     * Buffer padding test.
      */
     @Test
     public void testPadBuffer() {
@@ -350,16 +351,16 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Write OF header test
+     * Write OF header test.
      */
     @Test
     public void testWriteHeader() {
-        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
         HelloInputBuilder helloBuilder = new HelloInputBuilder();
         helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
         helloBuilder.setXid(12345L);
         helloBuilder.setElements(null);
         HelloInput helloInput = helloBuilder.build();
+        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
         ByteBufUtils.writeOFHeader((byte) 0, helloInput, buf, EncodeConstants.OFHEADER_SIZE);
         Assert.assertEquals("Wrong version", EncodeConstants.OF13_VERSION_ID, buf.readUnsignedByte());
         Assert.assertEquals("Wrong type", 0, buf.readUnsignedByte());
@@ -369,7 +370,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Fill bitmask test
+     * Fill bitmask test.
      */
     @Test
     public void testFillBitmask() {
@@ -385,7 +386,7 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test bytes to hex string
+     * Test bytes to hex string.
      */
     @Test
     public void testBytesToHexString() {
@@ -396,9 +397,9 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test ipv4 address conversion
+     * Test ipv4 address conversion.
      */
-    @Test(expected=IndexOutOfBoundsException.class)
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testReadIpv4Address() {
         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
         buffer.writeByte(10);
@@ -415,9 +416,9 @@ public class ByteBufUtilsTest {
     }
 
     /**
-     * Test ipv6 address conversion
+     * Test ipv6 address conversion.
      */
-    @Test(expected=IndexOutOfBoundsException.class)
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testReadIpv6Address() {
         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
         buffer.writeShort(10);
@@ -445,7 +446,7 @@ public class ByteBufUtilsTest {
         shorts.add((short) 255);
 
         final byte[] bytes = ByteBufUtils.serializeList(shorts);
-        Assert.assertTrue(bytes.length == shorts.size()*2);
+        Assert.assertTrue(bytes.length == shorts.size() * 2);
         Assert.assertArrayEquals(EXPECTEDVALUES1AND255, bytes);
     }
 
@@ -453,17 +454,17 @@ public class ByteBufUtilsTest {
     public void testUpdateHeader() throws IOException {
         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
         buffer.writeInt(1);
-        int start = buffer.writerIndex();
+        final int start = buffer.writerIndex();
         buffer.writeShort(4);
         buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
         buffer.writeLong(8);
-        int end = buffer.writerIndex();
+        final int end = buffer.writerIndex();
 
         ByteBufUtils.updateOFHeaderLength(buffer, start);
         Assert.assertEquals(buffer.readInt(), 1);
         Assert.assertEquals(buffer.readShort(), 4);
         Assert.assertEquals(buffer.readShort(), 12);
-        Assert.assertEquals(buffer.readLong(), 8l);
+        Assert.assertEquals(buffer.readLong(), 8L);
         Assert.assertEquals(buffer.getShort(start + EncodeConstants.OFHEADER_LENGTH_INDEX), end - start);
     }
 }
index a8cc83682a7d32bcc7d9641c917ded62a28e71aa..13bfa51c42dbaa643fa12ee6664e899bc4f7b76a 100644 (file)
@@ -20,6 +20,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
 /**
+ * Unit tests for ExperimenterDeserializerKeyFactory.
+ *
  * @author michal.polkorab
  */
 public class ExperimenterDeserializerKeyFactoryTest {
@@ -118,4 +120,4 @@ public class ExperimenterDeserializerKeyFactoryTest {
                 43L, ExperimenterDataOfChoice.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
     }
-}
\ No newline at end of file
+}
index 471e413399634f7b9d713fa948d2940ce1935877..6b863c82cb69daa50f98c6a26f38961722346043 100755 (executable)
@@ -20,9 +20,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
 /**
- * Test ExperimenterSerializerKeyFactory key creation
- * @author michal.polkorab
+ * Test ExperimenterSerializerKeyFactory key creation.
  *
+ * @author michal.polkorab
  */
 public class ExperimenterSerializerKeyFactoryTest {
 
@@ -76,12 +76,12 @@ public class ExperimenterSerializerKeyFactoryTest {
 
     @Test
     public void testCreateMeterBandSubTypeSerializerKey() throws Exception {
-        ExperimenterIdSerializerKey<?> createdKey;
-        ExperimenterIdSerializerKey<?> comparationKey1;
-        ExperimenterIdSerializerKey<?> comparationKey2;
-        ExperimenterIdSerializerKey<?> comparationKey3;
-        ExperimenterIdSerializerKey<?> comparationKey4;
-        ExperimenterIdSerializerKey<?> comparationKey5;
+        final ExperimenterIdSerializerKey<?> createdKey;
+        final ExperimenterIdSerializerKey<?> comparationKey1;
+        final ExperimenterIdSerializerKey<?> comparationKey2;
+        final ExperimenterIdSerializerKey<?> comparationKey3;
+        final ExperimenterIdSerializerKey<?> comparationKey4;
+        final ExperimenterIdSerializerKey<?> comparationKey5;
 
         createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(
                 EncodeConstants.OF10_VERSION_ID, 43L, ExperimenterMeterBandSubType.class);
@@ -101,4 +101,4 @@ public class ExperimenterSerializerKeyFactoryTest {
         Assert.assertNotEquals("Wrong key created", comparationKey4, createdKey);
         Assert.assertEquals("Wrong key created", comparationKey5, createdKey);
     }
-}
\ No newline at end of file
+}