3c421a7a93d732acf31245c2c17c0bbb4de60388
[policy/apex-pdp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.context.test.entities;
22
23 import java.util.Arrays;
24 import java.util.List;
25
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
32 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
36 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
37
38 /**
39  * The Class ReferenceKeyTestEntity provides a reference key test concept.
40  */
41 @Entity
42 @Table(name = "ReferenceKeyTestEntity")
43 public class ReferenceKeyTestEntity extends AxConcept {
44     private static final long serialVersionUID = -2962570563281067895L;
45
46     @EmbeddedId()
47     @XmlElement(name = "key", required = true)
48     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
49     protected AxReferenceKey key;
50
51     private double doubleValue;
52
53     /**
54      * Instantiates a new reference key test entity.
55      */
56     public ReferenceKeyTestEntity() {
57         this.key = new AxReferenceKey();
58         this.doubleValue = 0;
59     }
60
61     /**
62      * Instantiates a new reference key test entity.
63      *
64      * @param doubleValue the double value
65      */
66     public ReferenceKeyTestEntity(final Double doubleValue) {
67         this.key = new AxReferenceKey();
68         this.doubleValue = doubleValue;
69     }
70
71     /**
72      * Instantiates a new reference key test entity.
73      *
74      * @param key the key
75      * @param doubleValue the double value
76      */
77     public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
78         this.key = key;
79         this.doubleValue = doubleValue;
80     }
81
82     /*
83      * (non-Javadoc)
84      * 
85      * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
86      */
87     @Override
88     public AxReferenceKey getKey() {
89         return key;
90     }
91
92     /*
93      * (non-Javadoc)
94      * 
95      * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
96      */
97     @Override
98     public List<AxKey> getKeys() {
99         return Arrays.asList((AxKey) getKey());
100     }
101
102     /**
103      * Sets the key.
104      *
105      * @param key the new key
106      */
107     public void setKey(final AxReferenceKey key) {
108         this.key = key;
109     }
110
111     /**
112      * Check set key.
113      *
114      * @return true, if successful
115      */
116     public boolean checkSetKey() {
117         return (this.key != null);
118     }
119
120     /**
121      * Gets the double value.
122      *
123      * @return the double value
124      */
125     public double getDoubleValue() {
126         return doubleValue;
127     }
128
129     /**
130      * Sets the double value.
131      *
132      * @param doubleValue the new double value
133      */
134     public void setDoubleValue(final double doubleValue) {
135         this.doubleValue = doubleValue;
136     }
137
138     /*
139      * (non-Javadoc)
140      * 
141      * @see
142      * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
143      * AxValidationResult)
144      */
145     @Override
146     public AxValidationResult validate(final AxValidationResult result) {
147         return key.validate(result);
148     }
149
150     /*
151      * (non-Javadoc)
152      * 
153      * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
154      */
155     @Override
156     public void clean() {
157         key.clean();
158     }
159
160     /*
161      * (non-Javadoc)
162      * 
163      * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
164      */
165     @Override
166     public String toString() {
167         return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
168     }
169
170     /*
171      * (non-Javadoc)
172      * 
173      * @see
174      * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
175      * AxConcept)
176      */
177     @Override
178     public AxConcept copyTo(final AxConcept target) {
179         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
180         if (copyObject instanceof ReferenceKeyTestEntity) {
181             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
182             if (this.checkSetKey()) {
183                 copy.setKey(new AxReferenceKey(key));
184             } else {
185                 copy.key = null;
186             }
187             copy.doubleValue = doubleValue;
188             return copy;
189         } else {
190             return null;
191         }
192     }
193
194     /*
195      * (non-Javadoc)
196      * 
197      * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
198      */
199     @Override
200     public int hashCode() {
201         final int prime = 31;
202         int result = 1;
203         result = prime * result + ((key == null) ? 0 : key.hashCode());
204         return result;
205     }
206
207     /*
208      * (non-Javadoc)
209      * 
210      * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
211      */
212     @Override
213     public boolean equals(final Object obj) {
214         if (obj == null) {
215             return false;
216         }
217         if (this == obj) {
218             return true;
219         }
220         if (getClass() != obj.getClass()) {
221             return false;
222         }
223         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
224         if (key == null) {
225             if (other.key != null) {
226                 return false;
227             }
228         } else if (!key.equals(other.key)) {
229             return false;
230         }
231         return (Double.compare(doubleValue, other.doubleValue) == 0);
232     }
233
234     /*
235      * (non-Javadoc)
236      * 
237      * @see java.lang.Comparable#compareTo(java.lang.Object)
238      */
239     @Override
240     public int compareTo(final AxConcept otherObj) {
241         if (otherObj == null) {
242             return -1;
243         }
244         if (this == otherObj) {
245             return 0;
246         }
247         if (getClass() != otherObj.getClass()) {
248             return -1;
249         }
250         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
251         if (key == null) {
252             if (other.key != null) {
253                 return 1;
254             }
255         } else if (!key.equals(other.key)) {
256             return key.compareTo(other.key);
257         }
258         return Double.compare(doubleValue, other.doubleValue);
259     }
260 }