2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.mode.impl.add;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.primitives.UnsignedInteger;
12 import javax.annotation.Nonnull;
14 public final class RouteKey implements Comparable<RouteKey> {
15 private final Long remotePathId;
16 private final UnsignedInteger routerId;
18 public RouteKey(final UnsignedInteger routerId, final Long remotePathId) {
19 this.routerId = routerId;
20 this.remotePathId = remotePathId != null ? remotePathId : 0;
23 private Long getExternalPathId() {
24 return this.remotePathId;
27 public UnsignedInteger getRouteId() {
31 private MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
32 toStringHelper.add("externalPathId", this.remotePathId);
33 toStringHelper.add("routerId", this.routerId);
34 return toStringHelper;
38 public int hashCode() {
41 result = prime * result + this.remotePathId.hashCode();
42 result = prime * result + this.routerId.hashCode();
47 public boolean equals(final Object obj) {
52 if (!(obj instanceof RouteKey)) {
56 final RouteKey other = (RouteKey) obj;
57 return this.remotePathId.equals(other.remotePathId) && this.routerId.equals(other.routerId);
61 public String toString() {
62 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
66 public int compareTo(@Nonnull final RouteKey otherRouteKey) {
67 final int routeIdCompareTo = this.routerId.compareTo(otherRouteKey.getRouteId());
68 return routeIdCompareTo == 0 ? this.remotePathId.compareTo(otherRouteKey.getExternalPathId())