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 {
31 //public String duration;
32 public Map<String, String> duration;
33 public Map<String, String> time_in_range;
35 public LinkedList<String> blacklist;
41 public Constraint(Integer num, Map<String, String> duration) {
43 this.duration = duration;
46 public Constraint(List<String> blacklist) {
47 this.blacklist = new LinkedList<String>(blacklist);
51 public Constraint(Integer num, Map<String, String> duration, List<String> blacklist) {
53 this.duration = Collections.unmodifiableMap(duration);
54 this.blacklist = new LinkedList<String>(blacklist);
57 public Constraint(Integer num, Map<String, String> duration, Map<String, String> time_in_range, List<String> blacklist) {
58 //this(num, duration);
59 if (duration != null) {
60 this.duration = Collections.unmodifiableMap(duration);
62 if (time_in_range != null) {
63 this.time_in_range = Collections.unmodifiableMap(time_in_range);
65 this.blacklist = new LinkedList<String>(blacklist);
68 public Constraint(Constraint constraint) {
69 this.num = constraint.num;
70 this.duration = constraint.duration;
71 if (constraint.time_in_range != null) {
72 this.time_in_range = Collections.unmodifiableMap(constraint.time_in_range);
74 this.blacklist = new LinkedList<String>(constraint.blacklist);
77 public boolean isValid() {
79 if (num == null && duration != null) {
80 throw new NullPointerException();
82 if (duration == null && num != null) {
83 throw new NullPointerException();
85 } catch (Exception e) {
92 public String toString() {
93 return "Constraint [num=" + num + ", duration=" + duration + ", time_in_range=" + time_in_range + ", blacklist=" + blacklist + "]";
97 public int hashCode() {
100 result = prime * result + ((num == null) ? 0 : num.hashCode());
101 result = prime * result + ((duration == null) ? 0 : duration.hashCode());
102 result = prime * result + ((time_in_range == null) ? 0 : time_in_range.hashCode());
103 result = prime * result + ((blacklist == null) ? 0 : blacklist.hashCode());
108 public boolean equals(Object obj) {
113 if (getClass() != obj.getClass())
115 Constraint other = (Constraint) obj;
117 if (other.num != null)
119 } else if (!num.equals(other.num))
121 if (duration == null) {
122 if (other.duration != null)
124 } else if (!duration.equals(other.duration))
126 if (time_in_range == null) {
127 if (other.time_in_range != null)
129 } else if (!time_in_range.equals(other.time_in_range))
131 if (blacklist == null) {
132 if (other.blacklist != null)
134 } else if (!blacklist.equals(other.blacklist))