2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.policy.controlloop.policy.guard;
23 import java.util.Collections;
24 import java.util.LinkedList;
25 import java.util.List;
28 public class Constraint {
30 private Integer freqLimitPerTarget;
31 private Map<String,String> timeWindow;
32 private Map<String, String> activeTimeRange;
34 private List<String> blacklist;
37 // Do Nothing empty constructor.
40 public Integer getFreq_limit_per_target() {
41 return freqLimitPerTarget;
45 public void setFreq_limit_per_target(Integer freqLimitPerTarget) {
46 this.freqLimitPerTarget = freqLimitPerTarget;
50 public Map<String, String> getTime_window() {
55 public void setTime_window(Map<String, String> timeWindow) {
56 this.timeWindow = timeWindow;
60 public Map<String, String> getActive_time_range() {
61 return activeTimeRange;
65 public void setActive_time_range(Map<String, String> activeTimeRange) {
66 this.activeTimeRange = activeTimeRange;
70 public List<String> getBlacklist() {
74 public void setBlacklist(List<String> blacklist) {
75 this.blacklist = blacklist;
81 * @param freqLimitPerTarget frequency limit
82 * @param timeWindow time window
84 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow) {
85 this.freqLimitPerTarget = freqLimitPerTarget;
86 if (timeWindow != null) {
87 this.timeWindow = Collections.unmodifiableMap(timeWindow);
91 public Constraint(List<String> blacklist) {
92 this.blacklist = new LinkedList<>(blacklist);
98 * @param freqLimitPerTarget frequency limit
99 * @param timeWindow time window
100 * @param blacklist blacklist
102 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, List<String> blacklist) {
103 this.freqLimitPerTarget = freqLimitPerTarget;
104 this.timeWindow = Collections.unmodifiableMap(timeWindow);
105 this.blacklist = new LinkedList<>(blacklist);
111 * @param freqLimitPerTarget frequency limit
112 * @param timeWindow time window
113 * @param activeTimeRange active time range
115 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange) {
116 this(freqLimitPerTarget, timeWindow);
117 if (activeTimeRange != null) {
118 this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
125 * @param freqLimitPerTarget frequency limit
126 * @param timeWindow the time window
127 * @param activeTimeRange active time range
128 * @param blacklist incoming blacklist
130 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange,
131 List<String> blacklist) {
132 this(freqLimitPerTarget, timeWindow);
133 if (activeTimeRange != null) {
134 this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
136 if (blacklist != null) {
137 this.blacklist = new LinkedList<>(blacklist);
144 * @param constraint objec to copy
146 public Constraint(Constraint constraint) {
147 this.freqLimitPerTarget = constraint.freqLimitPerTarget;
148 this.timeWindow = constraint.timeWindow;
149 if (constraint.activeTimeRange != null) {
150 this.activeTimeRange = Collections.unmodifiableMap(constraint.activeTimeRange);
152 this.blacklist = new LinkedList<>(constraint.blacklist);
155 public boolean isValid() {
156 return ((freqLimitPerTarget == null && timeWindow != null)
157 || (timeWindow == null && freqLimitPerTarget != null)) ? false : true;
161 public String toString() {
162 return "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window="
163 + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]";
167 public int hashCode() {
168 final int prime = 31;
170 result = prime * result + ((freqLimitPerTarget == null) ? 0 : freqLimitPerTarget.hashCode());
171 result = prime * result + ((timeWindow == null) ? 0 : timeWindow.hashCode());
172 result = prime * result + ((activeTimeRange == null) ? 0 : activeTimeRange.hashCode());
173 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
178 public boolean equals(Object obj) {
185 if (getClass() != obj.getClass()) {
188 Constraint other = (Constraint) obj;
189 return equalsMayBeNull(freqLimitPerTarget, other.freqLimitPerTarget)
190 && equalsMayBeNull(timeWindow, other.timeWindow)
191 && equalsMayBeNull(activeTimeRange, other.activeTimeRange)
192 && equalsMayBeNull(blacklist, other.blacklist);
195 private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
199 return obj1.equals(obj2);