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 String localeLanguage = Locale.ENGLISH.getLanguage();
42 private String localeCountry = Locale.ENGLISH.getCountry();
47 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 final Locale locale = new Locale(language, country);
67 this.localeLanguage = locale.getLanguage();
68 this.localeCountry = locale.getCountry();
74 * @param original the original
76 public TestContextDateLocaleItem(final TestContextDateLocaleItem original) {
77 this.dateValue = original.dateValue;
78 this.timeZoneString = TimeZone.getTimeZone(original.timeZoneString).getDisplayName();
79 this.dst = original.dst;
80 this.utcOffset = original.utcOffset;
82 final Locale locale = new Locale(original.localeLanguage, original.localeCountry);
83 this.localeLanguage = locale.getLanguage();
84 this.localeCountry = locale.getCountry();
88 * Gets the date value.
90 * @return the date value
92 public TestContextDateItem getDateValue() {
97 * Sets the date value.
99 * @param dateValue the date value
101 public void setDateValue(final TestContextDateItem dateValue) {
102 this.dateValue = dateValue;
108 * @return the TZ value
110 public String getTzValue() {
111 return timeZoneString;
117 * @param tzValue the TZ value
119 public void setTzValue(final String tzValue) {
120 this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
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() {
165 return new Locale(localeLanguage, localeCountry);
171 * @param locale the locale
173 public void setLocale(final Locale locale) {
174 this.localeLanguage = locale.getLanguage();
175 this.localeCountry = locale.getCountry();
181 * @see java.lang.Object#hashCode()
184 public int hashCode() {
185 final int prime = HASH_PRIME_1;
187 result = prime * result + ((dateValue == null) ? 0 : dateValue.hashCode());
188 result = prime * result + (dst ? HASH_PRIME_2 : HASH_PRIME_3);
189 result = prime * result + ((localeCountry == null) ? 0 : localeCountry.hashCode());
190 result = prime * result + ((localeLanguage == null) ? 0 : localeLanguage.hashCode());
191 result = prime * result + ((timeZoneString == null) ? 0 : timeZoneString.hashCode());
192 result = prime * result + utcOffset;
199 * @see java.lang.Object#equals(java.lang.Object)
202 public boolean equals(final Object obj) {
209 if (getClass() != obj.getClass()) {
212 final TestContextDateLocaleItem other = (TestContextDateLocaleItem) obj;
213 if (dateValue == null) {
214 if (other.dateValue != null) {
217 } else if (!dateValue.equals(other.dateValue)) {
220 if (dst != other.dst) {
223 if (localeCountry == null) {
224 if (other.localeCountry != null) {
227 } else if (!localeCountry.equals(other.localeCountry)) {
230 if (localeLanguage == null) {
231 if (other.localeLanguage != null) {
234 } else if (!localeLanguage.equals(other.localeLanguage)) {
237 if (timeZoneString == null) {
238 if (other.timeZoneString != null) {
241 } else if (!timeZoneString.equals(other.timeZoneString)) {
244 return utcOffset == other.utcOffset;
250 * @see java.lang.Object#toString()
253 public String toString() {
254 return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst
255 + ", utcOffset=" + utcOffset + ", localeLanguage=" + localeLanguage + ", localeCountry=" + localeCountry