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
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.apex.context.test.concepts;
23 import java.io.Serializable;
24 import java.util.Calendar;
25 import java.util.Date;
26 import java.util.TimeZone;
29 * The Class TestContextItem008.
31 public class TestContextDateItem implements Serializable {
32 private static final long serialVersionUID = -6984963129968805460L;
34 private static final int HASH_PRIME_1 = 31;
35 private static final int FOUR_BYTES = 32;
45 private int milliSecond;
50 public TestContextDateItem() {
51 this(new Date(System.currentTimeMillis()));
57 * @param dateValue the date value
59 public TestContextDateItem(final Date dateValue) {
60 if (dateValue != null) {
61 setDateValue(dateValue.getTime());
71 * @param time the time
73 public TestContextDateItem(final long time) {
82 public long getTime() {
91 public int getYear() {
100 public int getMonth() {
109 public int getDay() {
118 public int getHour() {
127 public int getMinute() {
136 public int getSecond() {
141 * Gets the milli second.
143 * @return the milli second
145 public int getMilliSecond() {
150 * Gets the date value.
152 * @return the date value
154 public Date getDateValue() {
155 return new Date(time);
159 * Sets the date value.
161 * @param dateValue the date value
163 public void setDateValue(final Date dateValue) {
164 if (dateValue != null) {
165 setDateValue(dateValue.getTime());
170 * Sets the date value.
172 * @param dateValue the date value
174 public void setDateValue(final long dateValue) {
175 this.time = dateValue;
177 final Calendar calendar = Calendar.getInstance();
178 calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
179 calendar.setTimeInMillis(time);
181 year = calendar.get(Calendar.YEAR);
182 month = calendar.get(Calendar.MONTH);
183 day = calendar.get(Calendar.DAY_OF_MONTH);
184 hour = calendar.get(Calendar.HOUR);
185 minute = calendar.get(Calendar.MINUTE);
186 second = calendar.get(Calendar.SECOND);
187 milliSecond = calendar.get(Calendar.MILLISECOND);
194 * @see java.lang.Object#hashCode()
197 public int hashCode() {
198 final int prime = HASH_PRIME_1;
200 result = prime * result + day;
201 result = prime * result + hour;
202 result = prime * result + milliSecond;
203 result = prime * result + minute;
204 result = prime * result + month;
205 result = prime * result + second;
206 result = prime * result + (int) (time ^ (time >>> FOUR_BYTES));
207 result = prime * result + year;
214 * @see java.lang.Object#equals(java.lang.Object)
217 public boolean equals(final Object obj) {
224 if (getClass() != obj.getClass()) {
227 final TestContextDateItem other = (TestContextDateItem) obj;
228 return time == other.time;
234 * @see java.lang.Object#toString()
237 public String toString() {
238 return "TestContextItem008 [time=" + time + ", year=" + year + ", month=" + month + ", day=" + day + ", hour="
239 + hour + ", minute=" + minute + ", second=" + second + ", milliSecond=" + milliSecond + "]";