Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / policy-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  * ================================================================================
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 MatchParameters(String actor, String recipe) {
38         this.actor = actor;
39         this.recipe = recipe;
40     }
41
42     /**
43      * Constructor.
44      * 
45      * @param actor actor
46      * @param recipe recipe
47      * @param targets targets
48      */
49     public MatchParameters(String actor, String recipe, List<String> targets) {
50         this(actor, recipe);
51         if (targets != null) {
52             this.targets = new LinkedList<>(targets);
53         }
54     }
55
56     public MatchParameters(String controlLoopName, String actor, String recipe, List<String> targets) {
57         this(actor, recipe, targets);
58         this.controlLoopName = controlLoopName;
59     }
60
61     /**
62      * Constructor.
63      * 
64      * @param matchParameters match parameters
65      */
66     public MatchParameters(MatchParameters matchParameters) {
67
68         this.controlLoopName = matchParameters.controlLoopName;
69         this.actor = matchParameters.actor;
70         this.recipe = matchParameters.recipe;
71         if (matchParameters.targets != null) {
72             this.targets = new LinkedList<>(matchParameters.targets);
73         }
74     }
75
76     public String getControlLoopName() {
77         return controlLoopName;
78     }
79
80     public void setControlLoopName(String controlLoopName) {
81         this.controlLoopName = controlLoopName;
82     }
83
84     public String getActor() {
85         return actor;
86     }
87
88     public void setActor(String actor) {
89         this.actor = actor;
90     }
91
92     public String getRecipe() {
93         return recipe;
94     }
95
96     public void setRecipe(String recipe) {
97         this.recipe = recipe;
98     }
99
100     public List<String> getTargets() {
101         return targets;
102     }
103
104     public void setTargets(List<String> targets) {
105         this.targets = targets;
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 }