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