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