Fix minor warnings in code
[policy/apex-pdp.git] / testsuites / integration / integration-context-test / src / test / java / org / onap / policy / apex / testsuites / integration / context / entities / ReferenceKeyTestEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019,2022 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.testsuites.integration.context.entities;
24
25 import java.util.Arrays;
26 import java.util.List;
27 import javax.xml.bind.annotation.XmlElement;
28 import lombok.AllArgsConstructor;
29 import lombok.EqualsAndHashCode;
30 import lombok.Getter;
31 import lombok.Setter;
32 import lombok.ToString;
33 import org.apache.commons.lang3.builder.CompareToBuilder;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
37 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
38
39 /**
40  * The Class ReferenceKeyTestEntity provides a reference key test concept.
41  */
42 @Getter
43 @Setter
44 @ToString
45 @EqualsAndHashCode(callSuper = false)
46 @AllArgsConstructor
47 public class ReferenceKeyTestEntity extends AxConcept {
48     private static final long serialVersionUID = -2962570563281067895L;
49
50     @XmlElement(name = "key", required = true)
51     protected AxReferenceKey key;
52
53     private double doubleValue;
54
55     /**
56      * Instantiates a new reference key test entity.
57      */
58     public ReferenceKeyTestEntity() {
59         this.key = new AxReferenceKey();
60         this.doubleValue = 0;
61     }
62
63     /**
64      * Instantiates a new reference key test entity.
65      *
66      * @param doubleValue the double value
67      */
68     public ReferenceKeyTestEntity(final Double doubleValue) {
69         this.key = new AxReferenceKey();
70         this.doubleValue = doubleValue;
71     }
72
73     /**
74      * {@inheritDoc}.
75      */
76     @Override
77     public List<AxKey> getKeys() {
78         return Arrays.asList((AxKey) getKey());
79     }
80
81     /**
82      * Check set key.
83      *
84      * @return true, if successful
85      */
86     public boolean checkSetKey() {
87         return (this.key != null);
88     }
89
90     /**
91      * {@inheritDoc}.
92      */
93     @Override
94     public AxValidationResult validate(final AxValidationResult result) {
95         return key.validate(result);
96     }
97
98     /**
99      * {@inheritDoc}.
100      */
101     @Override
102     public void clean() {
103         key.clean();
104     }
105
106     /**
107      * {@inheritDoc}.
108      */
109     @Override
110     public AxConcept copyTo(final AxConcept target) {
111         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
112         if (copyObject instanceof ReferenceKeyTestEntity) {
113             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
114             if (this.checkSetKey()) {
115                 copy.setKey(new AxReferenceKey(key));
116             } else {
117                 copy.key = null;
118             }
119             copy.doubleValue = doubleValue;
120             return copy;
121         } else {
122             return null;
123         }
124     }
125
126     /**
127      * {@inheritDoc}.
128      */
129     @Override
130     public int compareTo(final AxConcept otherObj) {
131         if (otherObj == null) {
132             return -1;
133         }
134         if (this == otherObj) {
135             return 0;
136         }
137         if (getClass() != otherObj.getClass()) {
138             return -1;
139         }
140         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
141         return new CompareToBuilder()
142                         .append(key, other.key)
143                         .append(doubleValue, other.doubleValue)
144                         .toComparison();
145     }
146 }