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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.context.test.concepts;
24 import java.io.Serializable;
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
30 * The Class TestContextItem008.
32 public class TestContextDateItem implements Serializable {
33 private static final long serialVersionUID = -6984963129968805460L;
35 private static final int HASH_PRIME_1 = 31;
36 private static final int FOUR_BYTES = 32;
46 private int milliSecond;
51 public TestContextDateItem() {
52 this(new Date(System.currentTimeMillis()));
58 * @param dateValue the date value
60 public TestContextDateItem(final Date dateValue) {
61 if (dateValue != null) {
62 setDateValue(dateValue.getTime());
72 * @param time the time
74 public TestContextDateItem(final long time) {
83 public long getTime() {
92 public int getYear() {
101 public int getMonth() {
110 public int getDay() {
119 public int getHour() {
128 public int getMinute() {
137 public int getSecond() {
142 * Gets the milli second.
144 * @return the milli second
146 public int getMilliSecond() {
151 * Gets the date value.
153 * @return the date value
155 public Date getDateValue() {
156 return new Date(time);
160 * Sets the date value.
162 * @param dateValue the date value
164 public void setDateValue(final Date dateValue) {
165 if (dateValue != null) {
166 setDateValue(dateValue.getTime());
171 * Sets the date value.
173 * @param dateValue the date value
175 public void setDateValue(final long dateValue) {
176 this.time = dateValue;
178 final Calendar calendar = Calendar.getInstance();
179 calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
180 calendar.setTimeInMillis(time);
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);
196 public int hashCode() {
197 final int prime = HASH_PRIME_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;
214 public boolean equals(final Object obj) {
221 if (getClass() != obj.getClass()) {
224 final TestContextDateItem other = (TestContextDateItem) obj;
225 return time == other.time;
232 public String toString() {
233 return "TestContextItem008 [time=" + time + ", year=" + year + ", month=" + month + ", day=" + day + ", hour="
234 + hour + ", minute=" + minute + ", second=" + second + ", milliSecond=" + milliSecond + "]";