2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.examples.adaptive.concepts;
23 import java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.List;
28 * The Class AutoLearn is used as a Java context for Adaptive auto-learning of trends towards a fixed value in the
31 public class AutoLearn implements Serializable {
32 private static final long serialVersionUID = 3825970380434170754L;
34 private transient List<Double> avDiffs = null;
36 private transient List<Long> counts = null;
39 * Checks if the Autolearn instance is initialized.
41 * @return true, if the Autolearn instance is initialized
43 public boolean isInitialized() {
44 return (avDiffs != null && counts != null);
48 * initializes the auto learning algorithm with the number of convergent variables to use.
50 * @param size the number of convergent variables to use
52 public void init(final int size) {
53 if (avDiffs == null || avDiffs.isEmpty()) {
54 avDiffs = new ArrayList<>(size);
55 for (int i = 0; i < size; i++) {
56 avDiffs.add(i, Double.NaN);
60 if (counts == null || counts.isEmpty()) {
61 counts = new ArrayList<>(size);
62 for (int i = 0; i < size; i++) {
69 * Gets the average difference values of the algorithm.
71 * @return the average difference values of the algorithm
73 public List<Double> getAvDiffs() {
78 * Sets the average difference values of the algorithm.
80 * @param avDiffs the average difference values of the algorithm
82 public void setAvDiffs(final List<Double> avDiffs) {
83 this.avDiffs = avDiffs;
87 * Check if the average difference values of the algorithm are set.
89 * @return true, if check set av diffs
91 public boolean checkSetAvDiffs() {
92 return ((avDiffs != null) && (!avDiffs.isEmpty()));
96 * Unset the average difference values of the algorithm.
98 public void unsetAvDiffs() {
103 * Gets the count values of the algorithm.
105 * @return the count values of the algorithm
107 public List<Long> getCounts() {
112 * Sets the count values of the algorithm.
114 * @param counts the count values of the algorithm
116 public void setCounts(final List<Long> counts) {
117 this.counts = counts;
121 * Check if the count values of the algorithm are set.
123 * @return true, if the count values of the algorithm are set
125 public boolean checkSetCounts() {
126 return ((counts != null) && (!counts.isEmpty()));
130 * Unset the count values of the algorithm.
132 public void unsetCounts() {
139 * @see java.lang.Object#toString()
142 public String toString() {
143 return "AutoLearn [avDiffs=" + avDiffs + ", counts=" + counts + "]";
149 * @see java.lang.Object#hashCode()
152 public int hashCode() {
153 final int prime = 31;
155 result = prime * result + ((avDiffs == null) ? 0 : avDiffs.hashCode());
156 result = prime * result + ((counts == null) ? 0 : counts.hashCode());
163 * @see java.lang.Object#equals(java.lang.Object)
166 public boolean equals(final Object obj) {
173 if (getClass() != obj.getClass()) {
176 final AutoLearn other = (AutoLearn) obj;
177 if (avDiffs == null) {
178 if (other.avDiffs != null) {
181 } else if (!avDiffs.equals(other.avDiffs)) {
184 if (counts == null) {
185 if (other.counts != null) {
188 } else if (!counts.equals(other.counts)) {