Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPBandwidthObject.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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
12
13 import com.google.common.base.Objects.ToStringHelper;
14
15 /**
16  * Basic structure of Bandwidth Object.
17  * 
18  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.7">PCEP Bandwidth Object</a>
19  */
20 public abstract class PCEPBandwidthObject extends PCEPObject {
21
22         private final Bandwidth bandwidth;
23
24         /**
25          * Constructs basic Bandwidth Object.
26          * 
27          * @param bandwidth Bandwidth
28          * @param processed boolean
29          * @param ignored boolean
30          */
31         public PCEPBandwidthObject(final Bandwidth bandwidth, final boolean processed, final boolean ignored) {
32                 super(processed, ignored);
33                 if (bandwidth == null)
34                         this.bandwidth = new Bandwidth(new byte[] { 0 });
35                 else
36                         this.bandwidth = bandwidth;
37         }
38
39         /**
40          * Gets {@link PCEPBandwidthObject}.
41          * 
42          * @return Bandwidth. Can't be null.
43          */
44         public Bandwidth getBandwidth() {
45                 return this.bandwidth;
46         }
47
48         @Override
49         public int hashCode() {
50                 final int prime = 31;
51                 int result = super.hashCode();
52                 result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode());
53                 return result;
54         }
55
56         @Override
57         public boolean equals(final Object obj) {
58                 if (this == obj)
59                         return true;
60                 if (!super.equals(obj))
61                         return false;
62                 if (this.getClass() != obj.getClass())
63                         return false;
64                 final PCEPBandwidthObject other = (PCEPBandwidthObject) obj;
65                 if (this.bandwidth == null) {
66                         if (other.bandwidth != null)
67                                 return false;
68                 } else if (!this.bandwidth.equals(other.bandwidth))
69                         return false;
70                 return true;
71         }
72
73         @Override
74         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
75                 toStringHelper.add("bandwidth", this.bandwidth);
76                 return super.addToStringAttributes(toStringHelper);
77         }
78 }