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.openecomp.policy.controlloop.policy.guard;
22 import java.util.Collections;
23 import java.util.LinkedList;
24 import java.util.List;
27 public class Constraint {
30 private String duration;
31 private Map<String, String> time_in_range;
33 private List<String> blacklist;
36 // Do Nothing empty constructor.
39 public Integer getNum() {
43 public void setNum(Integer num) {
47 public String getDuration() {
51 public void setDuration(String duration) {
52 this.duration = duration;
55 public Map<String, String> getTime_in_range() {
59 public void setTime_in_range(Map<String, String> time_in_range) {
60 this.time_in_range = time_in_range;
63 public List<String> getBlacklist() {
67 public void setBlacklist(List<String> blacklist) {
68 this.blacklist = blacklist;
71 public Constraint(Integer num, String duration) {
73 this.duration = duration;
76 public Constraint(List<String> blacklist) {
77 this.blacklist = new LinkedList<>(blacklist);
81 public Constraint(Integer num, String duration, List<String> blacklist) {
83 this.duration = duration;
84 this.blacklist = new LinkedList<>(blacklist);
87 public Constraint(Integer num, String duration, Map<String, String> time_in_range, List<String> blacklist) {
89 if (time_in_range != null) {
90 this.time_in_range = Collections.unmodifiableMap(time_in_range);
92 this.blacklist = new LinkedList<>(blacklist);
95 public Constraint(Constraint constraint) {
96 this.num = constraint.num;
97 this.duration = constraint.duration;
98 if (constraint.time_in_range != null) {
99 this.time_in_range = Collections.unmodifiableMap(constraint.time_in_range);
101 this.blacklist = new LinkedList<>(constraint.blacklist);
104 public boolean isValid() {
105 if (num == null && duration != null) {
108 if (duration == null && num != null) {
115 public String toString() {
116 return "Constraint [num=" + num + ", duration=" + duration + ", time_in_range=" + time_in_range + ", blacklist=" + blacklist + "]";
120 public int hashCode() {
121 final int prime = 31;
123 result = prime * result + ((num == null) ? 0 : num.hashCode());
124 result = prime * result + ((duration == null) ? 0 : duration.hashCode());
125 result = prime * result + ((time_in_range == null) ? 0 : time_in_range.hashCode());
126 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
131 public boolean equals(Object obj) {
136 if (getClass() != obj.getClass())
138 Constraint other = (Constraint) obj;
140 if (other.num != null)
142 } else if (!num.equals(other.num))
144 if (duration == null) {
145 if (other.duration != null)
147 } else if (!duration.equals(other.duration))
149 if (time_in_range == null) {
150 if (other.time_in_range != null)
152 } else if (!time_in_range.equals(other.time_in_range))
154 if (blacklist == null) {
155 if (other.blacklist != null)
157 } else if (!blacklist.equals(other.blacklist))