97d3d6faf6fe88436da655a6a1654d1856a2d1c2
[policy/drools-applications.git] /
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * policy-yaml\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.onap.policy.controlloop.policy.guard;\r
22 \r
23 import java.util.Collections;\r
24 import java.util.LinkedList;\r
25 import java.util.List;\r
26 import java.util.UUID;\r
27 \r
28 public class GuardPolicy {\r
29 \r
30     private String id = UUID.randomUUID().toString();\r
31     private String name;\r
32     private String description;\r
33     private MatchParameters match_parameters;\r
34     private LinkedList<Constraint> limit_constraints;\r
35     \r
36     public GuardPolicy() {\r
37         //Do Nothing Empty Constructor. \r
38     }\r
39     \r
40     public String getId() {\r
41         return id;\r
42     }\r
43 \r
44     public void setId(String id) {\r
45         this.id = id;\r
46     }\r
47 \r
48     public String getName() {\r
49         return name;\r
50     }\r
51 \r
52     public void setName(String name) {\r
53         this.name = name;\r
54     }\r
55 \r
56     public String getDescription() {\r
57         return description;\r
58     }\r
59 \r
60     public void setDescription(String description) {\r
61         this.description = description;\r
62     }\r
63 \r
64     public MatchParameters getMatch_parameters() {\r
65         return match_parameters;\r
66     }\r
67 \r
68     public void setMatch_parameters(MatchParameters match_parameters) {\r
69         this.match_parameters = match_parameters;\r
70     }\r
71 \r
72     public LinkedList<Constraint> getLimit_constraints() {\r
73         return  limit_constraints;\r
74     }\r
75 \r
76     public void setLimit_constraints(LinkedList<Constraint> limit_constraints) {\r
77         this.limit_constraints = limit_constraints;\r
78     }\r
79 \r
80     public GuardPolicy(String id) {\r
81         this.id = id;\r
82     }\r
83     \r
84     public GuardPolicy(String name, MatchParameters matchParameters) {\r
85         this.name = name;\r
86         this.match_parameters = matchParameters;\r
87     }\r
88     \r
89     public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {\r
90         this(name, matchParameters);\r
91         this.id = id;\r
92         this.description = description;\r
93     }\r
94     \r
95     public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {\r
96         this(name, matchParameters);\r
97         if (limit_constraints != null) {\r
98             this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(limitConstraints);\r
99         }\r
100     }\r
101     \r
102     public GuardPolicy(String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {\r
103         this(name, matchParameters, limitConstraints);\r
104         this.description = description;\r
105     }\r
106     \r
107     public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {\r
108         this(name, description, matchParameters, limitConstraints);\r
109         this.id = id;\r
110     }\r
111     \r
112     public GuardPolicy(GuardPolicy policy) {\r
113         this.id = policy.id;\r
114         this.name = policy.name;\r
115         this.description = policy.description;\r
116         this.match_parameters = new MatchParameters(policy.match_parameters);\r
117         if (policy.limit_constraints != null) {\r
118             this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(policy.limit_constraints);\r
119         }\r
120     }\r
121     \r
122     public boolean isValid() {\r
123         return (id==null || name ==null)? false : true;\r
124     }\r
125     \r
126     @Override\r
127     public String toString() {\r
128         return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters=" \r
129                 +match_parameters + ", limitConstraints=" + limit_constraints + "]";\r
130     }\r
131 \r
132     @Override\r
133     public int hashCode() {\r
134         final int prime = 31;\r
135         int result = 1;\r
136         result = prime * result + ((description == null) ? 0 : description.hashCode());\r
137         result = prime * result + ((id == null) ? 0 : id.hashCode());\r
138         result = prime * result + ((name == null) ? 0 : name.hashCode());\r
139         result = prime * result + ((limit_constraints == null) ? 0 : limit_constraints.hashCode());\r
140         result = prime * result + ((match_parameters == null) ? 0 : match_parameters.hashCode());\r
141         return result;\r
142     }\r
143 \r
144     @Override\r
145     public boolean equals(Object obj) {\r
146         if (this == obj)\r
147             return true;\r
148         if (obj == null)\r
149             return false;\r
150         if (getClass() != obj.getClass())\r
151             return false;\r
152         GuardPolicy other = (GuardPolicy) obj;\r
153         if (description == null) {\r
154             if (other.description != null)\r
155                 return false;\r
156         } else if (!description.equals(other.description))\r
157             return false;\r
158         if (id == null) {\r
159             if (other.id != null)\r
160                 return false;\r
161         } else if (!id.equals(other.id))\r
162             return false;\r
163         if (name == null) {\r
164             if (other.name != null)\r
165                 return false;\r
166         } else if (!name.equals(other.name))\r
167             return false;\r
168         if (limit_constraints == null) {\r
169             if (other.limit_constraints != null)\r
170                 return false;\r
171         } else if (!limit_constraints.equals(other.limit_constraints))\r
172             return false;\r
173         if (match_parameters==null){\r
174             if(other.match_parameters !=null)\r
175                 return false;\r
176         } else if(!match_parameters.equals(other.match_parameters))\r
177             return false;\r
178         return true;\r
179     }\r
180     \r
181     \r
182 }\r