03763d5464233832881e8a4602926f7994f768df
[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 Class<BgpTableType> getImplementedInterface() {
38                 return BgpTableType.class;
39         }
40
41         @Override
42         public int hashCode() {
43                 int ret = 3 * this.afi.hashCode();
44                 ret += this.safi.hashCode();
45                 return ret;
46         }
47
48         @Override
49         public boolean equals(final Object obj) {
50                 if (obj != null && obj instanceof BgpTableTypeImpl) {
51                         final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
52                         return this.afi.equals(o.afi) && this.safi.equals(o.safi);
53                 }
54                 return false;
55         }
56
57         @Override
58         public String toString() {
59                 return this.afi.toString() + "." + this.safi.toString();
60         }
61
62         /**
63          * Returns Address Family Identifier.
64          * 
65          * @return afi AFI
66          */
67         @Override
68         public Class<? extends AddressFamily> getAfi() {
69                 return this.afi;
70         }
71
72         /**
73          * Returns Subsequent Address Family Identifier.
74          * 
75          * @return safi SAFI
76          */
77         @Override
78         public Class<? extends SubsequentAddressFamily> getSafi() {
79                 return this.safi;
80         }
81 }