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.Locale;
25 import java.util.TimeZone;
28 * The Class TestContextItem00A.
30 public class TestContextDateLocaleItem implements Serializable {
31 private static final long serialVersionUID = -6579903685538233754L;
33 private static final int HASH_PRIME_1 = 31;
34 private static final int HASH_PRIME_2 = 1231;
35 private static final int HASH_PRIME_3 = 1237;
37 private TestContextDateItem dateValue = new TestContextDateItem(System.currentTimeMillis());
38 private String timeZoneString = TimeZone.getTimeZone("Europe/Dublin").getDisplayName();
39 private boolean dst = false;
40 private int utcOffset = 0;
41 private Locale locale = Locale.ENGLISH;
46 public TestContextDateLocaleItem() {
52 * @param dateValue the date value
53 * @param tzValue the tz value
55 * @param utcOffset the utc offset
56 * @param language the language
57 * @param country the country
59 public TestContextDateLocaleItem(final TestContextDateItem dateValue, final String tzValue, final boolean dst,
60 final int utcOffset, final String language, final String country) {
61 this.dateValue = dateValue;
62 this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
64 this.utcOffset = utcOffset;
66 this.locale = new Locale(language, country);
72 * @param original the original
74 public TestContextDateLocaleItem(final TestContextDateLocaleItem original) {
75 this.dateValue = original.dateValue;
76 this.timeZoneString = TimeZone.getTimeZone(original.timeZoneString).getDisplayName();
77 this.dst = original.dst;
78 this.utcOffset = original.utcOffset;
80 this.locale = new Locale(original.getLocale().getCountry(), original.getLocale().getLanguage());
84 * Gets the date value.
86 * @return the date value
88 public TestContextDateItem getDateValue() {
93 * Sets the date value.
95 * @param dateValue the date value
97 public void setDateValue(final TestContextDateItem dateValue) {
98 this.dateValue = dateValue;
104 * @return the TZ value
106 public String getTzValue() {
107 return timeZoneString;
113 * @param tzValue the TZ value
115 public void setTzValue(final String tzValue) {
116 if (tzValue != null) {
117 this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
119 this.timeZoneString = null;
128 public boolean getDst() {
135 * @param newDst the dst
137 public void setDst(final boolean newDst) {
142 * Gets the UTC offset.
144 * @return the UTC offset
146 public int getUtcOffset() {
151 * Sets the UTC offset.
153 * @param newUtcOffset the UTC offset
155 public void setUtcOffset(final int newUtcOffset) {
156 this.utcOffset = newUtcOffset;
164 public Locale getLocale() {
171 * @param locale the locale
173 public void setLocale(final Locale locale) {
174 if (locale != null) {
175 this.locale = locale;
185 * @see java.lang.Object#hashCode()
188 public int hashCode() {
189 final int prime = HASH_PRIME_1;
191 result = prime * result + ((dateValue == null) ? 0 : dateValue.hashCode());
192 result = prime * result + (dst ? HASH_PRIME_2 : HASH_PRIME_3);
193 result = prime * result + ((locale == null) ? 0 : locale.hashCode());
194 result = prime * result + ((timeZoneString == null) ? 0 : timeZoneString.hashCode());
195 result = prime * result + utcOffset;
202 * @see java.lang.Object#equals(java.lang.Object)
205 public boolean equals(final Object obj) {
212 if (getClass() != obj.getClass()) {
215 final TestContextDateLocaleItem other = (TestContextDateLocaleItem) obj;
216 if (dateValue == null) {
217 if (other.dateValue != null) {
220 } else if (!dateValue.equals(other.dateValue)) {
223 if (dst != other.dst) {
226 if (locale == null) {
227 if (other.locale != null) {
230 } else if (!locale.equals(other.locale)) {
233 if (timeZoneString == null) {
234 if (other.timeZoneString != null) {
237 } else if (!timeZoneString.equals(other.timeZoneString)) {
240 return utcOffset == other.utcOffset;
246 * @see java.lang.Object#toString()
249 public String toString() {
250 return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst
251 + ", utcOffset=" + utcOffset + ", locale=" + locale + "]";