Further warning removal
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / VlanVidEntrySerializer.java
index f34fd6ac2bd111d444488a1849f8e14a301cd776..dd5c754cdde1fb30da57882198e643268fe83bd2 100644 (file)
@@ -8,58 +8,46 @@
 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
 
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
+import org.opendaylight.yangtools.yang.common.Empty;
 
-public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer {
+public class VlanVidEntrySerializer extends AbstractMatchEntrySerializer<VlanId, Empty> {
     private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
 
-    @Override
-    public void serialize(Match match, ByteBuf outBuffer) {
-        super.serialize(match, outBuffer);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanId =
-                match.getVlanMatch().getVlanId().getVlanId();
-
-        int vlanVidValue = vlanId != null ? vlanId.getValue() : 0;
-
-        if (Boolean.TRUE.equals(match.getVlanMatch().getVlanId().isVlanIdPresent())) {
-            short cfi = 1 << 12;
-            vlanVidValue = vlanVidValue | cfi;
-        }
-
-        outBuffer.writeShort(vlanVidValue);
-
-        if (getHasMask(match)) {
-            writeMask(VLAN_VID_MASK, outBuffer, getValueLength());
-        }
+    public VlanVidEntrySerializer() {
+        super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.VLAN_VID, Short.BYTES);
     }
 
     @Override
-    public boolean matchTypeCheck(Match match) {
-        return match.getVlanMatch() != null && match.getVlanMatch().getVlanId() != null;
+    protected VlanId extractEntry(final Match match) {
+        final VlanMatch vlanMatch = match.getVlanMatch();
+        return vlanMatch == null ? null : vlanMatch.getVlanId();
     }
 
     @Override
-    protected boolean getHasMask(Match match) {
-        final VlanId vlanId = match.getVlanMatch().getVlanId();
-        return Boolean.TRUE.equals(vlanId.isVlanIdPresent())
-                && (vlanId.getVlanId() == null || vlanId.getVlanId().getValue() == 0);
+    protected Empty extractEntryMask(final VlanId entry) {
+        return Boolean.TRUE.equals(entry.getVlanIdPresent())
+                && (entry.getVlanId() == null || entry.getVlanId().getValue().shortValue() == 0) ? Empty.getInstance()
+                        : null;
     }
 
     @Override
-    protected int getOxmFieldCode() {
-        return OxmMatchConstants.VLAN_VID;
-    }
+    protected void serializeEntry(final VlanId entry, final Empty mask, final ByteBuf outBuffer) {
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanId = entry.getVlanId();
 
-    @Override
-    protected int getOxmClassCode() {
-        return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
-    }
+        int vlanVidValue = vlanId != null ? vlanId.getValue().toJava() : 0;
 
-    @Override
-    protected int getValueLength() {
-        return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
+        if (Boolean.TRUE.equals(entry.getVlanIdPresent())) {
+            short cfi = 1 << 12;
+            vlanVidValue = vlanVidValue | cfi;
+        }
+        outBuffer.writeShort(vlanVidValue);
+
+        if (mask != null) {
+            writeMask(VLAN_VID_MASK, outBuffer, Short.BYTES);
+        }
     }
 }