759a0533de4de14aa53729458e61848f01d8987c
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
4  * ================================================================================
5  * Copyright (C) 2017-2018 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.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 matchParameters;
33     private LinkedList<Constraint> limitConstraints;
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 matchParameters;
65     }
66
67     public void setMatch_parameters(MatchParameters matchParameters) {
68         this.matchParameters = matchParameters;
69     }
70
71     public LinkedList<Constraint> getLimit_constraints() {
72         return  limitConstraints;
73     }
74
75     public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
76         this.limitConstraints = limitConstraints;
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.matchParameters = 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 (limitConstraints != null) {
97             this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
98         }
99     }
100     
101     public GuardPolicy(String name, String description, MatchParameters matchParameters, 
102                     List<Constraint> limitConstraints) {
103         this(name, matchParameters, limitConstraints);
104         this.description = description;
105     }
106     
107     public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, 
108                     List<Constraint> limitConstraints) {
109         this(name, description, matchParameters, limitConstraints);
110         this.id = id;
111     }
112     
113     public GuardPolicy(GuardPolicy policy) {
114         this.id = policy.id;
115         this.name = policy.name;
116         this.description = policy.description;
117         this.matchParameters = new MatchParameters(policy.matchParameters);
118         if (policy.limitConstraints != null) {
119             this.limitConstraints = policy.limitConstraints;
120         }
121     }
122     
123     public boolean isValid() {
124         return (id == null || name == null) ? false : true;
125     }
126     
127     @Override
128     public String toString() {
129         return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters=" 
130                 + matchParameters + ", limitConstraints=" + limitConstraints + "]";
131     }
132
133     @Override
134     public int hashCode() {
135         final int prime = 31;
136         int result = 1;
137         result = prime * result + ((description == null) ? 0 : description.hashCode());
138         result = prime * result + ((id == null) ? 0 : id.hashCode());
139         result = prime * result + ((name == null) ? 0 : name.hashCode());
140         result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
141         result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
142         return result;
143     }
144
145     @Override
146     public boolean equals(Object obj) {
147         if (this == obj) {
148             return true;
149         }
150         if (obj == null) {
151             return false;
152         }
153         if (getClass() != obj.getClass()) {
154             return false;
155         }
156         GuardPolicy other = (GuardPolicy) obj;
157         return equalsMayBeNull(description, other.description)
158                 && equalsMayBeNull(id, other.id)
159                 && equalsMayBeNull(name, other.name)
160                 && equalsMayBeNull(limitConstraints, other.limitConstraints)
161                 && equalsMayBeNull(matchParameters, other.matchParameters);
162     }
163     
164     private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
165         if ( obj1 == null ) {
166             return obj2 == null;
167         }
168         return obj1.equals(obj2);
169     }        
170 }