2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.onap.policy.controlloop.policy.guard;
\r
23 import java.util.LinkedList;
\r
24 import java.util.List;
\r
25 import java.util.UUID;
\r
27 public class GuardPolicy {
\r
29 private String id = UUID.randomUUID().toString();
\r
30 private String name;
\r
31 private String description;
\r
32 private MatchParameters matchParameters;
\r
33 private LinkedList<Constraint> limitConstraints;
\r
35 public GuardPolicy() {
\r
36 //Do Nothing Empty Constructor.
\r
39 public String getId() {
\r
43 public void setId(String id) {
\r
47 public String getName() {
\r
51 public void setName(String name) {
\r
55 public String getDescription() {
\r
59 public void setDescription(String description) {
\r
60 this.description = description;
\r
63 public MatchParameters getMatch_parameters() {
\r
64 return matchParameters;
\r
67 public void setMatch_parameters(MatchParameters matchParameters) {
\r
68 this.matchParameters = matchParameters;
\r
71 public LinkedList<Constraint> getLimit_constraints() {
\r
72 return limitConstraints;
\r
75 public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
\r
76 this.limitConstraints = limitConstraints;
\r
79 public GuardPolicy(String id) {
\r
83 public GuardPolicy(String name, MatchParameters matchParameters) {
\r
85 this.matchParameters = matchParameters;
\r
88 public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
\r
89 this(name, matchParameters);
\r
91 this.description = description;
\r
94 public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
\r
95 this(name, matchParameters);
\r
96 if (limitConstraints != null) {
\r
97 this.limitConstraints = (LinkedList<Constraint>) limitConstraints;
\r
101 public GuardPolicy(String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
\r
102 this(name, matchParameters, limitConstraints);
\r
103 this.description = description;
\r
106 public GuardPolicy(String id, String name, String description, MatchParameters matchParameters, List<Constraint> limitConstraints) {
\r
107 this(name, description, matchParameters, limitConstraints);
\r
111 public GuardPolicy(GuardPolicy policy) {
\r
112 this.id = policy.id;
\r
113 this.name = policy.name;
\r
114 this.description = policy.description;
\r
115 this.matchParameters = new MatchParameters(policy.matchParameters);
\r
116 if (policy.limitConstraints != null) {
\r
117 this.limitConstraints = policy.limitConstraints;
\r
121 public boolean isValid() {
\r
122 return (id==null || name ==null)? false : true;
\r
126 public String toString() {
\r
127 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
\r
128 +matchParameters + ", limitConstraints=" + limitConstraints + "]";
\r
132 public int hashCode() {
\r
133 final int prime = 31;
\r
135 result = prime * result + ((description == null) ? 0 : description.hashCode());
\r
136 result = prime * result + ((id == null) ? 0 : id.hashCode());
\r
137 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
138 result = prime * result + ((limitConstraints == null) ? 0 : limitConstraints.hashCode());
\r
139 result = prime * result + ((matchParameters == null) ? 0 : matchParameters.hashCode());
\r
144 public boolean equals(Object obj) {
\r
149 if (getClass() != obj.getClass())
\r
151 GuardPolicy other = (GuardPolicy) obj;
\r
152 return equalsMayBeNull(description, other.description)
\r
153 && equalsMayBeNull(id, other.id)
\r
154 && equalsMayBeNull(name, other.name)
\r
155 && equalsMayBeNull(limitConstraints, other.limitConstraints)
\r
156 && equalsMayBeNull(matchParameters, other.matchParameters);
\r
159 private boolean equalsMayBeNull(final Object obj1, final Object obj2){
\r
160 if ( obj1 == null ) {
\r
161 return obj2 == null;
\r
163 return obj1.equals(obj2);
\r