Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / concepts / DummyEntity.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 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.model.basicmodel.concepts;
23
24 import java.util.Arrays;
25 import java.util.List;
26 import javax.persistence.EmbeddedId;
27 import javax.persistence.Entity;
28 import javax.persistence.Table;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
32
33 @Entity
34 @Table(name = "TestEntity")
35
36 public class DummyEntity extends AxConcept {
37     private static final long serialVersionUID = -2962570563281067894L;
38
39     @EmbeddedId()
40     @XmlElement(name = "key", required = true)
41     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
42     protected AxReferenceKey key;
43
44     private double doubleValue;
45
46     public DummyEntity() {
47         this.key = new AxReferenceKey();
48         this.doubleValue = 0;
49     }
50
51     public DummyEntity(Double doubleValue) {
52         this.key = new AxReferenceKey();
53         this.doubleValue = doubleValue;
54     }
55
56     public DummyEntity(AxReferenceKey key, Double doubleValue) {
57         this.key = key;
58         this.doubleValue = doubleValue;
59     }
60
61     @Override
62     public AxReferenceKey getKey() {
63         return key;
64     }
65
66     @Override
67     public List<AxKey> getKeys() {
68         return Arrays.asList((AxKey) getKey());
69     }
70
71     public void setKey(AxReferenceKey key) {
72         this.key = key;
73     }
74
75     public boolean checkSetKey() {
76         return (this.key != null);
77     }
78
79     public double getDoubleValue() {
80         return doubleValue;
81     }
82
83     public void setDoubleValue(double doubleValue) {
84         this.doubleValue = doubleValue;
85     }
86
87     @Override
88     public AxValidationResult validate(AxValidationResult result) {
89         return key.validate(result);
90     }
91
92     @Override
93     public void clean() {
94         key.clean();
95     }
96
97     @Override
98     public String toString() {
99         final StringBuilder builder = new StringBuilder();
100         builder.append("doubleValue=");
101         builder.append(doubleValue);
102         return builder.toString();
103     }
104
105     @Override
106     public AxConcept copyTo(AxConcept target) {
107         final Object copyObject = ((target == null) ? new DummyEntity() : target);
108         if (copyObject instanceof DummyEntity) {
109             final DummyEntity copy = ((DummyEntity) copyObject);
110             if (this.checkSetKey()) {
111                 copy.setKey(new AxReferenceKey(key));
112             } else {
113                 copy.key = null;
114             }
115             copy.doubleValue = doubleValue;
116             return copy;
117         } else {
118             return null;
119         }
120     }
121
122     @Override
123     public int hashCode() {
124         final int prime = 31;
125         int result = 1;
126         result = prime * result + ((key == null) ? 0 : key.hashCode());
127         return result;
128     }
129
130     @Override
131     public boolean equals(Object obj) {
132         if (obj == null) {
133             return false;
134         }
135         if (this == obj) {
136             return true;
137         }
138         if (getClass() != obj.getClass()) {
139             return false;
140         }
141         DummyEntity other = (DummyEntity) obj;
142         if (key == null) {
143             if (other.key != null) {
144                 return false;
145             }
146         } else if (!key.equals(other.key)) {
147             return false;
148         }
149         if (doubleValue != other.doubleValue) {
150             return false;
151         }
152         return true;
153     }
154
155     @Override
156     public int compareTo(AxConcept otherObj) {
157         if (otherObj == null) {
158             return -1;
159         }
160         if (this == otherObj) {
161             return 0;
162         }
163         DummyEntity other = (DummyEntity) otherObj;
164         if (key == null) {
165             if (other.key != null) {
166                 return 1;
167             }
168         } else if (!key.equals(other.key)) {
169             return key.compareTo(other.key);
170         }
171         if (doubleValue != other.doubleValue) {
172             return Double.valueOf(doubleValue).compareTo(other.doubleValue);
173         }
174
175         return 0;
176     }
177 }