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