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=========================================================
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 public Integer freq_limit_per_target;
31 public Map<String, String> time_window;
32 public Map<String, String> active_time_range;
34 public LinkedList<String> blacklist;
40 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window) {
41 this.freq_limit_per_target = freq_limit_per_target;
42 if (time_window != null) {
43 this.time_window = Collections.unmodifiableMap(time_window);
47 public Constraint(List<String> blacklist) {
48 this.blacklist = new LinkedList<String>(blacklist);
52 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, List<String> blacklist) {
53 this.freq_limit_per_target = freq_limit_per_target;
54 this.time_window = Collections.unmodifiableMap(time_window);
55 this.blacklist = new LinkedList<String>(blacklist);
58 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, Map<String, String> active_time_range, List<String> blacklist) {
59 this(freq_limit_per_target, time_window);
60 if (active_time_range != null) {
61 this.active_time_range = Collections.unmodifiableMap(active_time_range);
63 this.blacklist = new LinkedList<String>(blacklist);
66 public Constraint(Integer freq_limit_per_target, Map<String, String> time_window, Map<String, String> active_time_range) {
67 this(freq_limit_per_target, time_window);
68 if (active_time_range != null) {
69 this.active_time_range = Collections.unmodifiableMap(active_time_range);
73 public Constraint(Constraint constraint) {
74 this.freq_limit_per_target = constraint.freq_limit_per_target;
75 this.time_window = constraint.time_window;
76 if (constraint.active_time_range != null) {
77 this.active_time_range = Collections.unmodifiableMap(constraint.active_time_range);
79 this.blacklist = new LinkedList<String>(constraint.blacklist);
82 public boolean isValid() {
83 //System.out.println("freq_limit_per_target: " + freq_limit_per_target + " time_window" + time_window );
85 if (freq_limit_per_target == null && time_window != null) {
86 throw new NullPointerException();
88 if (time_window == null && freq_limit_per_target != null) {
89 throw new NullPointerException();
91 } catch (Exception e) {
98 public String toString() {
99 return "Constraint [freq_limit_per_target=" + freq_limit_per_target + ", time_window=" + time_window + ", active_time_range=" + active_time_range + ", blacklist=" + blacklist + "]";
103 public int hashCode() {
104 final int prime = 31;
106 result = prime * result + ((freq_limit_per_target == null) ? 0 : freq_limit_per_target.hashCode());
107 result = prime * result + ((time_window == null) ? 0 : time_window.hashCode());
108 result = prime * result + ((active_time_range == null) ? 0 : active_time_range.hashCode());
109 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
114 public boolean equals(Object obj) {
119 if (getClass() != obj.getClass())
121 Constraint other = (Constraint) obj;
122 if (freq_limit_per_target == null) {
123 if (other.freq_limit_per_target != null)
125 } else if (!freq_limit_per_target.equals(other.freq_limit_per_target))
127 if (time_window == null) {
128 if (other.time_window != null)
130 } else if (!time_window.equals(other.time_window))
132 if (active_time_range == null) {
133 if (other.active_time_range != null)
135 } else if (!active_time_range.equals(other.active_time_range))
137 if (blacklist == null) {
138 if (other.blacklist != null)
140 } else if (!blacklist.equals(other.blacklist))