Merge "Removed `which` dependency, now using proper shell builtin."
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / rpc / RpcContextIdentifier.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.sal.binding.api.rpc;
9
10 import org.opendaylight.yangtools.concepts.Immutable;
11 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
12 import org.opendaylight.yangtools.yang.binding.RpcService;
13
14 public final  class RpcContextIdentifier implements Immutable{
15
16     public final Class<? extends RpcService> rpcService;
17     public final Class<? extends BaseIdentity> routingContext;
18
19     private RpcContextIdentifier(Class<? extends RpcService> rpcService, Class<? extends BaseIdentity> routingContext) {
20         super();
21         this.rpcService = rpcService;
22         this.routingContext = routingContext;
23     }
24
25     public Class<? extends RpcService> getRpcService() {
26         return rpcService;
27     }
28
29     public Class<? extends BaseIdentity> getRoutingContext() {
30         return routingContext;
31     }
32
33     public static final RpcContextIdentifier contextForGlobalRpc(Class<? extends RpcService> serviceType) {
34         return new RpcContextIdentifier(serviceType, null);
35     }
36
37     public static final RpcContextIdentifier contextFor(Class<? extends RpcService> serviceType,Class<? extends BaseIdentity> routingContext) {
38         return new RpcContextIdentifier(serviceType, routingContext);
39     }
40
41     @Override
42     public int hashCode() {
43         final int prime = 31;
44         int result = 1;
45         result = prime * result + ((routingContext == null) ? 0 : routingContext.hashCode());
46         result = prime * result + ((rpcService == null) ? 0 : rpcService.hashCode());
47         return result;
48     }
49
50     @Override
51     public boolean equals(Object obj) {
52         if (this == obj)
53             return true;
54         if (obj == null)
55             return false;
56         if (getClass() != obj.getClass())
57             return false;
58         RpcContextIdentifier other = (RpcContextIdentifier) obj;
59         if (routingContext == null) {
60             if (other.routingContext != null)
61                 return false;
62         } else if (!routingContext.equals(other.routingContext))
63             return false;
64         if (rpcService == null) {
65             if (other.rpcService != null)
66                 return false;
67         } else if (!rpcService.equals(other.rpcService))
68             return false;
69         return true;
70     }
71
72 }