Migrate boolean getters
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPMetricObjectParser.java
index 6a0f172ed34a312d228848508eba919138594010..58aa8ad4feb25a78e74705e2e2068c68f581d124 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.parser.object;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -19,18 +18,17 @@ 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.ByteArray;
-import org.opendaylight.protocol.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
 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.metric.object.Metric;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.MetricBuilder;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
  * Parser for {@link Metric}.
  */
 public final class PCEPMetricObjectParser extends CommonObjectParser implements ObjectSerializer {
-
     private static final int CLASS = 6;
     private static final int TYPE = 1;
 
@@ -39,12 +37,10 @@ public final class PCEPMetricObjectParser extends CommonObjectParser implements
      */
     private static final int FLAGS_SIZE = 8;
     private static final int METRIC_VALUE_F_LENGTH = 4;
-
     /*
      * offsets of fields in bytes
      */
     private static final int RESERVED = 2;
-
     /*
      * flags offsets inside flags field in bits
      */
@@ -66,14 +62,14 @@ public final class PCEPMetricObjectParser extends CommonObjectParser implements
         }
         bytes.skipBytes(RESERVED);
         final BitArray flags = BitArray.valueOf(bytes.readByte());
-        final MetricBuilder builder = new MetricBuilder()
-                .setIgnore(header.isIgnore())
-                .setProcessingRule(header.isProcessingRule())
+        return new MetricBuilder()
+                .setIgnore(header.getIgnore())
+                .setProcessingRule(header.getProcessingRule())
                 .setBound(flags.get(B_FLAG_OFFSET))
                 .setComputed(flags.get(C_FLAG_OFFSET))
                 .setMetricType(ByteBufUtils.readUint8(bytes))
-                .setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)));
-        return builder.build();
+                .setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)))
+                .build();
     }
 
     @Override
@@ -84,12 +80,11 @@ public final class PCEPMetricObjectParser extends CommonObjectParser implements
         final ByteBuf body = Unpooled.buffer(SIZE);
         body.writeZero(RESERVED);
         final BitArray flags = new BitArray(FLAGS_SIZE);
-        flags.set(C_FLAG_OFFSET, mObj.isComputed());
-        flags.set(B_FLAG_OFFSET, mObj.isBound());
+        flags.set(C_FLAG_OFFSET, mObj.getComputed());
+        flags.set(B_FLAG_OFFSET, mObj.getBound());
         flags.toByteBuf(body);
-        checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
-        writeUnsignedByte(mObj.getMetricType(), body);
+        ByteBufUtils.writeMandatory(body, mObj.getMetricType(), "MetricType");
         writeFloat32(mObj.getValue(), body);
-        ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+        ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
     }
 }