KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > tz > FixedDateTimeZone


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time.tz;
17
18 import org.joda.time.DateTimeZone;
19
20 /**
21  * Basic DateTimeZone implementation that has a fixed name key and offsets.
22  * <p>
23  * FixedDateTimeZone is thread-safe and immutable.
24  *
25  * @author Brian S O'Neill
26  * @since 1.0
27  */

28 public final class FixedDateTimeZone extends DateTimeZone {
29
30     private static final long serialVersionUID = -3513011772763289092L;
31
32     private final String JavaDoc iNameKey;
33     private final int iWallOffset;
34     private final int iStandardOffset;
35
36     public FixedDateTimeZone(String JavaDoc id, String JavaDoc nameKey,
37                              int wallOffset, int standardOffset) {
38         super(id);
39         iNameKey = nameKey;
40         iWallOffset = wallOffset;
41         iStandardOffset = standardOffset;
42     }
43
44     public String JavaDoc getNameKey(long instant) {
45         return iNameKey;
46     }
47
48     public int getOffset(long instant) {
49         return iWallOffset;
50     }
51
52     public int getStandardOffset(long instant) {
53         return iStandardOffset;
54     }
55
56     public int getOffsetFromLocal(long instantLocal) {
57         return iWallOffset;
58     }
59
60     public boolean isFixed() {
61         return true;
62     }
63
64     public long nextTransition(long instant) {
65         return instant;
66     }
67
68     public long previousTransition(long instant) {
69         return instant;
70     }
71
72     public boolean equals(Object JavaDoc obj) {
73         if (this == obj) {
74             return true;
75         }
76         if (obj instanceof FixedDateTimeZone) {
77             FixedDateTimeZone other = (FixedDateTimeZone)obj;
78             return
79                 getID().equals(other.getID()) &&
80                 iStandardOffset == other.iStandardOffset &&
81                 iWallOffset == other.iWallOffset;
82         }
83         return false;
84     }
85
86     public int hashCode() {
87         return getID().hashCode() + 37 * iStandardOffset + 31 * iWallOffset;
88     }
89
90 }
91
Popular Tags