BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / XROIPPrefixSubobject.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.subobject;
9
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
11
12 /**
13  * Parametrized structure of IP Prefix Subobject. Defined in RFC5521.
14  * 
15  * @see <a href="http://tools.ietf.org/html/rfc5521#section-2.1.1">Exclude Route Object definition</a>
16  * 
17  * @param <T> subtype of Prefix
18  */
19 public class XROIPPrefixSubobject extends ExcludeRouteSubobject {
20
21         private final XROSubobjectAttribute attribute;
22
23         private final IpPrefix prefix;
24
25         /**
26          * Constructs IPPrefix Subobject.
27          * 
28          * @param prefix T
29          * @param mandatory boolean
30          * @param attribute XROSubobjectAttribute
31          */
32         public XROIPPrefixSubobject(final IpPrefix prefix, final boolean mandatory, final XROSubobjectAttribute attribute) {
33                 super(mandatory);
34                 this.attribute = attribute;
35                 this.prefix = prefix;
36         }
37
38         /**
39          * Gets specific {@link Prefix}.
40          * 
41          * @return prefix T
42          */
43         public IpPrefix getPrefix() {
44                 return this.prefix;
45         }
46
47         /**
48          * Gets the attribute of the subobject
49          * 
50          * @return the attribute
51          */
52         public XROSubobjectAttribute getAttribute() {
53                 return this.attribute;
54         }
55
56         @Override
57         public int hashCode() {
58                 final int prime = 31;
59                 int result = super.hashCode();
60                 result = prime * result + ((this.attribute == null) ? 0 : this.attribute.hashCode());
61                 result = prime * result + ((this.prefix == null) ? 0 : this.prefix.hashCode());
62                 return result;
63         }
64
65         @Override
66         public boolean equals(final Object obj) {
67                 if (this == obj)
68                         return true;
69                 if (!super.equals(obj))
70                         return false;
71                 if (this.getClass() != obj.getClass())
72                         return false;
73                 final XROIPPrefixSubobject other = (XROIPPrefixSubobject) obj;
74                 if (this.attribute != other.attribute)
75                         return false;
76                 if (this.prefix == null) {
77                         if (other.prefix != null)
78                                 return false;
79                 } else if (!this.prefix.equals(other.prefix))
80                         return false;
81                 return true;
82         }
83
84         @Override
85         public String toString() {
86                 final StringBuilder builder = new StringBuilder();
87                 builder.append("XROIPPrefixSubobject [attribute=");
88                 builder.append(this.attribute);
89                 builder.append(", prefix=");
90                 builder.append(this.prefix);
91                 builder.append(", mandatory=");
92                 builder.append(this.mandatory);
93                 builder.append("]");
94                 return builder.toString();
95         }
96
97 }