a28ac20545e802b125fcd33e03eea82eb2c23641
[bgpcep.git] / bgp / parser-api / src / main / java / org / opendaylight / protocol / bgp / parser / BgpTableTypeImpl.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.parser;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
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 BgpTableTypeImpl implements BgpTableType {
20
21         private final Class<? extends SubsequentAddressFamily> safi;
22
23         private final Class<? extends AddressFamily> afi;
24
25         /**
26          * Creates BGP Table type.
27          * 
28          * @param afi Address Family Identifier
29          * @param safi Subsequent Address Family Identifier
30          */
31         public BgpTableTypeImpl(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
32                 this.afi = Preconditions.checkNotNull(afi, "Address family may not be null");
33                 this.safi = Preconditions.checkNotNull(safi, "Subsequent address family may not be null");
34         }
35
36         @Override
37         public int hashCode() {
38                 int ret = 3 * this.afi.hashCode();
39                 ret += this.safi.hashCode();
40                 return ret;
41         }
42
43         @Override
44         public boolean equals(final Object obj) {
45                 if (obj != null && obj instanceof BgpTableTypeImpl) {
46                         final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
47                         return this.afi.equals(o.afi) && this.safi.equals(o.safi);
48                 }
49                 return false;
50         }
51
52         @Override
53         public String toString() {
54                 return this.afi.toString() + "." + this.safi.toString();
55         }
56
57         /**
58          * Returns Address Family Identifier.
59          * 
60          * @return afi AFI
61          */
62         @Override
63         public Class<? extends AddressFamily> getAfi() {
64                 return this.afi;
65         }
66
67         /**
68          * Returns Subsequent Address Family Identifier.
69          * 
70          * @return safi SAFI
71          */
72         @Override
73         public Class<? extends SubsequentAddressFamily> getSafi() {
74                 return this.safi;
75         }
76 }