Migrate boolean getters
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPSvecObjectParser.java
index a8205215d187b95b739d17347ade5cd220c51e10..c3548a25a1a7730f50915fb50b054619619dbac5 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.parser.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
@@ -19,18 +18,17 @@ import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.Svec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.SvecBuilder;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
- * Parser for {@link Svec}
+ * Parser for {@link Svec}.
  */
 public final class PCEPSvecObjectParser extends CommonObjectParser implements ObjectSerializer {
-
     private static final int CLASS = 11;
     private static final int TYPE = 1;
 
@@ -64,8 +62,7 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob
 
     @Override
     public Svec parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
-            "Array of bytes is mandatory. Can't be null or empty.");
+        checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         if (bytes.readableBytes() < MIN_SIZE) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: "
                 + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
@@ -80,40 +77,39 @@ public final class PCEPSvecObjectParser extends CommonObjectParser implements Ob
         if (requestIDs.isEmpty()) {
             throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
         }
-        final SvecBuilder builder = new SvecBuilder();
-
-        builder.setIgnore(header.isIgnore());
-        builder.setProcessingRule(header.isProcessingRule());
-
-        builder.setLinkDiverse(flags.get(L_FLAG_OFFSET));
-        builder.setNodeDiverse(flags.get(N_FLAG_OFFSET));
-        builder.setSrlgDiverse(flags.get(S_FLAG_OFFSET));
-        builder.setLinkDirectionDiverse(flags.get(D_FLAG_OFFSET));
-        builder.setPartialPathDiverse(flags.get(P_FLAG_OFFSET));
-        builder.setRequestsIds(requestIDs);
-        return builder.build();
+        return new SvecBuilder()
+                .setIgnore(header.getIgnore())
+                .setProcessingRule(header.getProcessingRule())
+                .setLinkDiverse(flags.get(L_FLAG_OFFSET))
+                .setNodeDiverse(flags.get(N_FLAG_OFFSET))
+                .setSrlgDiverse(flags.get(S_FLAG_OFFSET))
+                .setLinkDirectionDiverse(flags.get(D_FLAG_OFFSET))
+                .setPartialPathDiverse(flags.get(P_FLAG_OFFSET))
+                .setRequestsIds(requestIDs)
+                .build();
     }
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof Svec,
-            "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.", object.getClass());
+        checkArgument(object instanceof Svec, "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.",
+            object.getClass());
         final Svec svecObj = (Svec) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_F_OFFSET);
         final BitArray flags = new BitArray(FLAGS_SIZE);
-        flags.set(L_FLAG_OFFSET, svecObj.isLinkDiverse());
-        flags.set(N_FLAG_OFFSET, svecObj.isNodeDiverse());
-        flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiverse());
-        flags.set(D_FLAG_OFFSET, svecObj.isLinkDirectionDiverse());
-        flags.set(P_FLAG_OFFSET, svecObj.isPartialPathDiverse());
+        flags.set(L_FLAG_OFFSET, svecObj.getLinkDiverse());
+        flags.set(N_FLAG_OFFSET, svecObj.getNodeDiverse());
+        flags.set(S_FLAG_OFFSET, svecObj.getSrlgDiverse());
+        flags.set(D_FLAG_OFFSET, svecObj.getLinkDirectionDiverse());
+        flags.set(P_FLAG_OFFSET, svecObj.getPartialPathDiverse());
         flags.toByteBuf(body);
 
         final List<RequestId> requestIDs = svecObj.getRequestsIds();
+        // FIXME: remove this assert
         assert !requestIDs.isEmpty() : "Empty Svec Object - no request ids.";
         for (final RequestId requestId : requestIDs) {
-            writeUnsignedInt(requestId.getValue(), body);
+            ByteBufUtils.write(body, requestId.getValue());
         }
-        ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+        ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
     }
 }