2 * Copyright (c) 2013 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.concepts;
10 import org.opendaylight.protocol.concepts.NetworkAddress;
11 import com.google.common.base.Objects;
12 import com.google.common.base.Objects.ToStringHelper;
13 import com.google.common.base.Preconditions;
16 * Abstract implementation of a NextHop class. This is a useful base class
17 * implementing all the required semantics for a NextHop. Subclasses only
18 * need to supply an appropriate public constructor.
20 * @param <T> template reference to subclass
22 public abstract class AbstractNextHop<T extends NetworkAddress<T>> implements NextHop<T> {
23 private static final long serialVersionUID = 2462286640242941943L;
24 private final T global;
25 private final T linkLocal;
27 protected AbstractNextHop(final T global, final T linkLocal) {
28 this.global = Preconditions.checkNotNull(global);
29 this.linkLocal = linkLocal;
33 public T getGlobal() {
38 public T getLinkLocal() {
43 public int hashCode() {
46 result = prime * result + ((global == null) ? 0 : global.hashCode());
47 result = prime * result
48 + ((linkLocal == null) ? 0 : linkLocal.hashCode());
53 public boolean equals(final Object obj) {
58 if (getClass() != obj.getClass())
60 final AbstractNextHop<?> other = (AbstractNextHop<?>) obj;
62 if (other.global != null)
64 } else if (!global.equals(other.global))
66 if (linkLocal == null) {
67 if (other.linkLocal != null)
69 } else if (!linkLocal.equals(other.linkLocal))
75 public final String toString() {
76 return addToStringAttributes(Objects.toStringHelper(this)).toString();
79 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
80 toStringHelper.add("global", global);
81 toStringHelper.add("linkLocal", linkLocal);
82 return toStringHelper;