Merge "BUG 2820 - LLDP refactor"
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RouteIdentifierImpl.java
1 /*
2  * Copyright (c) 2014 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.controller.remote.rpc;
9
10 import com.google.common.base.Preconditions;
11 import java.io.Serializable;
12 import org.opendaylight.controller.sal.connector.api.RpcRouter;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15
16 public class RouteIdentifierImpl implements RpcRouter.RouteIdentifier<QName, QName, YangInstanceIdentifier>,Serializable {
17   private static final long serialVersionUID = 1L;
18
19   private final QName context;
20   private final QName type;
21   private final YangInstanceIdentifier route;
22
23   public RouteIdentifierImpl(final QName context, final QName type, final YangInstanceIdentifier route) {
24     Preconditions.checkNotNull(type, "Rpc type should not be null");
25     this.context = context;
26     this.type = type;
27     this.route = route;
28   }
29
30   @Override
31   public QName getContext() {
32     return context;
33   }
34
35   @Override
36   public QName getType() {
37     return type;
38   }
39
40   @Override
41   public YangInstanceIdentifier getRoute() {
42     return route;
43   }
44
45
46   @Override
47   public boolean equals(final Object o) {
48     if (this == o) return true;
49     if (o == null || getClass() != o.getClass()) return false;
50
51     final RouteIdentifierImpl that = (RouteIdentifierImpl) o;
52
53     if (context == null){
54       if (that.getContext() != null)  return false;
55     }else
56       if (!context.equals(that.context)) return false;
57
58     if (route == null){
59       if (that.getRoute() != null) return false;
60     }else
61       if (!route.equals(that.route)) return false;
62
63     if (type == null){
64       if (that.getType() != null) return false;
65     }else
66       if (!type.equals(that.type)) return false;
67
68     return true;
69   }
70
71   @Override
72   public int hashCode() {
73     final int prime = 31;
74     int result = 0;
75     result = prime * result + (context == null ? 0:context.hashCode());
76     result = prime * result + (type    == null ? 0:type.hashCode());
77     result = prime * result + (route   == null ? 0:route.hashCode());
78     return result;
79   }
80
81   @Override
82   public String toString() {
83     return "RouteIdentifierImpl{" +
84         "context=" + context +
85         ", type=" + type +
86         ", route=" + route +
87         '}';
88   }
89 }