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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.examples.adaptive.concepts;
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.LinkedList;
27 import java.util.List;
28 import lombok.EqualsAndHashCode;
31 * The Class AnomalyDetection is used as a Java context for Adaptive anomaly detection in the adaptive domain.
34 public class AnomalyDetection implements Serializable {
35 private static final long serialVersionUID = -823013127095523727L;
37 private boolean firstRound = true;
38 private int frequency = 0;
40 private List<Double> anomalyScores = new LinkedList<>();
41 private List<Double> frequencyForecasted;
44 * The Constructor creates an AnomalyDetection instance.
46 public AnomalyDetection() {
52 * Checks if the AnomalyDetection instance is initialized.
54 * @return true, if the AnomalyDetection instance is initialized
56 public boolean isInitialized() {
57 return (frequencyForecasted != null);
61 * Initializes the AnomalyDetection instance.
63 * @param incomingFrequency the frequency
65 public void init(final int incomingFrequency) {
66 frequencyForecasted = new ArrayList<>(incomingFrequency);
67 for (var i = 0; i < incomingFrequency; i++) {
68 frequencyForecasted.add(null);
73 * Indicates if this is the first round of the algorithm.
75 * @return true if this is the first round of the algorithm
77 public boolean getFirstRound() {
82 * Sets the first round indicator of the algorithm.
84 * @param firstRound the first round indicator of the algorithm
86 public void setFirstRound(final boolean firstRound) {
87 this.firstRound = firstRound;
91 * Gets the frequency value of the algorithm.
93 * @return the frequency value of the algorithm
95 public int getFrequency() {
100 * Sets the frequency value of the algorithm.
102 * @param frequency the frequency value of the algorithm
104 public void setFrequency(final int frequency) {
105 this.frequency = frequency;
109 * Gets the anomaly score values of the algorithm.
111 * @return the anomaly score values of the algorithm
113 public List<Double> getAnomalyScores() {
114 return anomalyScores;
118 * Sets the anomaly score values of the algorithm.
120 * @param anomalyScores the anomaly score values of the algorithm
122 public void setAnomalyScores(final List<Double> anomalyScores) {
123 this.anomalyScores = anomalyScores;
127 * Check if the anomaly score values of the algorithm are set.
129 * @return true, if the anomaly score values of the algorithm are set
131 public boolean checkSetAnomalyScores() {
132 return ((anomalyScores != null) && (!anomalyScores.isEmpty()));
136 * Unset the anomaly score values of the algorithm.
138 public void unsetAnomalyScores() {
139 anomalyScores = null;
143 * Gets the frequency forecasted by the algorithm.
145 * @return the frequency forecasted by the algorithm
147 public List<Double> getFrequencyForecasted() {
148 return frequencyForecasted;
152 * Sets the frequency forecasted by the algorithm.
154 * @param frequencyForecasted the frequency forecasted by the algorithm
156 public void setFrequencyForecasted(final List<Double> frequencyForecasted) {
157 this.frequencyForecasted = frequencyForecasted;
161 * Check if the frequency forecasted by the algorithm is set.
163 * @return true, if the frequency forecasted by the algorithm is set
165 public boolean checkSetFrequencyForecasted() {
166 return ((frequencyForecasted != null) && (!frequencyForecasted.isEmpty()));
170 * Unset the frequency forecasted by the algorithm.
172 public void unsetFrequencyForecasted() {
173 frequencyForecasted = null;
180 public String toString() {
181 return "AnomalyDetection [firstRound=" + firstRound + ", frequency=" + frequency + ", anomalyScores="
182 + anomalyScores + ", frequencyForecasted=" + frequencyForecasted + "]";