84024578de8aebe0d4d8182625afb4dd18fcf615
[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      * (non-Javadoc)
185      *
186      * @see java.lang.Object#hashCode()
187      */
188     @Override
189     public int hashCode() {
190         final int prime = HASH_PRIME_1;
191         int result = 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;
197         return result;
198     }
199
200     /*
201      * (non-Javadoc)
202      *
203      * @see java.lang.Object#equals(java.lang.Object)
204      */
205     @Override
206     public boolean equals(final Object obj) {
207         if (this == obj) {
208             return true;
209         }
210         if (obj == null) {
211             return false;
212         }
213         if (getClass() != obj.getClass()) {
214             return false;
215         }
216         final TestContextDateLocaleItem other = (TestContextDateLocaleItem) obj;
217         if (dateValue == null) {
218             if (other.dateValue != null) {
219                 return false;
220             }
221         } else if (!dateValue.equals(other.dateValue)) {
222             return false;
223         }
224         if (dst != other.dst) {
225             return false;
226         }
227         if (locale == null) {
228             if (other.locale != null) {
229                 return false;
230             }
231         } else if (!locale.equals(other.locale)) {
232             return false;
233         }
234         if (timeZoneString == null) {
235             if (other.timeZoneString != null) {
236                 return false;
237             }
238         } else if (!timeZoneString.equals(other.timeZoneString)) {
239             return false;
240         }
241         return utcOffset == other.utcOffset;
242     }
243
244     /*
245      * (non-Javadoc)
246      *
247      * @see java.lang.Object#toString()
248      */
249     @Override
250     public String toString() {
251         return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst
252                         + ", utcOffset=" + utcOffset + ", locale=" + locale + "]";
253     }
254 }