Replace non-Javadoc comments with inheritDocs
[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 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
29 /**
30  * The Class TestContextItem008.
31  */
32 public class TestContextDateItem implements Serializable {
33     private static final long serialVersionUID = -6984963129968805460L;
34
35     private static final int HASH_PRIME_1 = 31;
36     private static final int FOUR_BYTES = 32;
37
38     private long time;
39
40     private int year;
41     private int month;
42     private int day;
43     private int hour;
44     private int minute;
45     private int second;
46     private int milliSecond;
47
48     /**
49      * The Constructor.
50      */
51     public TestContextDateItem() {
52         this(new Date(System.currentTimeMillis()));
53     }
54
55     /**
56      * The Constructor.
57      *
58      * @param dateValue the date value
59      */
60     public TestContextDateItem(final Date dateValue) {
61         if (dateValue != null) {
62             setDateValue(dateValue.getTime());
63         }
64         else {
65             new Date(0);
66         }
67     }
68
69     /**
70      * The Constructor.
71      *
72      * @param time the time
73      */
74     public TestContextDateItem(final long time) {
75         setDateValue(time);
76     }
77
78     /**
79      * Gets the time.
80      *
81      * @return the time
82      */
83     public long getTime() {
84         return time;
85     }
86
87     /**
88      * Gets the year.
89      *
90      * @return the year
91      */
92     public int getYear() {
93         return year;
94     }
95
96     /**
97      * Gets the month.
98      *
99      * @return the month
100      */
101     public int getMonth() {
102         return month;
103     }
104
105     /**
106      * Gets the day.
107      *
108      * @return the day
109      */
110     public int getDay() {
111         return day;
112     }
113
114     /**
115      * Gets the hour.
116      *
117      * @return the hour
118      */
119     public int getHour() {
120         return hour;
121     }
122
123     /**
124      * Gets the minute.
125      *
126      * @return the minute
127      */
128     public int getMinute() {
129         return minute;
130     }
131
132     /**
133      * Gets the second.
134      *
135      * @return the second
136      */
137     public int getSecond() {
138         return second;
139     }
140
141     /**
142      * Gets the milli second.
143      *
144      * @return the milli second
145      */
146     public int getMilliSecond() {
147         return milliSecond;
148     }
149
150     /**
151      * Gets the date value.
152      *
153      * @return the date value
154      */
155     public Date getDateValue() {
156         return new Date(time);
157     }
158
159     /**
160      * Sets the date value.
161      *
162      * @param dateValue the date value
163      */
164     public void setDateValue(final Date dateValue) {
165         if (dateValue != null) {
166             setDateValue(dateValue.getTime());
167         }
168     }
169
170     /**
171      * Sets the date value.
172      *
173      * @param dateValue the date value
174      */
175     public void setDateValue(final long dateValue) {
176         this.time = dateValue;
177
178         final Calendar calendar = Calendar.getInstance();
179         calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
180         calendar.setTimeInMillis(time);
181
182         year = calendar.get(Calendar.YEAR);
183         month = calendar.get(Calendar.MONTH);
184         day = calendar.get(Calendar.DAY_OF_MONTH);
185         hour = calendar.get(Calendar.HOUR);
186         minute = calendar.get(Calendar.MINUTE);
187         second = calendar.get(Calendar.SECOND);
188         milliSecond = calendar.get(Calendar.MILLISECOND);
189     }
190
191
192     /**
193      * {@inheritDoc}.
194      */
195     @Override
196     public int hashCode() {
197         final int prime = HASH_PRIME_1;
198         int result = 1;
199         result = prime * result + day;
200         result = prime * result + hour;
201         result = prime * result + milliSecond;
202         result = prime * result + minute;
203         result = prime * result + month;
204         result = prime * result + second;
205         result = prime * result + (int) (time ^ (time >>> FOUR_BYTES));
206         result = prime * result + year;
207         return result;
208     }
209
210     /**
211      * {@inheritDoc}.
212      */
213     @Override
214     public boolean equals(final Object obj) {
215         if (this == obj) {
216             return true;
217         }
218         if (obj == null) {
219             return false;
220         }
221         if (getClass() != obj.getClass()) {
222             return false;
223         }
224         final TestContextDateItem other = (TestContextDateItem) obj;
225         return time == other.time;
226     }
227
228     /**
229      * {@inheritDoc}.
230      */
231     @Override
232     public String toString() {
233         return "TestContextItem008 [time=" + time + ", year=" + year + ", month=" + month + ", day=" + day + ", hour="
234                 + hour + ", minute=" + minute + ", second=" + second + ", milliSecond=" + milliSecond + "]";
235     }
236 }