b0cff91d000b96b81fea6a740588a10de38e0592
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (c) 2021 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.examples.adaptive.concepts;
23
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.LinkedList;
27 import java.util.List;
28 import lombok.EqualsAndHashCode;
29
30 /**
31  * The Class AnomalyDetection is used as a Java context for Adaptive anomaly detection in the adaptive domain.
32  */
33 @EqualsAndHashCode
34 public class AnomalyDetection implements Serializable {
35     private static final long serialVersionUID = -823013127095523727L;
36
37     private boolean firstRound = true;
38     private int frequency = 0;
39
40     private List<Double> anomalyScores = new LinkedList<>();
41     private List<Double> frequencyForecasted;
42
43     /**
44      * The Constructor creates an AnomalyDetection instance.
45      */
46     public AnomalyDetection() {
47         firstRound = true;
48         frequency = 0;
49     }
50
51     /**
52      * Checks if the AnomalyDetection instance is initialized.
53      *
54      * @return true, if the AnomalyDetection instance is initialized
55      */
56     public boolean isInitialized() {
57         return (frequencyForecasted != null);
58     }
59
60     /**
61      * Initializes the AnomalyDetection instance.
62      *
63      * @param incomingFrequency the frequency
64      */
65     public void init(final int incomingFrequency) {
66         frequencyForecasted = new ArrayList<>(incomingFrequency);
67         for (var i = 0; i < incomingFrequency; i++) {
68             frequencyForecasted.add(null);
69         }
70     }
71
72     /**
73      * Indicates if this is the first round of the algorithm.
74      *
75      * @return true if this is the first round of the algorithm
76      */
77     public boolean getFirstRound() {
78         return firstRound;
79     }
80
81     /**
82      * Sets the first round indicator of the algorithm.
83      *
84      * @param firstRound the first round indicator of the algorithm
85      */
86     public void setFirstRound(final boolean firstRound) {
87         this.firstRound = firstRound;
88     }
89
90     /**
91      * Gets the frequency value of the algorithm.
92      *
93      * @return the frequency value of the algorithm
94      */
95     public int getFrequency() {
96         return frequency;
97     }
98
99     /**
100      * Sets the frequency value of the algorithm.
101      *
102      * @param frequency the frequency value of the algorithm
103      */
104     public void setFrequency(final int frequency) {
105         this.frequency = frequency;
106     }
107
108     /**
109      * Gets the anomaly score values of the algorithm.
110      *
111      * @return the anomaly score values of the algorithm
112      */
113     public List<Double> getAnomalyScores() {
114         return anomalyScores;
115     }
116
117     /**
118      * Sets the anomaly score values of the algorithm.
119      *
120      * @param anomalyScores the anomaly score values of the algorithm
121      */
122     public void setAnomalyScores(final List<Double> anomalyScores) {
123         this.anomalyScores = anomalyScores;
124     }
125
126     /**
127      * Check if the anomaly score values of the algorithm are set.
128      *
129      * @return true, if the anomaly score values of the algorithm are set
130      */
131     public boolean checkSetAnomalyScores() {
132         return ((anomalyScores != null) && (!anomalyScores.isEmpty()));
133     }
134
135     /**
136      * Unset the anomaly score values of the algorithm.
137      */
138     public void unsetAnomalyScores() {
139         anomalyScores = null;
140     }
141
142     /**
143      * Gets the frequency forecasted by the algorithm.
144      *
145      * @return the frequency forecasted by the algorithm
146      */
147     public List<Double> getFrequencyForecasted() {
148         return frequencyForecasted;
149     }
150
151     /**
152      * Sets the frequency forecasted by the algorithm.
153      *
154      * @param frequencyForecasted the frequency forecasted by the algorithm
155      */
156     public void setFrequencyForecasted(final List<Double> frequencyForecasted) {
157         this.frequencyForecasted = frequencyForecasted;
158     }
159
160     /**
161      * Check if the frequency forecasted by the algorithm is set.
162      *
163      * @return true, if the frequency forecasted by the algorithm is set
164      */
165     public boolean checkSetFrequencyForecasted() {
166         return ((frequencyForecasted != null) && (!frequencyForecasted.isEmpty()));
167     }
168
169     /**
170      * Unset the frequency forecasted by the algorithm.
171      */
172     public void unsetFrequencyForecasted() {
173         frequencyForecasted = null;
174     }
175
176     /**
177      * {@inheritDoc}.
178      */
179     @Override
180     public String toString() {
181         return "AnomalyDetection [firstRound=" + firstRound + ", frequency=" + frequency + ", anomalyScores="
182                 + anomalyScores + ", frequencyForecasted=" + frequencyForecasted + "]";
183     }
184 }