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.LinkedList;
24 import java.util.List;
25 import java.util.UUID;
27 public class GuardPolicy {
29 private String id = UUID.randomUUID().toString();
31 private String description;
32 private MatchParameters matchParameters;
33 private LinkedList<Constraint> limitConstraints;
35 public GuardPolicy() {
36 //Do Nothing Empty Constructor.
39 public String getId() {
43 public void setId(String id) {
47 public String getName() {
51 public void setName(String name) {
55 public String getDescription() {
59 public void setDescription(String description) {
60 this.description = description;
63 public MatchParameters getMatch_parameters() {
64 return matchParameters;
67 public void setMatch_parameters(MatchParameters matchParameters) {
68 this.matchParameters = matchParameters;
71 public LinkedList<Constraint> getLimit_constraints() {
72 return limitConstraints;
75 public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
76 this.limitConstraints = limitConstraints;
79 public GuardPolicy(String id) {
83 public GuardPolicy(String name, MatchParameters matchParameters) {
85 this.matchParameters = matchParameters;
88 public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
89 this(name, matchParameters);
91 this.description = description;
94 public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
95 this(name, matchParameters);
96 if (limitConstraints != null) {
97 this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
101 public GuardPolicy(String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
102 this(name, matchParameters, limitConstraints);
103 this.description = description;
106 public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
107 this(name, description, matchParameters, limitConstraints);
111 public GuardPolicy(GuardPolicy policy) {
113 this.name = policy.name;
114 this.description = policy.description;
115 this.matchParameters = new MatchParameters(policy.matchParameters);
116 if (policy.limitConstraints != null) {
117 this.limitConstraints = policy.limitConstraints;
121 public boolean isValid() {
122 return (id==null || name ==null)? false : true;
126 public String toString() {
127 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
128 +matchParameters + ", limitConstraints=" + limitConstraints + "]";
132 public int hashCode() {
133 final int prime = 31;
135 result = prime * result + ((description == null) ? 0 : description.hashCode());
136 result = prime * result + ((id == null) ? 0 : id.hashCode());
137 result = prime * result + ((name == null) ? 0 : name.hashCode());
138 result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
139 result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
144 public boolean equals(Object obj) {
149 if (getClass() != obj.getClass())
151 GuardPolicy other = (GuardPolicy) obj;
152 return equalsMayBeNull(description, other.description)
153 && equalsMayBeNull(id, other.id)
154 && equalsMayBeNull(name, other.name)
155 && equalsMayBeNull(limitConstraints, other.limitConstraints)
156 && equalsMayBeNull(matchParameters, other.matchParameters);
159 private boolean equalsMayBeNull(final Object obj1, final Object obj2){
160 if ( obj1 == null ) {
163 return obj1.equals(obj2);