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