Initial code drop
[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.protocol.concepts.Prefix;
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
16  *      Object definition</a>
17  *
18  * @param <T>
19  *            subtype of Prefix
20  */
21 public class XROIPPrefixSubobject<T extends Prefix<?>> extends ExcludeRouteSubobject {
22
23         private final XROSubobjectAttribute attribute;
24
25         private final T prefix;
26
27         /**
28          * Constructs IPPrefix Subobject.
29          *
30          * @param prefix
31          *            T
32          * @param mandatory
33          *            boolean
34          * @param attribute
35          *            XROSubobjectAttribute
36          */
37         public XROIPPrefixSubobject(T prefix, boolean mandatory, XROSubobjectAttribute attribute) {
38                 super(mandatory);
39                 this.attribute = attribute;
40                 this.prefix = prefix;
41         }
42
43         /**
44          * Gets specific {@link Prefix}.
45          *
46          * @return prefix T
47          */
48         public T getPrefix() {
49                 return this.prefix;
50         }
51
52         /**
53          * Gets the attribute of the subobject
54          *
55          * @return the attribute
56          */
57         public XROSubobjectAttribute getAttribute() {
58                 return this.attribute;
59         }
60
61         @Override
62         public int hashCode() {
63                 final int prime = 31;
64                 int result = super.hashCode();
65                 result = prime * result + ((this.attribute == null) ? 0 : this.attribute.hashCode());
66                 result = prime * result + ((this.prefix == null) ? 0 : this.prefix.hashCode());
67                 return result;
68         }
69
70         @Override
71         public boolean equals(Object obj) {
72                 if (this == obj)
73                         return true;
74                 if (!super.equals(obj))
75                         return false;
76                 if (this.getClass() != obj.getClass())
77                         return false;
78                 final XROIPPrefixSubobject<?> other = (XROIPPrefixSubobject<?>) obj;
79                 if (this.attribute != other.attribute)
80                         return false;
81                 if (this.prefix == null) {
82                         if (other.prefix != null)
83                                 return false;
84                 } else if (!this.prefix.equals(other.prefix))
85                         return false;
86                 return true;
87         }
88
89         @Override
90         public String toString() {
91                 final StringBuilder builder = new StringBuilder();
92                 builder.append("XROIPPrefixSubobject [attribute=");
93                 builder.append(this.attribute);
94                 builder.append(", prefix=");
95                 builder.append(this.prefix);
96                 builder.append(", mandatory=");
97                 builder.append(this.mandatory);
98                 builder.append("]");
99                 return builder.toString();
100         }
101
102 }