2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.policy.guard;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.UUID;
28 public class GuardPolicy {
30 private String id = UUID.randomUUID().toString();
32 private String description;
33 private MatchParameters matchParameters;
34 private LinkedList<Constraint> limitConstraints;
36 public GuardPolicy() {
37 //Do Nothing Empty Constructor.
40 public GuardPolicy(String id) {
44 public GuardPolicy(String name, MatchParameters matchParameters) {
46 this.matchParameters = matchParameters;
54 * @param description description
55 * @param matchParameters match parameters
57 public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
58 this(name, matchParameters);
60 this.description = description;
67 * @param matchParameters match parameters
68 * @param limitConstraints limit constraints
70 public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
71 this(name, matchParameters);
72 if (limitConstraints != null) {
73 this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
77 public GuardPolicy(String name, String description, MatchParameters matchParameters,
78 List<Constraint> limitConstraints) {
79 this(name, matchParameters, limitConstraints);
80 this.description = description;
83 public GuardPolicy(String id, String name, String description, MatchParameters matchParameters,
84 List<Constraint> limitConstraints) {
85 this(name, description, matchParameters, limitConstraints);
92 * @param policy copy object
94 public GuardPolicy(GuardPolicy policy) {
96 this.name = policy.name;
97 this.description = policy.description;
98 this.matchParameters = new MatchParameters(policy.matchParameters);
99 if (policy.limitConstraints != null) {
100 this.limitConstraints = policy.limitConstraints;
104 public String getId() {
108 public void setId(String id) {
112 public String getName() {
116 public void setName(String name) {
120 public String getDescription() {
124 public void setDescription(String description) {
125 this.description = description;
128 public MatchParameters getMatch_parameters() {
129 return matchParameters;
132 public void setMatch_parameters(MatchParameters matchParameters) {
133 this.matchParameters = matchParameters;
136 public LinkedList<Constraint> getLimit_constraints() {
137 return limitConstraints;
140 public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
141 this.limitConstraints = limitConstraints;
144 public boolean isValid() {
145 return (id == null || name == null) ? false : true;
149 public String toString() {
150 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
151 + matchParameters + ", limitConstraints=" + limitConstraints + "]";
155 public int hashCode() {
156 final int prime = 31;
158 result = prime * result + ((description == null) ? 0 : description.hashCode());
159 result = prime * result + ((id == null) ? 0 : id.hashCode());
160 result = prime * result + ((name == null) ? 0 : name.hashCode());
161 result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
162 result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
167 public boolean equals(Object obj) {
174 if (getClass() != obj.getClass()) {
177 GuardPolicy other = (GuardPolicy) obj;
178 return equalsMayBeNull(description, other.description)
179 && equalsMayBeNull(id, other.id)
180 && equalsMayBeNull(name, other.name)
181 && equalsMayBeNull(limitConstraints, other.limitConstraints)
182 && equalsMayBeNull(matchParameters, other.matchParameters);
185 private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
186 if ( obj1 == null ) {
189 return obj1.equals(obj2);