Fixes for sonar critical issues
[policy/engine.git] / ONAP-XACML / src / main / java / org / onap / policy / xacml / std / pap / StdPDPItemSetChangeNotifier.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-XACML
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.policy.xacml.std.pap;
21
22 import java.util.Collection;
23 import java.util.LinkedList;
24
25 import org.onap.policy.xacml.api.pap.OnapPDP;
26 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
27
28 public class StdPDPItemSetChangeNotifier {
29         
30         private Collection<StdItemSetChangeListener> listeners = null;
31         
32         public interface StdItemSetChangeListener {
33                 
34                 public void changed();
35                 
36                 public void groupChanged(OnapPDPGroup group);
37                 
38                 public void pdpChanged(OnapPDP pdp);
39
40         }
41         
42         public void addItemSetChangeListener(StdItemSetChangeListener listener) {
43                 if (this.listeners == null) {
44                         this.listeners = new LinkedList<>();
45                 }
46                 this.listeners.add(listener);
47         }
48         
49         public void removeItemSetChangeListener(StdItemSetChangeListener listener) {
50                 if (this.listeners != null) {
51                         this.listeners.remove(listener);
52                 }
53         }
54
55         public void fireChanged() {
56                 if (this.listeners == null) {
57                         return;
58                 }
59                 for (StdItemSetChangeListener l : this.listeners) {
60                         l.changed();
61                 }               
62         }
63
64         public void firePDPGroupChanged(OnapPDPGroup group) {
65                 if (this.listeners == null) {
66                         return;
67                 }
68                 for (StdItemSetChangeListener l : this.listeners) {
69                         l.groupChanged(group);
70                 }
71         }
72
73         public void firePDPChanged(OnapPDP pdp) {
74                 if (this.listeners == null) {
75                         return;
76                 }
77                 for (StdItemSetChangeListener l : this.listeners) {
78                         l.pdpChanged(pdp);
79                 }
80         }
81 }