Removed checkstyle warnings.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / AbstractEROWithSubobjectsParser.java
index 38a471151a3f8cf75ced36cf095c002f0e61b818..1e3153a802c757175bcc4137934b1076f8d1ab11 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 
@@ -21,64 +25,60 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.primitives.UnsignedBytes;
-
 public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
 
-       private static final Logger LOG = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
 
-       private static final int HEADER_LENGTH = 2;
+    private static final int HEADER_LENGTH = 2;
 
-       private final EROSubobjectRegistry subobjReg;
+    private final EROSubobjectRegistry subobjReg;
 
-       protected AbstractEROWithSubobjectsParser(final EROSubobjectRegistry subobjReg) {
-               this.subobjReg = Preconditions.checkNotNull(subobjReg);
-       }
+    protected AbstractEROWithSubobjectsParser(final EROSubobjectRegistry subobjReg) {
+        this.subobjReg = Preconditions.checkNotNull(subobjReg);
+    }
 
-       protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException {
-               Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
-               final List<Subobject> subs = new ArrayList<>();
-               while (buffer.isReadable()) {
-                       boolean loose = ((buffer.getByte(buffer.readerIndex()) & (1 << 7)) != 0) ? true : false;
-                       int type = (buffer.readByte() & 0xff) & ~(1 << 7);
-                       int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
-                       if (length > buffer.readableBytes()) {
-                               throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
-                                               + buffer.readableBytes());
-                       }
-                       LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
-                       final Subobject sub = this.subobjReg.parseSubobject(type, buffer.slice(buffer.readerIndex(), length), loose);
-                       if (sub == null) {
-                               LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
-                       } else {
-                               LOG.debug("Subobject was parsed. {}", sub);
-                               subs.add(sub);
-                       }
-                       buffer.readerIndex(buffer.readerIndex() + length);
-               }
-               return subs;
-       }
+    protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException {
+        Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        final List<Subobject> subs = new ArrayList<>();
+        while (buffer.isReadable()) {
+            boolean loose = ((buffer.getByte(buffer.readerIndex()) & (1 << 7)) != 0) ? true : false;
+            int type = (buffer.readByte() & 0xff) & ~(1 << 7);
+            int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
+            if (length > buffer.readableBytes()) {
+                throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
+                        + buffer.readableBytes());
+            }
+            LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
+            final Subobject sub = this.subobjReg.parseSubobject(type, buffer.slice(buffer.readerIndex(), length), loose);
+            if (sub == null) {
+                LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
+            } else {
+                LOG.debug("Subobject was parsed. {}", sub);
+                subs.add(sub);
+            }
+            buffer.readerIndex(buffer.readerIndex() + length);
+        }
+        return subs;
+    }
 
-       protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
-               final List<byte[]> result = Lists.newArrayList();
-               int finalLength = 0;
-               for (final Subobject subobject : subobjects) {
-                       final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
-                       if (bytes == null) {
-                               LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
-                       } else  {
-                               finalLength += bytes.length;
-                               result.add(bytes);
-                       }
-               }
-               final byte[] resultBytes = new byte[finalLength];
-               int byteOffset = 0;
-               for (final byte[] b : result) {
-                       System.arraycopy(b, 0, resultBytes, byteOffset, b.length);
-                       byteOffset += b.length;
-               }
-               return resultBytes;
-       }
+    protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
+        final List<byte[]> result = Lists.newArrayList();
+        int finalLength = 0;
+        for (final Subobject subobject : subobjects) {
+            final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
+            if (bytes == null) {
+                LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
+            } else {
+                finalLength += bytes.length;
+                result.add(bytes);
+            }
+        }
+        final byte[] resultBytes = new byte[finalLength];
+        int byteOffset = 0;
+        for (final byte[] b : result) {
+            System.arraycopy(b, 0, resultBytes, byteOffset, b.length);
+            byteOffset += b.length;
+        }
+        return resultBytes;
+    }
 }