remove dependency of drool-application/yaml in actors
[policy/models.git] / models-interactions / model-yaml / src / main / java / org / onap / policy / controlloop / policy / guard / GuardPolicy.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 import java.util.UUID;
27
28 public class GuardPolicy {
29
30     private String id = UUID.randomUUID().toString();
31     private String name;
32     private String description;
33     private MatchParameters matchParameters;
34     private LinkedList<Constraint> limitConstraints;
35     
36     public GuardPolicy() {
37         //Do Nothing Empty Constructor. 
38     }
39     
40     public GuardPolicy(String id) {
41         this.id = id;
42     }
43     
44     public GuardPolicy(String name, MatchParameters matchParameters) {
45         this.name = name;
46         this.matchParameters = matchParameters;
47     }
48     
49     /**
50      * Constructor.
51      * 
52      * @param id id
53      * @param name name
54      * @param description description
55      * @param matchParameters match parameters
56      */
57     public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
58         this(name, matchParameters);
59         this.id = id;
60         this.description = description;
61     }
62     
63     /**
64      * Constructor.
65      * 
66      * @param name name
67      * @param matchParameters match parameters
68      * @param limitConstraints limit constraints
69      */
70     public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
71         this(name, matchParameters);
72         if (limitConstraints != null) {
73             this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
74         }
75     }
76     
77     public GuardPolicy(String name, String description, MatchParameters matchParameters, 
78                     List<Constraint> limitConstraints) {
79         this(name, matchParameters, limitConstraints);
80         this.description = description;
81     }
82     
83     public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, 
84                     List<Constraint> limitConstraints) {
85         this(name, description, matchParameters, limitConstraints);
86         this.id = id;
87     }
88     
89     /**
90      * Constructor.
91      * 
92      * @param policy copy object
93      */
94     public GuardPolicy(GuardPolicy policy) {
95         this.id = policy.id;
96         this.name = policy.name;
97         this.description = policy.description;
98         this.matchParameters = new MatchParameters(policy.matchParameters);
99         if (policy.limitConstraints != null) {
100             this.limitConstraints = policy.limitConstraints;
101         }
102     }
103     
104     public String getId() {
105         return id;
106     }
107
108     public void setId(String id) {
109         this.id = id;
110     }
111
112     public String getName() {
113         return name;
114     }
115
116     public void setName(String name) {
117         this.name = name;
118     }
119
120     public String getDescription() {
121         return description;
122     }
123
124     public void setDescription(String description) {
125         this.description = description;
126     }
127
128     public MatchParameters getMatch_parameters() {
129         return matchParameters;
130     }
131
132     public void setMatch_parameters(MatchParameters matchParameters) {
133         this.matchParameters = matchParameters;
134     }
135
136     public LinkedList<Constraint> getLimit_constraints() {
137         return  limitConstraints;
138     }
139
140     public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
141         this.limitConstraints = limitConstraints;
142     }
143
144     public boolean isValid() {
145         return (id == null || name == null) ? false : true;
146     }
147     
148     @Override
149     public String toString() {
150         return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters=" 
151                 + matchParameters + ", limitConstraints=" + limitConstraints + "]";
152     }
153
154     @Override
155     public int hashCode() {
156         final int prime = 31;
157         int result = 1;
158         result = prime * result + ((description == null) ? 0 : description.hashCode());
159         result = prime * result + ((id == null) ? 0 : id.hashCode());
160         result = prime * result + ((name == null) ? 0 : name.hashCode());
161         result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
162         result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
163         return result;
164     }
165
166     @Override
167     public boolean equals(Object obj) {
168         if (this == obj) {
169             return true;
170         }
171         if (obj == null) {
172             return false;
173         }
174         if (getClass() != obj.getClass()) {
175             return false;
176         }
177         GuardPolicy other = (GuardPolicy) obj;
178         return equalsMayBeNull(description, other.description)
179                 && equalsMayBeNull(id, other.id)
180                 && equalsMayBeNull(name, other.name)
181                 && equalsMayBeNull(limitConstraints, other.limitConstraints)
182                 && equalsMayBeNull(matchParameters, other.matchParameters);
183     }
184     
185     private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
186         if ( obj1 == null ) {
187             return obj2 == null;
188         }
189         return obj1.equals(obj2);
190     }        
191 }