Bump MDSAL to 4.0.0
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / TestVendorInformationTlvParser.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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
9 package org.opendaylight.protocol.pcep.impl;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.parser.tlv.AbstractVendorInformationTlvParser;
13 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
16
17 public class TestVendorInformationTlvParser extends AbstractVendorInformationTlvParser {
18
19     private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L);
20
21     @Override
22     public void serializeEnterpriseSpecificInformation(final EnterpriseSpecificInformation enterpriseSpecificInformation,
23             final ByteBuf buffer) {
24         if (enterpriseSpecificInformation instanceof TestEnterpriseSpecificInformation) {
25             buffer.writeInt(((TestEnterpriseSpecificInformation) enterpriseSpecificInformation).getValue());
26         }
27     }
28
29     @Override
30     public EnterpriseSpecificInformation parseEnterpriseSpecificInformation(final ByteBuf buffer) {
31         return new TestEnterpriseSpecificInformation(buffer.readInt());
32     }
33
34     @Override
35     public EnterpriseNumber getEnterpriseNumber() {
36         return TEST_ENTERPRISE_NUMBER;
37     }
38
39     protected static final class TestEnterpriseSpecificInformation implements EnterpriseSpecificInformation {
40
41         private final int value;
42
43         public TestEnterpriseSpecificInformation(final int value) {
44             this.value = value;
45         }
46
47         public int getValue() {
48             return this.value;
49         }
50
51         @Override
52         public Class<TestEnterpriseSpecificInformation> implementedInterface() {
53             return TestEnterpriseSpecificInformation.class;
54         }
55
56         @Override
57         public int hashCode() {
58             final int prime = 31;
59             int result = 1;
60             result = prime * result + this.value;
61             return result;
62         }
63
64         @Override
65         public boolean equals(final Object obj) {
66             if (this == obj) {
67                 return true;
68             }
69             if (obj == null) {
70                 return false;
71             }
72             if (getClass() != obj.getClass()) {
73                 return false;
74             }
75             TestEnterpriseSpecificInformation other = (TestEnterpriseSpecificInformation) obj;
76             if (this.value != other.value) {
77                 return false;
78             }
79             return true;
80         }
81     }
82
83 }