22c46b4a789a14882024ba245ed132748d630f71
[policy/apex-pdp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.context.test.concepts;
23
24 import java.io.Serializable;
25 import java.util.Locale;
26 import java.util.TimeZone;
27
28 /**
29  * The Class TestContextItem00A.
30  */
31 public class TestContextDateLocaleItem implements Serializable {
32     private static final long serialVersionUID = -6579903685538233754L;
33
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;
37
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;
43
44     /**
45      * The Constructor.
46      */
47     public TestContextDateLocaleItem() {
48     }
49
50     /**
51      * The Constructor.
52      *
53      * @param dateValue the date value
54      * @param tzValue the tz value
55      * @param dst the dst
56      * @param utcOffset the utc offset
57      * @param language the language
58      * @param country the country
59      */
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();
64         this.dst = dst;
65         this.utcOffset = utcOffset;
66
67         this.locale = new Locale(language, country);
68     }
69
70     /**
71      * The Constructor.
72      *
73      * @param original the original
74      */
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;
80
81         this.locale = new Locale(original.getLocale().getCountry(), original.getLocale().getLanguage());
82     }
83
84     /**
85      * Gets the date value.
86      *
87      * @return the date value
88      */
89     public TestContextDateItem getDateValue() {
90         return dateValue;
91     }
92
93     /**
94      * Sets the date value.
95      *
96      * @param dateValue the date value
97      */
98     public void setDateValue(final TestContextDateItem dateValue) {
99         this.dateValue = dateValue;
100     }
101
102     /**
103      * Gets the TZ value.
104      *
105      * @return the TZ value
106      */
107     public String getTzValue() {
108         return timeZoneString;
109     }
110
111     /**
112      * Sets the TZ value.
113      *
114      * @param tzValue the TZ value
115      */
116     public void setTzValue(final String tzValue) {
117         if (tzValue != null) {
118             this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
119         } else {
120             this.timeZoneString = null;
121         }
122     }
123
124     /**
125      * Gets the DST.
126      *
127      * @return the dst
128      */
129     public boolean getDst() {
130         return dst;
131     }
132
133     /**
134      * Sets the DST.
135      *
136      * @param newDst the dst
137      */
138     public void setDst(final boolean newDst) {
139         this.dst = newDst;
140     }
141
142     /**
143      * Gets the UTC offset.
144      *
145      * @return the UTC offset
146      */
147     public int getUtcOffset() {
148         return utcOffset;
149     }
150
151     /**
152      * Sets the UTC offset.
153      *
154      * @param newUtcOffset the UTC offset
155      */
156     public void setUtcOffset(final int newUtcOffset) {
157         this.utcOffset = newUtcOffset;
158     }
159
160     /**
161      * Gets the locale.
162      *
163      * @return the locale
164      */
165     public Locale getLocale() {
166         return locale;
167     }
168
169     /**
170      * Sets the locale.
171      *
172      * @param locale the locale
173      */
174     public void setLocale(final Locale locale) {
175         if (locale != null) {
176             this.locale = locale;
177         }
178         else {
179             this.locale = null;
180         }
181     }
182
183     /**
184      * {@inheritDoc}.
185      */
186     @Override
187     public int hashCode() {
188         final int prime = HASH_PRIME_1;
189         int result = 1;
190         result = prime * result + ((dateValue == null) ? 0 : dateValue.hashCode());
191         result = prime * result + (dst ? HASH_PRIME_2 : HASH_PRIME_3);
192         result = prime * result + ((locale == null) ? 0 : locale.hashCode());
193         result = prime * result + ((timeZoneString == null) ? 0 : timeZoneString.hashCode());
194         result = prime * result + utcOffset;
195         return result;
196     }
197
198     /**
199      * {@inheritDoc}.
200      */
201     @Override
202     public boolean equals(final Object obj) {
203         if (this == obj) {
204             return true;
205         }
206         if (obj == null) {
207             return false;
208         }
209         if (getClass() != obj.getClass()) {
210             return false;
211         }
212         final TestContextDateLocaleItem other = (TestContextDateLocaleItem) obj;
213         if (dateValue == null) {
214             if (other.dateValue != null) {
215                 return false;
216             }
217         } else if (!dateValue.equals(other.dateValue)) {
218             return false;
219         }
220         if (dst != other.dst) {
221             return false;
222         }
223         if (locale == null) {
224             if (other.locale != null) {
225                 return false;
226             }
227         } else if (!locale.equals(other.locale)) {
228             return false;
229         }
230         if (timeZoneString == null) {
231             if (other.timeZoneString != null) {
232                 return false;
233             }
234         } else if (!timeZoneString.equals(other.timeZoneString)) {
235             return false;
236         }
237         return utcOffset == other.utcOffset;
238     }
239
240     /**
241      * {@inheritDoc}.
242      */
243     @Override
244     public String toString() {
245         return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst
246                         + ", utcOffset=" + utcOffset + ", locale=" + locale + "]";
247     }
248 }