6f276335ba9bfd2100319798ca73c4d4b0ed9045
[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 @Entity
39 @Table(name = "ReferenceKeyTestEntity")
40 public class ReferenceKeyTestEntity extends AxConcept {
41     private static final long serialVersionUID = -2962570563281067895L;
42
43     @EmbeddedId()
44     @XmlElement(name = "key", required = true)
45     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
46     protected AxReferenceKey key;
47
48     private double doubleValue;
49
50     public ReferenceKeyTestEntity() {
51         this.key = new AxReferenceKey();
52         this.doubleValue = 0;
53     }
54
55     public ReferenceKeyTestEntity(final Double doubleValue) {
56         this.key = new AxReferenceKey();
57         this.doubleValue = doubleValue;
58     }
59
60     public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
61         this.key = key;
62         this.doubleValue = doubleValue;
63     }
64
65     @Override
66     public AxReferenceKey getKey() {
67         return key;
68     }
69
70     @Override
71     public List<AxKey> getKeys() {
72         return Arrays.asList((AxKey) getKey());
73     }
74
75     public void setKey(final AxReferenceKey key) {
76         this.key = key;
77     }
78
79     public boolean checkSetKey() {
80         return (this.key != null);
81     }
82
83     public double getDoubleValue() {
84         return doubleValue;
85     }
86
87     public void setDoubleValue(final double doubleValue) {
88         this.doubleValue = doubleValue;
89     }
90
91     @Override
92     public AxValidationResult validate(final AxValidationResult result) {
93         return key.validate(result);
94     }
95
96     @Override
97     public void clean() {
98         key.clean();
99     }
100
101     @Override
102     public String toString() {
103         return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
104     }
105
106     @Override
107     public AxConcept copyTo(final AxConcept target) {
108         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
109         if (copyObject instanceof ReferenceKeyTestEntity) {
110             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
111             if (this.checkSetKey()) {
112                 copy.setKey(new AxReferenceKey(key));
113             } else {
114                 copy.key = null;
115             }
116             copy.doubleValue = doubleValue;
117             return copy;
118         } else {
119             return null;
120         }
121     }
122
123     @Override
124     public int hashCode() {
125         final int prime = 31;
126         int result = 1;
127         result = prime * result + ((key == null) ? 0 : key.hashCode());
128         return result;
129     }
130
131     @Override
132     public boolean equals(final Object obj) {
133         if (obj == null) {
134             return false;
135         }
136         if (this == obj) {
137             return true;
138         }
139         if (getClass() != obj.getClass()) {
140             return false;
141         }
142         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
143         if (key == null) {
144             if (other.key != null) {
145                 return false;
146             }
147         } else if (!key.equals(other.key)) {
148             return false;
149         }
150         return (Double.compare(doubleValue, other.doubleValue) == 0);
151     }
152
153     @Override
154     public int compareTo(final AxConcept otherObj) {
155         if (otherObj == null) {
156             return -1;
157         }
158         if (this == otherObj) {
159             return 0;
160         }
161         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
162         if (key == null) {
163             if (other.key != null) {
164                 return 1;
165             }
166         } else if (!key.equals(other.key)) {
167             return key.compareTo(other.key);
168         }
169         return Double.compare(doubleValue, other.doubleValue);
170     }
171 }