Code Clean Up
[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.rev131005.vendor.information.EnterpriseSpecificInformation;
16 import org.opendaylight.yangtools.yang.binding.DataContainer;
17
18 public class TestVendorInformationTlvParser extends AbstractVendorInformationTlvParser {
19
20     private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L);
21
22     @Override
23     public void serializeEnterpriseSpecificInformation(final EnterpriseSpecificInformation enterpriseSpecificInformation,
24             final ByteBuf buffer) {
25         if (enterpriseSpecificInformation instanceof TestEnterpriseSpecificInformation) {
26             buffer.writeInt(((TestEnterpriseSpecificInformation) enterpriseSpecificInformation).getValue());
27         }
28     }
29
30     @Override
31     public EnterpriseSpecificInformation parseEnterpriseSpecificInformation(final ByteBuf buffer)
32             throws PCEPDeserializerException {
33         return new TestEnterpriseSpecificInformation(buffer.readInt());
34     }
35
36     @Override
37     public EnterpriseNumber getEnterpriseNumber() {
38         return TEST_ENTERPRISE_NUMBER;
39     }
40
41     protected static final class TestEnterpriseSpecificInformation implements EnterpriseSpecificInformation {
42
43         private final int value;
44
45         public TestEnterpriseSpecificInformation(final int value) {
46             this.value = value;
47         }
48
49         public int getValue() {
50             return this.value;
51         }
52
53         @Override
54         public Class<? extends DataContainer> getImplementedInterface() {
55             return TestEnterpriseSpecificInformation.class;
56         }
57
58         @Override
59         public int hashCode() {
60             final int prime = 31;
61             int result = 1;
62             result = prime * result + this.value;
63             return result;
64         }
65
66         @Override
67         public boolean equals(final Object obj) {
68             if (this == obj) {
69                 return true;
70             }
71             if (obj == null) {
72                 return false;
73             }
74             if (getClass() != obj.getClass()) {
75                 return false;
76             }
77             TestEnterpriseSpecificInformation other = (TestEnterpriseSpecificInformation) obj;
78             if (this.value != other.value) {
79                 return false;
80             }
81             return true;
82         }
83     }
84
85 }