90f108ce2b746387c4c6d0c68b709c736188937b
[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.TimeZone;
26
27 /**
28  * The Class TestContextItem009.
29  */
30 public class TestContextDateTzItem implements Serializable {
31     private static final long serialVersionUID = 5604426823170331706L;
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
41     /**
42      * The Constructor.
43      */
44     public TestContextDateTzItem() {
45         dst = true;
46     }
47
48     /**
49      * The Constructor.
50      *
51      * @param dateValue the date value
52      * @param tzValue the tz value
53      * @param dst the dst
54      */
55     public TestContextDateTzItem(final TestContextDateItem dateValue, final String tzValue, final boolean dst) {
56         this.dateValue = dateValue;
57         this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
58         this.dst = dst;
59     }
60
61     /**
62      * The Constructor.
63      *
64      * @param original the original
65      */
66     public TestContextDateTzItem(final TestContextDateTzItem original) {
67         this.dateValue = original.dateValue;
68         this.timeZoneString = original.timeZoneString;
69         this.dst = original.dst;
70     }
71
72     /**
73      * Gets the date value.
74      *
75      * @return the date value
76      */
77     public TestContextDateItem getDateValue() {
78         return dateValue;
79     }
80
81     /**
82      * Sets the date value.
83      *
84      * @param dateValue the date value
85      */
86     public void setDateValue(final TestContextDateItem dateValue) {
87         this.dateValue = dateValue;
88     }
89
90     /**
91      * Gets the TZ value.
92      *
93      * @return the TZ value
94      */
95     public String getTzValue() {
96         return timeZoneString;
97     }
98
99     /**
100      * Sets the TZ value.
101      *
102      * @param tzValue the TZ value
103      */
104     public void setTzValue(final String tzValue) {
105         if (tzValue != null) {
106             this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName();
107         }
108         else {
109             this.timeZoneString = null;
110         }
111     }
112
113     /**
114      * Gets the DST.
115      *
116      * @return the dst
117      */
118     public boolean getDst() {
119         return dst;
120     }
121
122     /**
123      * Sets the DST.
124      *
125      * @param newDst the dst
126      */
127     public void setDst(final boolean newDst) {
128         this.dst = newDst;
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see java.lang.Object#hashCode()
135      */
136     @Override
137     public int hashCode() {
138         final int prime = HASH_PRIME_1;
139         int result = 1;
140         result = prime * result + ((dateValue == null) ? 0 : dateValue.hashCode());
141         result = prime * result + (dst ? HASH_PRIME_2 : HASH_PRIME_3);
142         result = prime * result + ((timeZoneString == null) ? 0 : timeZoneString.hashCode());
143         return result;
144     }
145
146     /*
147      * (non-Javadoc)
148      *
149      * @see java.lang.Object#equals(java.lang.Object)
150      */
151     @Override
152     public boolean equals(final Object obj) {
153         if (this == obj) {
154             return true;
155         }
156         if (obj == null) {
157             return false;
158         }
159         if (getClass() != obj.getClass()) {
160             return false;
161         }
162         final TestContextDateTzItem other = (TestContextDateTzItem) obj;
163         if (dateValue == null) {
164             if (other.dateValue != null) {
165                 return false;
166             }
167         } else if (!dateValue.equals(other.dateValue)) {
168             return false;
169         }
170         if (dst != other.dst) {
171             return false;
172         }
173         if (timeZoneString == null) {
174             if (other.timeZoneString != null) {
175                 return false;
176             }
177         }
178         else if (!timeZoneString.equals(other.timeZoneString)) {
179             return false;
180         }
181         return true;
182     }
183
184     /*
185      * (non-Javadoc)
186      *
187      * @see java.lang.Object#toString()
188      */
189     @Override
190     public String toString() {
191         return "TestContextItem009 [dateValue=" + dateValue + ", tzValue=" + timeZoneString + ", dst=" + dst + "]";
192     }
193 }