dc9aee8c8879a566ef3cc6480a49de3676914228
[bgpcep.git] / bgp / concepts / src / main / java / org / opendaylight / protocol / bgp / concepts / BGPTableType.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.bgp.concepts;
9
10 import org.opendaylight.protocol.concepts.Identifier;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
13
14 import com.google.common.base.Preconditions;
15
16 /**
17  * Utility class identifying a BGP table type. A table type is formed by two identifiers: AFI and SAFI.
18  */
19 public final class BGPTableType implements Identifier {
20
21         private static final long serialVersionUID = -5502662876916458740L;
22
23         private final Class<? extends SubsequentAddressFamily> safi;
24
25         private final Class<? extends AddressFamily> afi;
26
27         /**
28          * Creates BGP Table type.
29          * 
30          * @param afi Address Family Identifier
31          * @param safi Subsequent Address Family Identifier
32          */
33         public BGPTableType(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
34                 this.afi = Preconditions.checkNotNull(afi, "Address family may not be null");
35                 this.safi = Preconditions.checkNotNull(safi, "Subsequent address family may not be null");
36         }
37
38         /**
39          * Returns Address Family Identifier.
40          * 
41          * @return afi AFI
42          */
43         public Class<? extends AddressFamily> getAddressFamily() {
44                 return this.afi;
45         }
46
47         /**
48          * Returns Subsequent Address Family Identifier.
49          * 
50          * @return safi SAFI
51          */
52         public Class<? extends SubsequentAddressFamily> getSubsequentAddressFamily() {
53                 return this.safi;
54         }
55
56         @Override
57         public int hashCode() {
58                 int ret = 3 * this.afi.hashCode();
59                 ret += this.safi.hashCode();
60                 return ret;
61         }
62
63         @Override
64         public boolean equals(final Object obj) {
65                 if (obj != null && obj instanceof BGPTableType) {
66                         final BGPTableType o = (BGPTableType) obj;
67                         return this.afi.equals(o.afi) && this.safi.equals(o.safi);
68                 }
69                 return false;
70         }
71
72         @Override
73         public String toString() {
74                 return this.afi.toString() + "." + this.safi.toString();
75         }
76 }