2 * ============LICENSE_START=======================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.onap.policy.controlloop.policy.guard;
\r
23 import java.util.Collections;
\r
24 import java.util.LinkedList;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
28 public class Constraint {
\r
30 private Integer freq_limit_per_target;
\r
31 private Map<String,String> time_window;
\r
32 private Map<String, String> active_time_range;
\r
34 private List<String> blacklist;
\r
36 public Constraint() {
\r
37 // Do Nothing empty constructor.
\r
40 public Integer getFreq_limit_per_target() {
\r
41 return freq_limit_per_target;
\r
45 public void setFreq_limit_per_target(Integer freq_limit_per_target) {
\r
46 this.freq_limit_per_target = freq_limit_per_target;
\r
50 public Map<String, String> getTime_window() {
\r
55 public void setTime_window(Map<String, String> time_window) {
\r
56 this.time_window = time_window;
\r
60 public Map<String, String> getActive_time_range() {
\r
61 return active_time_range;
\r
65 public void setActive_time_range(Map<String, String> active_time_range) {
\r
66 this.active_time_range = active_time_range;
\r
70 public List<String> getBlacklist() {
\r
74 public void setBlacklist(List<String> blacklist) {
\r
75 this.blacklist = blacklist;
\r
78 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window) {
\r
79 this.freq_limit_per_target = freq_limit_per_target;
\r
80 if(time_window!=null){
\r
81 this.time_window = Collections.unmodifiableMap(time_window);
\r
85 public Constraint(List<String> blacklist) {
\r
86 this.blacklist = new LinkedList<>(blacklist);
\r
89 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, List<String> blacklist) {
\r
90 this.freq_limit_per_target = freq_limit_per_target;
\r
91 this.time_window = Collections.unmodifiableMap(time_window);
\r
92 this.blacklist = new LinkedList<>(blacklist);
\r
95 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, Map<String, String> active_time_range) {
\r
96 this(freq_limit_per_target, time_window);
\r
97 if (active_time_range != null) {
\r
98 this.active_time_range = Collections.unmodifiableMap(active_time_range);
\r
102 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, Map<String, String> active_time_range, List<String> blacklist) {
\r
103 this(freq_limit_per_target, time_window);
\r
104 if (active_time_range != null) {
\r
105 this.active_time_range = Collections.unmodifiableMap(active_time_range);
\r
107 if(blacklist!=null){
\r
108 this.blacklist = new LinkedList<>(blacklist);
\r
112 public Constraint(Constraint constraint) {
\r
113 this.freq_limit_per_target = constraint.freq_limit_per_target;
\r
114 this.time_window = constraint.time_window;
\r
115 if (constraint.active_time_range != null) {
\r
116 this.active_time_range = Collections.unmodifiableMap(constraint.active_time_range);
\r
118 this.blacklist = new LinkedList<>(constraint.blacklist);
\r
121 public boolean isValid() {
\r
122 return ((freq_limit_per_target == null && time_window != null)|| (time_window == null && freq_limit_per_target != null))? false : true;
\r
126 public String toString() {
\r
127 return "Constraint [freq_limit_per_target=" + freq_limit_per_target + ", time_window=" + time_window + ", active_time_range=" + active_time_range + ", blacklist=" + blacklist + "]";
\r
131 public int hashCode() {
\r
132 final int prime = 31;
\r
134 result = prime * result + ((freq_limit_per_target == null) ? 0 : freq_limit_per_target.hashCode());
\r
135 result = prime * result + ((time_window == null) ? 0 : time_window.hashCode());
\r
136 result = prime * result + ((active_time_range == null) ? 0 : active_time_range.hashCode());
\r
137 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
\r
142 public boolean equals(Object obj) {
\r
147 if (getClass() != obj.getClass())
\r
149 Constraint other = (Constraint) obj;
\r
150 if (freq_limit_per_target == null) {
\r
151 if (other.freq_limit_per_target != null)
\r
153 } else if (!freq_limit_per_target.equals(other.freq_limit_per_target))
\r
155 if (time_window == null) {
\r
156 if (other.time_window != null)
\r
158 } else if (!time_window.equals(other.time_window))
\r
160 if (active_time_range == null) {
\r
161 if (other.active_time_range != null)
\r
163 } else if (!active_time_range.equals(other.active_time_range))
\r
165 if (blacklist == null) {
\r
166 if (other.blacklist != null)
\r
168 } else if (!blacklist.equals(other.blacklist))
\r