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