445e00f389dbc8afe5f040d0a2c396199268028e
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.policy.guard;
22
23 import java.util.LinkedList;
24 import java.util.List;
25
26
27 public class MatchParameters {
28     private String controlLoopName;
29     private String actor;
30     private String recipe;
31     private List<String> targets;
32
33     public MatchParameters() {
34         // Do Nothing Empty Constructor.
35     }   
36     
37     public String getControlLoopName() {
38         return controlLoopName;
39     }
40
41     public void setControlLoopName(String controlLoopName) {
42         this.controlLoopName = controlLoopName;
43     }
44
45     public String getActor() {
46         return actor;
47     }
48
49     public void setActor(String actor) {
50         this.actor = actor;
51     }
52
53     public String getRecipe() {
54         return recipe;
55     }
56
57     public void setRecipe(String recipe) {
58         this.recipe = recipe;
59     }
60
61     public List<String> getTargets() {
62         return targets;
63     }
64
65     public void setTargets(List<String> targets) {
66         this.targets = targets;
67     }
68
69     public MatchParameters(String actor, String recipe) {
70         this.actor = actor;
71         this.recipe = recipe;
72     }
73
74     public MatchParameters(String actor, String recipe, List<String> targets) {
75         this(actor, recipe);
76         if (targets != null) {
77             this.targets = new LinkedList<>(targets);
78         }
79     }
80
81     public MatchParameters(String controlLoopName, String actor, String recipe, List<String> targets) {
82         this(actor, recipe, targets);
83         this.controlLoopName = controlLoopName;
84     }
85
86     public MatchParameters(MatchParameters matchParameters) {
87
88         this.controlLoopName = matchParameters.controlLoopName;
89         this.actor = matchParameters.actor;
90         this.recipe = matchParameters.recipe;
91         if (matchParameters.targets != null) {
92             this.targets = new LinkedList<>(matchParameters.targets);
93         }
94     }
95
96     @Override
97     public String toString() {
98         return "MatchParameters [controlLoopName=" + controlLoopName + ", actor=" + actor + ", recipe=" + recipe
99                 + ", targets=" + targets + "]";
100     }
101
102     @Override
103     public int hashCode() {
104         final int prime = 31;
105         int result = 1;
106         result = prime * result + ((actor == null) ? 0 : actor.hashCode());
107         result = prime * result + ((controlLoopName == null) ? 0 : controlLoopName.hashCode());
108         result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
109         result = prime * result + ((targets == null) ? 0 : targets.hashCode());
110         return result;
111     }
112
113     @Override
114     public boolean equals(Object obj) {
115         if (this == obj)
116             return true;
117         if (obj == null)
118             return false;
119         if (getClass() != obj.getClass())
120             return false;
121         MatchParameters other = (MatchParameters) obj;
122         
123         return equalsMayBeNull(actor, other.actor)
124                         && equalsMayBeNull(controlLoopName, other.controlLoopName)
125                         && equalsMayBeNull(recipe, other.recipe)
126                         && equalsMayBeNull(targets, other.targets);
127     }
128     
129     private boolean equalsMayBeNull(final Object obj1, final Object obj2){
130         if ( obj1 == null ) {
131             return obj2 == null;
132         }
133         return obj1.equals(obj2);
134     }
135 }