BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / EROIPPrefixSubobject.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
9 package org.opendaylight.protocol.pcep.subobject;
10
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
12
13 import com.google.common.base.Objects.ToStringHelper;
14
15 /**
16  * Parametrized structure of IP Prefix Subobject.
17  * 
18  * @see <a href="http://tools.ietf.org/html/rfc3209#section-4.3.3.2">Section 4.3.3.2.: Subobject 1: IPv4 prefix</a> and
19  *      <a href="http://tools.ietf.org/html/rfc3209#section-4.3.3.3">Section 4.3.3.2.: Subobject 2: IPv6 prefix</a>
20  * 
21  * @param <T> subtype of Prefix
22  */
23 public class EROIPPrefixSubobject extends ExplicitRouteSubobject {
24
25         private final IpPrefix prefix;
26
27         /**
28          * Constructs IPPrefix Subobject.
29          * 
30          * @param prefix T
31          * @param loose boolean
32          */
33         public EROIPPrefixSubobject(final IpPrefix prefix, final boolean loose) {
34                 super(loose);
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         @Override
48         public int hashCode() {
49                 final int prime = 31;
50                 int result = 1;
51                 result = prime * result + ((this.prefix == null) ? 0 : this.prefix.hashCode());
52                 return result;
53         }
54
55         @Override
56         public boolean equals(final Object obj) {
57                 if (this == obj)
58                         return true;
59                 if (obj == null)
60                         return false;
61                 if (this.getClass() != obj.getClass())
62                         return false;
63                 final EROIPPrefixSubobject other = (EROIPPrefixSubobject) obj;
64                 if (this.prefix == null) {
65                         if (other.prefix != null)
66                                 return false;
67                 } else if (!this.prefix.equals(other.prefix))
68                         return false;
69                 return true;
70         }
71
72         @Override
73         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
74                 toStringHelper.add("prefix", this.prefix);
75                 return super.addToStringAttributes(toStringHelper);
76         }
77
78 }