Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / impl / base / BaseBestPath.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.mode.impl.base;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.primitives.UnsignedInteger;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
16 import org.opendaylight.protocol.bgp.mode.spi.AbstractBestPath;
17 import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
19
20 final class BaseBestPath extends AbstractBestPath {
21     private static final long PATH_ID = 0;
22     private final UnsignedInteger routerId;
23
24     BaseBestPath(@Nonnull final UnsignedInteger routerId, @Nonnull final BestPathState state) {
25         super(state);
26         this.routerId = requireNonNull(routerId);
27     }
28
29     @Override
30     public UnsignedInteger getRouterId() {
31         return this.routerId;
32     }
33
34     @Override
35     public PeerId getPeerId() {
36         return RouterIds.createPeerId(this.routerId);
37     }
38
39     @Override
40     public long getPathId() {
41         return PATH_ID;
42     }
43
44     @Override
45     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
46         toStringHelper.add("routerId", this.routerId);
47         toStringHelper.add("state", this.state);
48         return toStringHelper;
49     }
50
51     @Override
52     public int hashCode() {
53         final int prime = 31;
54         int result = 1;
55         result = prime * result + this.routerId.hashCode();
56         result = prime * result + this.state.hashCode();
57         return result;
58     }
59
60     @Override
61     public boolean equals(final Object obj) {
62         if (this == obj) {
63             return true;
64         }
65         if (!(obj instanceof BaseBestPath)) {
66             return false;
67         }
68         final BaseBestPath other = (BaseBestPath) obj;
69         if (!this.routerId.equals(other.routerId)) {
70             return false;
71         }
72         if (!this.state.equals(other.state)) {
73             return false;
74         }
75         return true;
76     }
77 }