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 public String duration;
31 public Map<String, String> time_in_range;
33 public LinkedList<String> blacklist;
39 public Constraint(Integer num, String duration) {
41 this.duration = duration;
44 public Constraint(List<String> blacklist) {
45 this.blacklist = new LinkedList<String>(blacklist);
49 public Constraint(Integer num, String duration, Map<String, String> time_in_range) {
51 if (time_in_range != null) {
52 this.time_in_range = Collections.unmodifiableMap(time_in_range);
56 public Constraint(Integer num, String duration, List<String> blacklist) {
58 this.duration = duration;
59 this.blacklist = new LinkedList<String>(blacklist);
62 public Constraint(Integer num, String duration, Map<String, String> time_in_range, List<String> blacklist) {
64 if (time_in_range != null) {
65 this.time_in_range = Collections.unmodifiableMap(time_in_range);
67 this.blacklist = new LinkedList<String>(blacklist);
70 public Constraint(Constraint constraint) {
71 this.num = constraint.num;
72 this.duration = constraint.duration;
73 if (constraint.time_in_range != null) {
74 this.time_in_range = Collections.unmodifiableMap(constraint.time_in_range);
76 this.blacklist = new LinkedList<String>(constraint.blacklist);
79 public boolean isValid() {
81 if (num == null && duration != null) {
82 throw new NullPointerException();
84 if (duration == null && num != null) {
85 throw new NullPointerException();
87 } catch (Exception e) {
94 public String toString() {
95 return "Constraint [num=" + num + ", duration=" + duration + ", time_in_range=" + time_in_range + ", blacklist=" + blacklist + "]";
99 public int hashCode() {
100 final int prime = 31;
102 result = prime * result + ((num == null) ? 0 : num.hashCode());
103 result = prime * result + ((duration == null) ? 0 : duration.hashCode());
104 result = prime * result + ((time_in_range == null) ? 0 : time_in_range.hashCode());
105 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
110 public boolean equals(Object obj) {
115 if (getClass() != obj.getClass())
117 Constraint other = (Constraint) obj;
119 if (other.num != null)
121 } else if (!num.equals(other.num))
123 if (duration == null) {
124 if (other.duration != null)
126 } else if (!duration.equals(other.duration))
128 if (time_in_range == null) {
129 if (other.time_in_range != null)
131 } else if (!time_in_range.equals(other.time_in_range))
133 if (blacklist == null) {
134 if (other.blacklist != null)
136 } else if (!blacklist.equals(other.blacklist))