b5f18d604f6f4fb92dd7940c0fafc07afa78379f
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / policy / RendererResolvedPolicy.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
10
11 import javax.annotation.Nonnull;
12 import javax.annotation.concurrent.Immutable;
13
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.EndpointPolicyParticipation;
15
16 import com.google.common.base.Preconditions;
17
18 @Immutable
19 public class RendererResolvedPolicy implements Comparable<RendererResolvedPolicy> {
20
21     private final EndpointPolicyParticipation rendererEndpointParticipation;
22     private final ResolvedRuleGroup ruleGroup;
23
24     public RendererResolvedPolicy(@Nonnull EndpointPolicyParticipation rendererEndpointParticipation,
25             @Nonnull ResolvedRuleGroup ruleGroupInfo) {
26         this.rendererEndpointParticipation = Preconditions.checkNotNull(rendererEndpointParticipation);
27         this.ruleGroup = Preconditions.checkNotNull(ruleGroupInfo);
28     }
29
30     public EndpointPolicyParticipation getRendererEndpointParticipation() {
31         return rendererEndpointParticipation;
32     }
33
34     public ResolvedRuleGroup getRuleGroup() {
35         return ruleGroup;
36     }
37
38     @Override
39     public int compareTo(RendererResolvedPolicy arg0) {
40         return ruleGroup.compareTo(arg0.getRuleGroup());
41     }
42
43     @Override
44     public int hashCode() {
45         final int prime = 31;
46         int result = 1;
47         result = prime * result
48                 + ((rendererEndpointParticipation == null) ? 0 : rendererEndpointParticipation.hashCode());
49         result = prime * result + ((ruleGroup == null) ? 0 : ruleGroup.hashCode());
50         return result;
51     }
52
53     @Override
54     public boolean equals(Object obj) {
55         if (this == obj)
56             return true;
57         if (obj == null)
58             return false;
59         if (getClass() != obj.getClass())
60             return false;
61         RendererResolvedPolicy other = (RendererResolvedPolicy) obj;
62         if (rendererEndpointParticipation != other.rendererEndpointParticipation)
63             return false;
64         if (ruleGroup == null) {
65             if (other.ruleGroup != null)
66                 return false;
67         } else if (!ruleGroup.equals(other.ruleGroup))
68             return false;
69         return true;
70     }
71
72     @Override
73     public String toString() {
74         return "RendererResolvedPolicy [rendererEndpointParticipation=" + rendererEndpointParticipation + ", ruleGroup="
75                 + ruleGroup + "]";
76     }
77
78 }