import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
+import java.util.Collection;
import org.opendaylight.protocol.bgp.evpn.spi.EsiParser;
import org.opendaylight.protocol.bgp.evpn.spi.EsiRegistry;
import org.opendaylight.protocol.bgp.evpn.spi.EsiSerializer;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
+ @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "SB does not grok TYPE_USE")
public Esi parseEsi(final ByteBuf buffer) {
checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
checkArgument(buffer.readableBytes() == CONTENT_LENGTH,
"Wrong length of array of bytes. Passed: %s;", buffer.readableBytes());
final EsiParser parser = this.handlers.getParser(EsiType.forValue(buffer.readByte()).getIntValue());
- if (parser == null) {
- return null;
- }
- return parser.parseEsi(buffer.readSlice(ESI_LENGTH));
+ return parser == null ? null : parser.parseEsi(buffer.readSlice(ESI_LENGTH));
}
@Override
+ @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "SB does not grok TYPE_USE")
public Esi parseEsiModel(final ChoiceNode esiChoice) {
- Preconditions.checkArgument(esiChoice != null && !esiChoice.getValue().isEmpty(),
- "ESI is mandatory. Can't be null or empty.");
- final ContainerNode cont = (ContainerNode) Iterables.getOnlyElement(esiChoice.getValue());
+ checkArgument(esiChoice != null, "ESI cannot be null");
+ final Collection<DataContainerChild<?, ?>> value = esiChoice.getValue();
+ checkArgument(!value.isEmpty(), "ESI may not be empty");
+ final ContainerNode cont = (ContainerNode) Iterables.getOnlyElement(value);
final EsiSerializer serializer = this.modelHandlers.get(cont.getIdentifier());
if (serializer != null) {
return serializer.serializeEsi(cont);
@Override
public void serializeEsi(final Esi esi, final ByteBuf buffer) {
final EsiSerializer serializer = this.handlers.getSerializer(esi.implementedInterface());
- if (serializer == null) {
- return;
+ if (serializer != null) {
+ serializer.serializeEsi(esi, buffer);
}
- serializer.serializeEsi(esi, buffer);
}
}