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.Locale;
26 import java.util.TimeZone;
29 * The Class TestContextItem00A.
31 public class TestContextDateLocaleItem implements Serializable {
32 private static final long serialVersionUID = -6579903685538233754L;
34 private static final int HASH_PRIME_1 = 31;
35 private static final int HASH_PRIME_2 = 1231;
36 private static final int HASH_PRIME_3 = 1237;
38 private TestContextDateItem dateValue = new TestContextDateItem(System.currentTimeMillis());
39 private String timeZoneString = TimeZone.getTimeZone("Europe/Dublin").getDisplayName();
40 private boolean dst = false;
41 private int utcOffset = 0;
42 private Locale locale = Locale.ENGLISH;
47 public TestContextDateLocaleItem() {
53 * @param dateValue the date value
54 * @param tzValue the tz value
56 * @param utcOffset the utc offset
57 * @param language the language
58 * @param country the country
60 public TestContextDateLocaleItem(final TestContextDateItem dateValue, final String tzValue, final boolean dst,
61 final int utcOffset, final String language, final String country) {
62 this.dateValue = dateValue;
63 this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
65 this.utcOffset = utcOffset;
67 this.locale = new Locale(language, country);
73 * @param original the original
75 public TestContextDateLocaleItem(final TestContextDateLocaleItem original) {
76 this.dateValue = original.dateValue;
77 this.timeZoneString = TimeZone.getTimeZone(original.timeZoneString).getDisplayName();
78 this.dst = original.dst;
79 this.utcOffset = original.utcOffset;
81 this.locale = new Locale(original.getLocale().getCountry(), original.getLocale().getLanguage());
85 * Gets the date value.
87 * @return the date value
89 public TestContextDateItem getDateValue() {
94 * Sets the date value.
96 * @param dateValue the date value
98 public void setDateValue(final TestContextDateItem dateValue) {
99 this.dateValue = dateValue;
105 * @return the TZ value
107 public String getTzValue() {
108 return timeZoneString;
114 * @param tzValue the TZ value
116 public void setTzValue(final String tzValue) {
117 if (tzValue != null) {
118 this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
120 this.timeZoneString = null;
129 public boolean getDst() {
136 * @param newDst the dst
138 public void setDst(final boolean newDst) {
143 * Gets the UTC offset.
145 * @return the UTC offset
147 public int getUtcOffset() {
152 * Sets the UTC offset.
154 * @param newUtcOffset the UTC offset
156 public void setUtcOffset(final int newUtcOffset) {
157 this.utcOffset = newUtcOffset;
165 public Locale getLocale() {
172 * @param locale the locale
174 public void setLocale(final Locale locale) {
175 if (locale != null) {
176 this.locale = locale;
186 * @see java.lang.Object#hashCode()
189 public int hashCode() {
190 final int prime = HASH_PRIME_1;
192 result = prime * result + ((dateValue == null) ? 0 : dateValue.hashCode());
193 result = prime * result + (dst ? HASH_PRIME_2 : HASH_PRIME_3);
194 result = prime * result + ((locale == null) ? 0 : locale.hashCode());
195 result = prime * result + ((timeZoneString == null) ? 0 : timeZoneString.hashCode());
196 result = prime * result + utcOffset;
203 * @see java.lang.Object#equals(java.lang.Object)
206 public boolean equals(final Object obj) {
213 if (getClass() != obj.getClass()) {
216 final TestContextDateLocaleItem other = (TestContextDateLocaleItem) obj;
217 if (dateValue == null) {
218 if (other.dateValue != null) {
221 } else if (!dateValue.equals(other.dateValue)) {
224 if (dst != other.dst) {
227 if (locale == null) {
228 if (other.locale != null) {
231 } else if (!locale.equals(other.locale)) {
234 if (timeZoneString == null) {
235 if (other.timeZoneString != null) {
238 } else if (!timeZoneString.equals(other.timeZoneString)) {
241 return utcOffset == other.utcOffset;
247 * @see java.lang.Object#toString()
250 public String toString() {
251 return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst
252 + ", utcOffset=" + utcOffset + ", locale=" + locale + "]";