Replace Preconditions.CheckNotNull per RequireNonNull
[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 static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
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 = requireNonNull(afi, "Address family may not be null");
33         this.safi = requireNonNull(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         final int prime = 3;
44         int ret = prime * this.afi.hashCode();
45         ret += this.safi.hashCode();
46         return ret;
47     }
48
49     @Override
50     public boolean equals(final Object obj) {
51         if (obj instanceof BgpTableTypeImpl) {
52             final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
53             return this.afi.equals(o.afi) && this.safi.equals(o.safi);
54         }
55         return false;
56     }
57
58     @Override
59     public String toString() {
60         final StringBuilder builder = new StringBuilder();
61         builder.append("BgpTableTypeImpl [getAfi()=");
62         builder.append(getAfi());
63         builder.append(", getSafi()=");
64         builder.append(getSafi());
65         builder.append("]");
66         return builder.toString();
67     }
68
69     /**
70      * Returns Address Family Identifier.
71      *
72      * @return afi AFI
73      */
74     @Override
75     public Class<? extends AddressFamily> getAfi() {
76         return this.afi;
77     }
78
79     /**
80      * Returns Subsequent Address Family Identifier.
81      *
82      * @return safi SAFI
83      */
84     @Override
85     public Class<? extends SubsequentAddressFamily> getSafi() {
86         return this.safi;
87     }
88 }