]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/impl/TimeZoneAdapter.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / impl / TimeZoneAdapter.java
1 /*\r
2  **********************************************************************\r
3  * Copyright (c) 2003-2008, International Business Machines\r
4  * Corporation and others.  All Rights Reserved.\r
5  **********************************************************************\r
6  * Author: Alan Liu\r
7  * Created: October 2 2003\r
8  * Since: ICU 2.8\r
9  **********************************************************************\r
10  */\r
11 \r
12 package com.ibm.icu.impl;\r
13 import com.ibm.icu.util.TimeZone;\r
14 import java.util.Date;\r
15 \r
16 /**\r
17  * <code>TimeZoneAdapter</code> wraps a com.ibm.icu.util.TimeZone\r
18  * subclass and inherits from java.util.TimeZone.\r
19  * Without this class, we would need to 'port' java.util.Date to\r
20  * com.ibm.icu.util as well, so that Date could interoperate properly\r
21  * with the com.ibm.icu.util TimeZone and Calendar classes.  With this\r
22  * class, we can use java.util.Date together with com.ibm.icu.util\r
23  * classes.\r
24  *\r
25  * @see com.ibm.icu.util.TimeZone#setDefault\r
26  * @author Alan Liu\r
27  * @since ICU 2.8\r
28  */\r
29 public class TimeZoneAdapter extends java.util.TimeZone {\r
30  \r
31     // Generated by serialver from JDK 1.4.1_01\r
32     static final long serialVersionUID = -2040072218820018557L;\r
33     \r
34     /**\r
35      * The contained com.ibm.icu.util.TimeZone object.  Must not be null.\r
36      * We delegate all methods to this object.\r
37      */\r
38     private TimeZone zone;\r
39     \r
40     /**\r
41      * Given a java.util.TimeZone, wrap it in the appropriate adapter\r
42      * subclass of com.ibm.icu.util.TimeZone and return the adapter.\r
43      */\r
44     public static java.util.TimeZone wrap(com.ibm.icu.util.TimeZone tz) {\r
45         return new TimeZoneAdapter(tz);\r
46     }\r
47 \r
48     /**\r
49      * Return the java.util.TimeZone wrapped by this object.\r
50      */\r
51     public com.ibm.icu.util.TimeZone unwrap() {\r
52         return zone;\r
53     }\r
54 \r
55     /**\r
56      * Constructs an adapter for a com.ibm.icu.util.TimeZone object.\r
57      */\r
58     public TimeZoneAdapter(TimeZone zone) {\r
59         this.zone = zone;\r
60         super.setID(zone.getID());\r
61     }\r
62 \r
63     /**\r
64      * TimeZone API; calls through to wrapped time zone.\r
65      */\r
66     public void setID(String ID) {\r
67         super.setID(ID);\r
68         zone.setID(ID);\r
69     }    \r
70 \r
71     /**\r
72      * TimeZone API; calls through to wrapped time zone.\r
73      */\r
74     public boolean hasSameRules(java.util.TimeZone other) {\r
75         return other instanceof TimeZoneAdapter &&\r
76             zone.hasSameRules(((TimeZoneAdapter)other).zone);\r
77     }\r
78 \r
79     /**\r
80      * TimeZone API; calls through to wrapped time zone.\r
81      */\r
82     public int getOffset(int era, int year, int month, int day, int dayOfWeek,\r
83                          int millis) {\r
84         return zone.getOffset(era, year, month, day, dayOfWeek, millis);\r
85     }\r
86 \r
87     /**\r
88      * TimeZone API; calls through to wrapped time zone.\r
89      */\r
90     public int getRawOffset() {\r
91         return zone.getRawOffset();\r
92     }\r
93 \r
94     /**\r
95      * TimeZone API; calls through to wrapped time zone.\r
96      */\r
97     public void setRawOffset(int offsetMillis) {\r
98         zone.setRawOffset(offsetMillis);\r
99     }\r
100 \r
101     /**\r
102      * TimeZone API; calls through to wrapped time zone.\r
103      */\r
104     public boolean useDaylightTime() {\r
105         return zone.useDaylightTime();\r
106     }\r
107 \r
108     /**\r
109      * TimeZone API; calls through to wrapped time zone.\r
110      */\r
111     public boolean inDaylightTime(Date date) {\r
112         return zone.inDaylightTime(date);\r
113     }\r
114 \r
115     /**\r
116      * Boilerplate API; calls through to wrapped object.\r
117      */\r
118     public Object clone() {\r
119         return new TimeZoneAdapter((TimeZone)zone.clone());\r
120     }\r
121 \r
122     /**\r
123      * Boilerplate API; calls through to wrapped object.\r
124      */\r
125     public synchronized int hashCode() {\r
126         return zone.hashCode();\r
127     }\r
128 \r
129     /**\r
130      * Boilerplate API; calls through to wrapped object.\r
131      */\r
132     public boolean equals(Object obj) {\r
133         if (obj instanceof TimeZoneAdapter) {\r
134             obj = ((TimeZoneAdapter) obj).zone;\r
135         }\r
136         return zone.equals(obj);\r
137     }\r
138 \r
139     /**\r
140      * Returns a string representation of this object.\r
141      * @return  a string representation of this object.\r
142      */\r
143     public String toString() {\r
144         return "TimeZoneAdapter: " + zone.toString();\r
145     }\r
146 }\r