[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / ONAP-ControlloopPolicy / src / main / java / org / onap / policy / controlloop / policy / guard / Constraint.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.Map;
26
27 public class Constraint {
28
29         private Integer freq_limit_per_target;
30         private Map<String,String> time_window;
31         private Map<String, String> active_time_range;
32         
33         private List<String> blacklist;
34         
35         public Constraint() {
36                 // Do Nothing empty constructor. 
37         }
38
39         public Integer getFreq_limit_per_target() {
40                 return freq_limit_per_target;
41         }
42
43
44         public void setFreq_limit_per_target(Integer freq_limit_per_target) {
45                 this.freq_limit_per_target = freq_limit_per_target;
46         }
47
48
49         public Map<String, String> getTime_window() {
50                 return time_window;
51         }
52
53
54         public void setTime_window(Map<String, String> time_window) {
55                 this.time_window = time_window;
56         }
57
58
59         public Map<String, String> getActive_time_range() {
60                 return active_time_range;
61         }
62
63
64         public void setActive_time_range(Map<String, String> active_time_range) {
65                 this.active_time_range = active_time_range;
66         }
67
68
69         public List<String> getBlacklist() {
70                 return blacklist;
71         }
72
73         public void setBlacklist(List<String> blacklist) {
74                 this.blacklist = blacklist;
75         }
76
77         public Constraint(Integer freq_limit_per_target, Map<String, String> time_window) {
78                 this.freq_limit_per_target = freq_limit_per_target;
79                 if(time_window!=null){
80                         this.time_window = Collections.unmodifiableMap(time_window);
81                 }
82         }
83         
84         public Constraint(List<String> blacklist) {
85                 this.blacklist = new LinkedList<>(blacklist);
86         }
87         
88         public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, List<String> blacklist) {
89                 this.freq_limit_per_target = freq_limit_per_target;
90                 this.time_window = Collections.unmodifiableMap(time_window);
91                 this.blacklist = new LinkedList<>(blacklist);
92         }
93         
94         public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, Map<String, String> active_time_range) {
95                 this(freq_limit_per_target, time_window);
96                 if (active_time_range != null) {
97                         this.active_time_range = Collections.unmodifiableMap(active_time_range);
98                 }
99         }
100         
101         public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, Map<String, String> active_time_range, List<String> blacklist) {
102                 this(freq_limit_per_target, time_window);
103                 if (active_time_range != null) {
104                         this.active_time_range = Collections.unmodifiableMap(active_time_range);
105                 }
106                 if(blacklist!=null){
107                         this.blacklist = new LinkedList<>(blacklist);
108                 }
109         }
110         
111         public Constraint(Constraint constraint) {
112                 this.freq_limit_per_target = constraint.freq_limit_per_target;
113                 this.time_window = constraint.time_window;
114                 if (constraint.active_time_range != null) {
115                         this.active_time_range = Collections.unmodifiableMap(constraint.active_time_range);
116                 }
117                 this.blacklist = new LinkedList<>(constraint.blacklist);
118         }
119         
120         public boolean isValid() {
121                 return ((freq_limit_per_target == null && time_window != null)|| (time_window == null && freq_limit_per_target != null))? false : true;
122         }
123         
124         @Override
125         public String toString() {
126                 return "Constraint [freq_limit_per_target=" + freq_limit_per_target + ", time_window=" + time_window + ", active_time_range=" + active_time_range + ", blacklist=" + blacklist + "]";
127         }
128
129         @Override
130         public int hashCode() {
131                 final int prime = 31;
132                 int result = 1;
133                 result = prime * result + ((freq_limit_per_target == null) ? 0 : freq_limit_per_target.hashCode());
134                 result = prime * result + ((time_window == null) ? 0 : time_window.hashCode());
135                 result = prime * result + ((active_time_range == null) ? 0 : active_time_range.hashCode());
136                 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
137                 return result;
138         }
139
140         @Override
141         public boolean equals(Object obj) {
142                 if (this == obj)
143                         return true;
144                 if (obj == null)
145                         return false;
146                 if (getClass() != obj.getClass())
147                         return false;
148                 Constraint other = (Constraint) obj;
149                 if (freq_limit_per_target == null) {
150                         if (other.freq_limit_per_target != null) 
151                                 return false;
152                 } else if (!freq_limit_per_target.equals(other.freq_limit_per_target))
153                         return false;
154                 if (time_window == null) {
155                         if (other.time_window != null)
156                                 return false;
157                 } else if (!time_window.equals(other.time_window))
158                         return false;
159                 if (active_time_range == null) {
160                         if (other.active_time_range != null)
161                                 return false;
162                 } else if (!active_time_range.equals(other.active_time_range))
163                         return false;
164                 if (blacklist == null) {
165                         if (other.blacklist != null)
166                                 return false;
167                 } else if (!blacklist.equals(other.blacklist))
168                         return false;
169                 return true;
170         }
171 }