2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.dao;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.List;
26 import javax.persistence.Column;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import javax.persistence.Temporal;
31 import javax.persistence.TemporalType;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35 import org.onap.policy.common.parameters.BeanValidationResult;
36 import org.onap.policy.models.base.PfConcept;
37 import org.onap.policy.models.base.PfGeneratedIdKey;
38 import org.onap.policy.models.base.PfKey;
42 @Table(name = "DummyGeneratedIdEntity")
44 @EqualsAndHashCode(callSuper = false)
45 public class DummyGeneratedIdEntity extends PfConcept {
46 private static final long serialVersionUID = -2962570563281067896L;
50 private PfGeneratedIdKey key;
52 @Column(precision = 3)
53 @Temporal(TemporalType.TIMESTAMP)
54 private Date timeStamp;
57 private double doubleValue;
60 * Default constructor.
62 public DummyGeneratedIdEntity() {
63 this.key = new PfGeneratedIdKey();
64 this.timeStamp = new Date();
67 public DummyGeneratedIdEntity(DummyGeneratedIdEntity source) {
68 this.key = source.key;
69 this.timeStamp = source.timeStamp;
76 * @param timeStamp the date value
78 public DummyGeneratedIdEntity(final PfGeneratedIdKey key, final Date timeStamp) {
80 this.timeStamp = timeStamp;
87 * @param timeStamp the date value
88 * @param doubleValue the double value *
90 public DummyGeneratedIdEntity(final PfGeneratedIdKey key, final Date timeStamp, final double doubleValue) {
92 this.timeStamp = timeStamp;
93 this.doubleValue = doubleValue;
97 public List<PfKey> getKeys() {
98 final List<PfKey> keyList = new ArrayList<>();
99 keyList.add(getKey());
104 public BeanValidationResult validate(@NonNull String fieldName) {
105 BeanValidationResult result = new BeanValidationResult(fieldName, this);
106 result.addResult(key.validate("key"));
111 public void clean() {
116 public int compareTo(@NonNull final PfConcept otherObj) {
117 if (this == otherObj) {
121 if (getClass() != otherObj.getClass()) {
122 return this.getClass().getName().compareTo(otherObj.getClass().getName());
125 final DummyGeneratedIdEntity other = (DummyGeneratedIdEntity) otherObj;
126 if (this.timeStamp != other.timeStamp) {
127 return timeStamp.compareTo(other.timeStamp);
129 return Double.compare(doubleValue, other.doubleValue);