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 freqLimitPerTarget;
\r
31 private Map<String,String> timeWindow;
\r
32 private Map<String, String> activeTimeRange;
\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 freqLimitPerTarget;
\r
45 public void setFreq_limit_per_target(Integer freqLimitPerTarget) {
\r
46 this.freqLimitPerTarget = freqLimitPerTarget;
\r
50 public Map<String, String> getTime_window() {
\r
55 public void setTime_window(Map<String, String> timeWindow) {
\r
56 this.timeWindow = timeWindow;
\r
60 public Map<String, String> getActive_time_range() {
\r
61 return activeTimeRange;
\r
65 public void setActive_time_range(Map<String, String> activeTimeRange) {
\r
66 this.activeTimeRange = activeTimeRange;
\r
70 public List<String> getBlacklist() {
\r
74 public void setBlacklist(List<String> blacklist) {
\r
75 this.blacklist = blacklist;
\r
78 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow) {
\r
79 this.freqLimitPerTarget = freqLimitPerTarget;
\r
80 if(timeWindow!=null){
\r
81 this.timeWindow = Collections.unmodifiableMap(timeWindow);
\r
85 public Constraint(List<String> blacklist) {
\r
86 this.blacklist = new LinkedList<>(blacklist);
\r
89 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, List<String> blacklist) {
\r
90 this.freqLimitPerTarget = freqLimitPerTarget;
\r
91 this.timeWindow = Collections.unmodifiableMap(timeWindow);
\r
92 this.blacklist = new LinkedList<>(blacklist);
\r
95 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange) {
\r
96 this(freqLimitPerTarget, timeWindow);
\r
97 if (activeTimeRange != null) {
\r
98 this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
\r
102 public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange, List<String> blacklist) {
\r
103 this(freqLimitPerTarget, timeWindow);
\r
104 if (activeTimeRange != null) {
\r
105 this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
\r
107 if(blacklist!=null){
\r
108 this.blacklist = new LinkedList<>(blacklist);
\r
112 public Constraint(Constraint constraint) {
\r
113 this.freqLimitPerTarget = constraint.freqLimitPerTarget;
\r
114 this.timeWindow = constraint.timeWindow;
\r
115 if (constraint.activeTimeRange != null) {
\r
116 this.activeTimeRange = Collections.unmodifiableMap(constraint.activeTimeRange);
\r
118 this.blacklist = new LinkedList<>(constraint.blacklist);
\r
121 public boolean isValid() {
\r
122 return ((freqLimitPerTarget == null && timeWindow != null)|| (timeWindow == null && freqLimitPerTarget != null))? false : true;
\r
126 public String toString() {
\r
127 return "Constraint [freq_limit_per_target=" + freqLimitPerTarget + ", time_window=" + timeWindow + ", active_time_range=" + activeTimeRange + ", blacklist=" + blacklist + "]";
\r
131 public int hashCode() {
\r
132 final int prime = 31;
\r
134 result = prime * result + ((freqLimitPerTarget == null) ? 0 : freqLimitPerTarget.hashCode());
\r
135 result = prime * result + ((timeWindow == null) ? 0 : timeWindow.hashCode());
\r
136 result = prime * result + ((activeTimeRange == null) ? 0 : activeTimeRange.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 return equalsMayBeNull(freqLimitPerTarget, other.freqLimitPerTarget)
\r
151 && equalsMayBeNull(timeWindow, other.timeWindow)
\r
152 && equalsMayBeNull(activeTimeRange, other.activeTimeRange)
\r
153 && equalsMayBeNull(blacklist, other.blacklist);
\r
156 private boolean equalsMayBeNull(final Object obj1, final Object obj2){
\r
157 if ( obj1 == null ) {
\r
158 return obj2 == null;
\r
160 return obj1.equals(obj2);
\r