4914a1bc5b27b099c806f23baf1d7986d30816be
[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 Locale locale = Locale.ENGLISH;
42
43     /**
44      * The Constructor.
45      */
46     public TestContextDateLocaleItem() {
47     }
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         this.locale = new Locale(language, country);
67     }
68
69     /**
70      * The Constructor.
71      *
72      * @param original the original
73      */
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;
79
80         this.locale = new Locale(original.getLocale().getCountry(), original.getLocale().getLanguage());
81     }
82
83     /**
84      * Gets the date value.
85      *
86      * @return the date value
87      */
88     public TestContextDateItem getDateValue() {
89         return dateValue;
90     }
91
92     /**
93      * Sets the date value.
94      *
95      * @param dateValue the date value
96      */
97     public void setDateValue(final TestContextDateItem dateValue) {
98         this.dateValue = dateValue;
99     }
100
101     /**
102      * Gets the TZ value.
103      *
104      * @return the TZ value
105      */
106     public String getTzValue() {
107         return timeZoneString;
108     }
109
110     /**
111      * Sets the TZ value.
112      *
113      * @param tzValue the TZ value
114      */
115     public void setTzValue(final String tzValue) {
116         if (tzValue != null) {
117             this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
118         } else {
119             this.timeZoneString = null;
120         }
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 locale;
166     }
167
168     /**
169      * Sets the locale.
170      *
171      * @param locale the locale
172      */
173     public void setLocale(final Locale locale) {
174         if (locale != null) {
175             this.locale = locale;
176         }
177         else { 
178             this.locale = null;
179         }
180     }
181
182     /*
183      * (non-Javadoc)
184      *
185      * @see java.lang.Object#hashCode()
186      */
187     @Override
188     public int hashCode() {
189         final int prime = HASH_PRIME_1;
190         int result = 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;
196         return result;
197     }
198
199     /*
200      * (non-Javadoc)
201      *
202      * @see java.lang.Object#equals(java.lang.Object)
203      */
204     @Override
205     public boolean equals(final Object obj) {
206         if (this == obj) {
207             return true;
208         }
209         if (obj == null) {
210             return false;
211         }
212         if (getClass() != obj.getClass()) {
213             return false;
214         }
215         final TestContextDateLocaleItem other = (TestContextDateLocaleItem) obj;
216         if (dateValue == null) {
217             if (other.dateValue != null) {
218                 return false;
219             }
220         } else if (!dateValue.equals(other.dateValue)) {
221             return false;
222         }
223         if (dst != other.dst) {
224             return false;
225         }
226         if (locale == null) {
227             if (other.locale != null) {
228                 return false;
229             }
230         } else if (!locale.equals(other.locale)) {
231             return false;
232         }
233         if (timeZoneString == null) {
234             if (other.timeZoneString != null) {
235                 return false;
236             }
237         } else if (!timeZoneString.equals(other.timeZoneString)) {
238             return false;
239         }
240         return utcOffset == other.utcOffset;
241     }
242
243     /*
244      * (non-Javadoc)
245      *
246      * @see java.lang.Object#toString()
247      */
248     @Override
249     public String toString() {
250         return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst
251                         + ", utcOffset=" + utcOffset + ", locale=" + locale + "]";
252     }
253 }