Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPClassTypeObject.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.protocol.pcep.object;
9
10 import org.opendaylight.protocol.pcep.PCEPObject;
11 import com.google.common.base.Objects.ToStringHelper;
12
13 /**
14  * Structure of ClassType Object.
15  *
16  * @see <a href="http://tools.ietf.org/html/rfc5455#section-5"> Object
17  *      Definition</a>
18  */
19 public class PCEPClassTypeObject extends PCEPObject {
20
21     private final short classType;
22
23     /**
24      * Constructs ClassType Object with given class type.
25      *
26      * @param classType
27      *            short, must be positive and less than 8.
28      */
29     public PCEPClassTypeObject(short classType) {
30         super(true, false);
31         if (classType < 0 || classType > 7) {
32             throw new IllegalArgumentException("ClassType range overstepped.");
33         }
34         this.classType = classType;
35     }
36
37     /**
38      * Gets class type.
39      *
40      * @return class type
41      */
42     public short getClassType() {
43         return this.classType;
44     }
45
46     @Override
47     public int hashCode() {
48         final int prime = 31;
49         int result = super.hashCode();
50         result = prime * result + this.classType;
51         return result;
52     }
53
54     @Override
55     public boolean equals(Object obj) {
56         if (this == obj)
57             return true;
58         if (!super.equals(obj))
59             return false;
60         if (!(obj instanceof PCEPClassTypeObject))
61             return false;
62         final PCEPClassTypeObject other = (PCEPClassTypeObject) obj;
63         if (this.classType != other.classType)
64             return false;
65         return true;
66     }
67
68         @Override
69         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
70                 toStringHelper.add("classType", this.classType);
71                 return super.addToStringAttributes(toStringHelper);
72         }
73 }