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(Map<String, String> time_in_range, List<String> blacklist) {
82 if (time_in_range != null) {
83 this.time_in_range = Collections.unmodifiableMap(time_in_range);
85 this.blacklist = new LinkedList<>(blacklist);
88 public Constraint(Integer num, String duration, List<String> blacklist) {
90 this.duration = duration;
91 this.blacklist = new LinkedList<>(blacklist);
94 public Constraint(Integer num, String duration, Map<String, String> time_in_range) {
96 if (time_in_range != null) {
97 this.time_in_range = Collections.unmodifiableMap(time_in_range);
101 public Constraint(Integer num, String duration, Map<String, String> time_in_range, List<String> blacklist) {
103 if (time_in_range != null) {
104 this.time_in_range = Collections.unmodifiableMap(time_in_range);
106 this.blacklist = new LinkedList<>(blacklist);
109 public Constraint(Constraint constraint) {
110 this.num = constraint.num;
111 this.duration = constraint.duration;
112 if (constraint.time_in_range != null) {
113 this.time_in_range = Collections.unmodifiableMap(constraint.time_in_range);
115 this.blacklist = new LinkedList<>(constraint.blacklist);
118 public boolean isValid() {
119 return ((num == null && duration != null)|| (duration == null && num != null))? false : true;
123 public String toString() {
124 return "Constraint [num=" + num + ", duration=" + duration + ", time_in_range=" + time_in_range + ", blacklist=" + blacklist + "]";
128 public int hashCode() {
129 final int prime = 31;
131 result = prime * result + ((num == null) ? 0 : num.hashCode());
132 result = prime * result + ((duration == null) ? 0 : duration.hashCode());
133 result = prime * result + ((time_in_range == null) ? 0 : time_in_range.hashCode());
134 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
139 public boolean equals(Object obj) {
144 if (getClass() != obj.getClass())
146 Constraint other = (Constraint) obj;
148 if (other.num != null)
150 } else if (!num.equals(other.num))
152 if (duration == null) {
153 if (other.duration != null)
155 } else if (!duration.equals(other.duration))
157 if (time_in_range == null) {
158 if (other.time_in_range != null)
160 } else if (!time_in_range.equals(other.time_in_range))
162 if (blacklist == null) {
163 if (other.blacklist != null)
165 } else if (!blacklist.equals(other.blacklist))