f0267b3ada5986006fd9131f5db60ba452603178
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
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
21 package org.onap.policy.controlloop.policy.guard;
22
23 import java.util.Collections;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.UUID;
27
28 public class GuardPolicy {
29
30         public String id = UUID.randomUUID().toString();
31         public String name;
32         public String description;
33         public MatchParameters match_parameters;
34         public LinkedList<Constraint> limit_constraints;
35         
36         
37 public GuardPolicy() {
38                 
39         }
40         
41         public GuardPolicy(String id) {
42                 this.id = id;
43         }
44         
45         public GuardPolicy(String name, MatchParameters match_parameters) {
46                 this.name = name;
47                 System.out.println("match_parameters: " + match_parameters);
48                 this.match_parameters = new MatchParameters(match_parameters);
49         }
50         
51         public GuardPolicy(String id, String name, String description, MatchParameters match_parameters) {
52                 this(name, match_parameters);
53                 this.id = id;
54                 this.description = description;
55         }
56         
57         public GuardPolicy(String name, MatchParameters match_parameters, List<Constraint> limit_constraints) {
58                 this(name, match_parameters);
59                 if (limit_constraints != null) {
60                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(limit_constraints);
61                 }
62         }
63         
64         public GuardPolicy(String name, String description, MatchParameters match_parameters, List<Constraint> limit_constraints) {
65                 this(name, match_parameters, limit_constraints);
66                 this.description = description;
67         }
68         
69         public GuardPolicy(String id, String name, String description, MatchParameters match_parameters, List<Constraint> limit_constraints) {
70                 this(name, description, match_parameters, limit_constraints);
71                 this.id = id;
72         }
73         
74         
75         
76         
77         
78         
79         public GuardPolicy(GuardPolicy policy) {
80                 this.id = policy.id;
81                 this.name = policy.name;
82                 this.description = policy.description;
83                 this.match_parameters = new MatchParameters(policy.match_parameters);
84                 if (policy.limit_constraints != null) {
85                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(policy.limit_constraints);
86                 }
87         }
88         
89         public boolean isValid() {
90                 try {
91                         if (id == null) {
92                                 throw new NullPointerException();
93                         }
94                         if (name == null) {
95                                 throw new NullPointerException();
96                         }
97                         
98                 } catch (Exception e) {
99                         return false;
100                 }
101                 return true;
102         }
103         
104         @Override
105         public String toString() {
106                 return "GuardPolicy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
107                                 + match_parameters + ", limit_constraints=" + limit_constraints + "]";
108         }
109
110         @Override
111         public int hashCode() {
112                 final int prime = 31;
113                 int result = 1;
114                 result = prime * result + ((description == null) ? 0 : description.hashCode());
115                 result = prime * result + ((id == null) ? 0 : id.hashCode());
116                 result = prime * result + ((limit_constraints == null) ? 0 : limit_constraints.hashCode());
117                 result = prime * result + ((match_parameters == null) ? 0 : match_parameters.hashCode());
118                 result = prime * result + ((name == null) ? 0 : name.hashCode());
119                 return result;
120         }
121
122         @Override
123         public boolean equals(Object obj) {
124                 if (this == obj)
125                         return true;
126                 if (obj == null)
127                         return false;
128                 if (getClass() != obj.getClass())
129                         return false;
130                 GuardPolicy other = (GuardPolicy) obj;
131                 if (description == null) {
132                         if (other.description != null)
133                                 return false;
134                 } else if (!description.equals(other.description))
135                         return false;
136                 if (id == null) {
137                         if (other.id != null)
138                                 return false;
139                 } else if (!id.equals(other.id))
140                         return false;
141                 if (limit_constraints == null) {
142                         if (other.limit_constraints != null)
143                                 return false;
144                 } else if (!limit_constraints.equals(other.limit_constraints))
145                         return false;
146                 if (match_parameters == null) {
147                         if (other.match_parameters != null)
148                                 return false;
149                 } else if (!match_parameters.equals(other.match_parameters))
150                         return false;
151                 if (name == null) {
152                         if (other.name != null)
153                                 return false;
154                 } else if (!name.equals(other.name))
155                         return false;
156                 return true;
157         }
158         
159         
160 }