Changes for checkstyle 8.32
[policy/apex-pdp.git] / testsuites / integration / integration-common / src / main / java / org / onap / policy / apex / context / test / concepts / TestContextDateItem.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.context.test.concepts;
23
24 import java.io.Serializable;
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
28 import lombok.Data;
29
30 /**
31  * The Class TestContextDateItem.
32  */
33 @Data
34 public class TestContextDateItem implements Serializable {
35     private static final long serialVersionUID = -6984963129968805460L;
36
37     private long time;
38
39     private int year;
40     private int month;
41     private int day;
42     private int hour;
43     private int minute;
44     private int second;
45     private int milliSecond;
46
47     /**
48      * The Constructor.
49      */
50     public TestContextDateItem() {
51         this(new Date(System.currentTimeMillis()));
52     }
53
54     /**
55      * The Constructor.
56      *
57      * @param dateValue the date value
58      */
59     public TestContextDateItem(final Date dateValue) {
60         if (dateValue != null) {
61             setDateValue(dateValue.getTime());
62         } else {
63             new Date(0);
64         }
65     }
66
67     /**
68      * The Constructor.
69      *
70      * @param time the time
71      */
72     public TestContextDateItem(final long time) {
73         setDateValue(time);
74     }
75
76     /**
77      * Gets the date value.
78      *
79      * @return the date value
80      */
81     public Date getDateValue() {
82         return new Date(time);
83     }
84
85     /**
86      * Sets the date value.
87      *
88      * @param dateValue the date value
89      */
90     public void setDateValue(final Date dateValue) {
91         if (dateValue != null) {
92             setDateValue(dateValue.getTime());
93         }
94     }
95
96     /**
97      * Sets the date value.
98      *
99      * @param dateValue the date value
100      */
101     public void setDateValue(final long dateValue) {
102         this.time = dateValue;
103
104         final Calendar calendar = Calendar.getInstance();
105         calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
106         calendar.setTimeInMillis(time);
107
108         year = calendar.get(Calendar.YEAR);
109         month = calendar.get(Calendar.MONTH);
110         day = calendar.get(Calendar.DAY_OF_MONTH);
111         hour = calendar.get(Calendar.HOUR);
112         minute = calendar.get(Calendar.MINUTE);
113         second = calendar.get(Calendar.SECOND);
114         milliSecond = calendar.get(Calendar.MILLISECOND);
115     }
116 }