Merge "Refactor Subnet.isSubnetOf - reduce number of 'if' statements. Added unitests."
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / spi / RpcContextIdentifier.java
1 package org.opendaylight.controller.sal.binding.spi;
2
3 import org.opendaylight.yangtools.concepts.Immutable;
4 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
5 import org.opendaylight.yangtools.yang.binding.RpcService;
6
7 public final  class RpcContextIdentifier implements Immutable{
8
9     public final Class<? extends RpcService> rpcService;
10     public final Class<? extends BaseIdentity> routingContext;
11    
12     private RpcContextIdentifier(Class<? extends RpcService> rpcService, Class<? extends BaseIdentity> routingContext) {
13         super();
14         this.rpcService = rpcService;
15         this.routingContext = routingContext;
16     }
17
18     public Class<? extends RpcService> getRpcService() {
19         return rpcService;
20     }
21
22     public Class<? extends BaseIdentity> getRoutingContext() {
23         return routingContext;
24     }
25     
26     public static final RpcContextIdentifier contextForGlobalRpc(Class<? extends RpcService> serviceType) {
27         return new RpcContextIdentifier(serviceType, null);
28     }
29     
30     public static final RpcContextIdentifier contextFor(Class<? extends RpcService> serviceType,Class<? extends BaseIdentity> routingContext) {
31         return new RpcContextIdentifier(serviceType, routingContext);
32     }
33
34     @Override
35     public int hashCode() {
36         final int prime = 31;
37         int result = 1;
38         result = prime * result + ((routingContext == null) ? 0 : routingContext.hashCode());
39         result = prime * result + ((rpcService == null) ? 0 : rpcService.hashCode());
40         return result;
41     }
42
43     @Override
44     public boolean equals(Object obj) {
45         if (this == obj)
46             return true;
47         if (obj == null)
48             return false;
49         if (getClass() != obj.getClass())
50             return false;
51         RpcContextIdentifier other = (RpcContextIdentifier) obj;
52         if (routingContext == null) {
53             if (other.routingContext != null)
54                 return false;
55         } else if (!routingContext.equals(other.routingContext))
56             return false;
57         if (rpcService == null) {
58             if (other.rpcService != null)
59                 return false;
60         } else if (!rpcService.equals(other.rpcService))
61             return false;
62         return true;
63     }
64
65 }