a850b36ed1c82c645a1c4d92ba4a6eecf6122409
[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 String actor;
34         public String recipe;
35         public LinkedList<Constraint> limit_constraints;
36         
37         public GuardPolicy() {
38                 
39         }
40         
41         public GuardPolicy(String id) {
42                 this.id = id;
43         }
44         
45         public GuardPolicy(String name, String actor, String recipe) {
46                 this.name = name;
47                 this.actor = actor;
48                 this.recipe = recipe;
49         }
50         
51         public GuardPolicy(String id, String name, String description, String actor, String recipe) {
52                 this(name, actor, recipe);
53                 this.id = id;
54                 this.description = description;
55         }
56         
57         public GuardPolicy(String name, String actor, String recipe, List<Constraint> limit_constraints) {
58                 this(name, actor, recipe);
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, String actor, String recipe, List<Constraint> limit_constraints) {
65                 this(name, actor, recipe, limit_constraints);
66                 this.description = description;
67         }
68         
69         public GuardPolicy(String id, String name, String description, String actor, String recipe, List<Constraint> limit_constraints) {
70                 this(name, description, actor, recipe, limit_constraints);
71                 this.id = id;
72         }
73         
74         public GuardPolicy(GuardPolicy policy) {
75                 this.id = policy.id;
76                 this.name = policy.name;
77                 this.description = policy.description;
78                 this.actor = policy.actor;
79                 this.recipe = policy.recipe;
80                 if (policy.limit_constraints != null) {
81                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(policy.limit_constraints);
82                 }
83         }
84         
85         public boolean isValid() {
86                 try {
87                         if (id == null) {
88                                 throw new NullPointerException();
89                         }
90                         if (name == null) {
91                                 throw new NullPointerException();
92                         }
93                         if (actor == null) {
94                                 throw new NullPointerException();
95                         }
96                         if (recipe == null) {
97                                 throw new NullPointerException();
98                         }
99                 } catch (Exception e) {
100                         return false;
101                 }
102                 return true;
103         }
104         
105         @Override
106         public String toString() {
107                 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe="
108                                 + recipe + ", limit_constraints=" + limit_constraints + "]";
109         }
110
111         @Override
112         public int hashCode() {
113                 final int prime = 31;
114                 int result = 1;
115                 result = prime * result + ((actor == null) ? 0 : actor.hashCode());
116                 result = prime * result + ((description == null) ? 0 : description.hashCode());
117                 result = prime * result + ((id == null) ? 0 : id.hashCode());
118                 result = prime * result + ((name == null) ? 0 : name.hashCode());
119                 result = prime * result + ((limit_constraints == null) ? 0 : limit_constraints.hashCode());
120                 result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
121                 return result;
122         }
123
124         @Override
125         public boolean equals(Object obj) {
126                 if (this == obj)
127                         return true;
128                 if (obj == null)
129                         return false;
130                 if (getClass() != obj.getClass())
131                         return false;
132                 GuardPolicy other = (GuardPolicy) obj;
133                 if (actor == null) {
134                         if (other.actor != null) 
135                                 return false;
136                 } else if (!actor.equals(other.actor))
137                         return false;
138                 if (description == null) {
139                         if (other.description != null)
140                                 return false;
141                 } else if (!description.equals(other.description))
142                         return false;
143                 if (id == null) {
144                         if (other.id != null)
145                                 return false;
146                 } else if (!id.equals(other.id))
147                         return false;
148                 if (name == null) {
149                         if (other.name != null)
150                                 return false;
151                 } else if (!name.equals(other.name))
152                         return false;
153                 if (limit_constraints == null) {
154                         if (other.limit_constraints != null)
155                                 return false;
156                 } else if (!limit_constraints.equals(other.limit_constraints))
157                         return false;
158                 if (recipe == null) {
159                         if (other.recipe != null)
160                                 return false;
161                 } else if (!recipe.equals(other.recipe))
162                         return false;
163                 return true;
164         }
165         
166         
167 }