1bf10734d02bd81c3f1d6fb6399478cf6c791cb7
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
4  * ================================================================================
5  * Copyright (C) 2017-2018 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     /**
75      * Constructor.
76      * 
77      * @param actor actor
78      * @param recipe recipe
79      * @param targets targets
80      */
81     public MatchParameters(String actor, String recipe, List<String> targets) {
82         this(actor, recipe);
83         if (targets != null) {
84             this.targets = new LinkedList<>(targets);
85         }
86     }
87
88     public MatchParameters(String controlLoopName, String actor, String recipe, List<String> targets) {
89         this(actor, recipe, targets);
90         this.controlLoopName = controlLoopName;
91     }
92
93     /**
94      * Constructor.
95      * 
96      * @param matchParameters match parameters
97      */
98     public MatchParameters(MatchParameters matchParameters) {
99
100         this.controlLoopName = matchParameters.controlLoopName;
101         this.actor = matchParameters.actor;
102         this.recipe = matchParameters.recipe;
103         if (matchParameters.targets != null) {
104             this.targets = new LinkedList<>(matchParameters.targets);
105         }
106     }
107
108     @Override
109     public String toString() {
110         return "MatchParameters [controlLoopName=" + controlLoopName + ", actor=" + actor + ", recipe=" + recipe
111                 + ", targets=" + targets + "]";
112     }
113
114     @Override
115     public int hashCode() {
116         final int prime = 31;
117         int result = 1;
118         result = prime * result + ((actor == null) ? 0 : actor.hashCode());
119         result = prime * result + ((controlLoopName == null) ? 0 : controlLoopName.hashCode());
120         result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
121         result = prime * result + ((targets == null) ? 0 : targets.hashCode());
122         return result;
123     }
124
125     @Override
126     public boolean equals(Object obj) {
127         if (this == obj) {
128             return true;
129         }
130         if (obj == null) {
131             return false;
132         }
133         if (getClass() != obj.getClass()) {
134             return false;
135         }
136         MatchParameters other = (MatchParameters) obj;
137         
138         return equalsMayBeNull(actor, other.actor)
139                 && equalsMayBeNull(controlLoopName, other.controlLoopName)
140                 && equalsMayBeNull(recipe, other.recipe)
141                 && equalsMayBeNull(targets, other.targets);
142     }
143     
144     private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
145         if (obj1 == null) {
146             return obj2 == null;
147         }
148         return obj1.equals(obj2);
149     }
150 }