2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.controlloop.policy.guard;
22 import java.util.Collections;
23 import java.util.LinkedList;
24 import java.util.List;
27 public class Constraint {
29 private Integer freq_limit_per_target;
30 private Map<String,String> time_window;
31 private Map<String, String> active_time_range;
33 private List<String> blacklist;
36 // Do Nothing empty constructor.
39 public Integer getFreq_limit_per_target() {
40 return freq_limit_per_target;
44 public void setFreq_limit_per_target(Integer freq_limit_per_target) {
45 this.freq_limit_per_target = freq_limit_per_target;
49 public Map<String, String> getTime_window() {
54 public void setTime_window(Map<String, String> time_window) {
55 this.time_window = time_window;
59 public Map<String, String> getActive_time_range() {
60 return active_time_range;
64 public void setActive_time_range(Map<String, String> active_time_range) {
65 this.active_time_range = active_time_range;
69 public List<String> getBlacklist() {
73 public void setBlacklist(List<String> blacklist) {
74 this.blacklist = blacklist;
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);
84 public Constraint(List<String> blacklist) {
85 this.blacklist = new LinkedList<>(blacklist);
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);
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);
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);
107 this.blacklist = new LinkedList<>(blacklist);
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);
117 this.blacklist = new LinkedList<>(constraint.blacklist);
120 public boolean isValid() {
121 return ((freq_limit_per_target == null && time_window != null)|| (time_window == null && freq_limit_per_target != null))? false : true;
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 + "]";
130 public int hashCode() {
131 final int prime = 31;
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());
141 public boolean equals(Object obj) {
146 if (getClass() != obj.getClass())
148 Constraint other = (Constraint) obj;
149 if (freq_limit_per_target == null) {
150 if (other.freq_limit_per_target != null)
152 } else if (!freq_limit_per_target.equals(other.freq_limit_per_target))
154 if (time_window == null) {
155 if (other.time_window != null)
157 } else if (!time_window.equals(other.time_window))
159 if (active_time_range == null) {
160 if (other.active_time_range != null)
162 } else if (!active_time_range.equals(other.active_time_range))
164 if (blacklist == null) {
165 if (other.blacklist != null)
167 } else if (!blacklist.equals(other.blacklist))