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;
26 import java.util.UUID;
28 public class GuardPolicy {
30 public String id = UUID.randomUUID().toString();
32 public String description;
33 public MatchParameters match_parameters;
34 public LinkedList<Constraint> limit_constraints;
37 public GuardPolicy() {
41 public GuardPolicy(String id) {
45 public GuardPolicy(String name, MatchParameters match_parameters) {
47 System.out.println("match_parameters: " + match_parameters);
48 this.match_parameters = new MatchParameters(match_parameters);
51 public GuardPolicy(String id, String name, String description, MatchParameters match_parameters) {
52 this(name, match_parameters);
54 this.description = description;
57 public GuardPolicy(String name, MatchParameters match_parameters, List<Constraint> limit_constraints) {
58 this(name, match_parameters);
59 if (limit_constraints != null) {
60 this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(limit_constraints);
64 public GuardPolicy(String name, String description, MatchParameters match_parameters, List<Constraint> limit_constraints) {
65 this(name, match_parameters, limit_constraints);
66 this.description = description;
69 public GuardPolicy(String id, String name, String description, MatchParameters match_parameters, List<Constraint> limit_constraints) {
70 this(name, description, match_parameters, limit_constraints);
79 public GuardPolicy(GuardPolicy policy) {
81 this.name = policy.name;
82 this.description = policy.description;
83 this.match_parameters = new MatchParameters(policy.match_parameters);
84 if (policy.limit_constraints != null) {
85 this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(policy.limit_constraints);
89 public boolean isValid() {
92 throw new NullPointerException();
95 throw new NullPointerException();
98 } catch (Exception e) {
105 public String toString() {
106 return "GuardPolicy [id=" + id + ", name=" + name + ", description=" + description + ", match_parameters="
107 + match_parameters + ", limit_constraints=" + limit_constraints + "]";
111 public int hashCode() {
112 final int prime = 31;
114 result = prime * result + ((description == null) ? 0 : description.hashCode());
115 result = prime * result + ((id == null) ? 0 : id.hashCode());
116 result = prime * result + ((limit_constraints == null) ? 0 : limit_constraints.hashCode());
117 result = prime * result + ((match_parameters == null) ? 0 : match_parameters.hashCode());
118 result = prime * result + ((name == null) ? 0 : name.hashCode());
123 public boolean equals(Object obj) {
128 if (getClass() != obj.getClass())
130 GuardPolicy other = (GuardPolicy) obj;
131 if (description == null) {
132 if (other.description != null)
134 } else if (!description.equals(other.description))
137 if (other.id != null)
139 } else if (!id.equals(other.id))
141 if (limit_constraints == null) {
142 if (other.limit_constraints != null)
144 } else if (!limit_constraints.equals(other.limit_constraints))
146 if (match_parameters == null) {
147 if (other.match_parameters != null)
149 } else if (!match_parameters.equals(other.match_parameters))
152 if (other.name != null)
154 } else if (!name.equals(other.name))