Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / RouteUpdateKey.java
1 /*
2  * Copyright (c) 2015 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.rib.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14
15 /**
16  * Combined key formed as a concatenation of source peer and route identifiers.
17  * This is used to internally track updates which need to be processed.
18  */
19 final class RouteUpdateKey {
20     private final PeerId peerId;
21     private final PathArgument routeId;
22
23     RouteUpdateKey(final PeerId peerId, final PathArgument routeId) {
24         this.peerId = requireNonNull(peerId);
25         this.routeId = requireNonNull(routeId);
26     }
27
28     PeerId getPeerId() {
29         return this.peerId;
30     }
31
32     PathArgument getRouteId() {
33         return this.routeId;
34     }
35
36     @Override
37     public int hashCode() {
38         final int prime = 31;
39         int result = 1;
40         result = prime * result + this.peerId.hashCode();
41         result = prime * result + this.routeId.hashCode();
42         return result;
43     }
44
45     @Override
46     public boolean equals(final Object obj) {
47         if (this == obj) {
48             return true;
49         }
50         if (!(obj instanceof RouteUpdateKey)) {
51             return false;
52         }
53         RouteUpdateKey other = (RouteUpdateKey) obj;
54         if (!this.peerId.equals(other.peerId)) {
55             return false;
56         }
57         if (!this.routeId.equals(other.routeId)) {
58             return false;
59         }
60         return true;
61     }
62 }