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