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