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