Remove Objects.{is,non}Null abuse
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / EthernetDestinationEntryDeserializer.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.protocol.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmDeserializerHelper;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
16
17 public class EthernetDestinationEntryDeserializer extends AbstractMatchEntryDeserializer {
18
19     @Override
20     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
21         final boolean hasMask = processHeader(message);
22         final EthernetMatch ethernetMatch = builder.getEthernetMatch();
23         final EthernetDestinationBuilder ethernetDestinationBuilder = new EthernetDestinationBuilder();
24         ethernetDestinationBuilder.setAddress(OxmDeserializerHelper.convertMacAddress(message));
25
26         if (hasMask) {
27             ethernetDestinationBuilder.setMask(OxmDeserializerHelper.convertMacAddress(message));
28         }
29
30         if (ethernetMatch == null) {
31             builder.setEthernetMatch(new EthernetMatchBuilder()
32                     .setEthernetDestination(ethernetDestinationBuilder.build())
33                     .build());
34         } else if (ethernetMatch.getEthernetDestination() == null) {
35             builder.setEthernetMatch(new EthernetMatchBuilder(ethernetMatch)
36                     .setEthernetDestination(ethernetDestinationBuilder.build())
37                     .build());
38         } else {
39             throwErrorOnMalformed(builder, "ethernetMatch", "ethernetDestination");
40         }
41     }
42 }