KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > impl > TimeZoneAdapter


1 /*
2 **********************************************************************
3 * Copyright (c) 2003-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: October 2 2003
8 * Since: ICU 2.8
9 **********************************************************************
10 */

11 package com.ibm.icu.impl;
12 import com.ibm.icu.util.TimeZone;
13 import java.util.Date JavaDoc;
14
15 /**
16  * <code>TimeZoneAdapter</code> wraps a com.ibm.icu.util.TimeZone
17  * subclass that is NOT a JDKTimeZone, that is, that does not itself
18  * wrap a java.util.TimeZone. It inherits from java.util.TimeZone.
19  * Without this class, we would need to 'port' java.util.Date to
20  * com.ibm.icu.util as well, so that Date could interoperate properly
21  * with the com.ibm.icu.util TimeZone and Calendar classes. With this
22  * class, we can use java.util.Date together with com.ibm.icu.util
23  * classes.
24  *
25  * The complement of this is JDKTimeZone, which makes a
26  * java.util.TimeZone look like a com.ibm.icu.util.TimeZone.
27  *
28  * @see com.ibm.icu.impl.JDKTimeZone
29  * @see com.ibm.icu.util.TimeZone#setDefault
30  * @author Alan Liu
31  * @since ICU 2.8
32  */

33 public class TimeZoneAdapter extends java.util.TimeZone JavaDoc {
34  
35     // Generated by serialver from JDK 1.4.1_01
36
static final long serialVersionUID = -2040072218820018557L;
37     
38     /**
39      * The contained com.ibm.icu.util.TimeZone object. Must not be null.
40      * We delegate all methods to this object.
41      */

42     private TimeZone zone;
43     
44     /**
45      * Given a java.util.TimeZone, wrap it in the appropriate adapter
46      * subclass of com.ibm.icu.util.TimeZone and return the adapter.
47      */

48     public static java.util.TimeZone JavaDoc wrap(com.ibm.icu.util.TimeZone tz) {
49         return new TimeZoneAdapter(tz);
50     }
51
52     /**
53      * Return the java.util.TimeZone wrapped by this object.
54      */

55     public com.ibm.icu.util.TimeZone unwrap() {
56         return zone;
57     }
58
59     /**
60      * Constructs an adapter for a com.ibm.icu.util.TimeZone object.
61      *
62      * @internal
63      * @deprecated This API is ICU internal only.
64      */

65     public TimeZoneAdapter(TimeZone zone) {
66         this.zone = zone;
67         super.setID(zone.getID());
68     }
69
70     /**
71      * TimeZone API; calls through to wrapped time zone.
72      */

73     public void setID(String JavaDoc ID) {
74         super.setID(ID);
75         zone.setID(ID);
76     }
77
78     /**
79      * TimeZone API; calls through to wrapped time zone.
80      */

81     public boolean hasSameRules(java.util.TimeZone JavaDoc other) {
82         return other instanceof TimeZoneAdapter &&
83             zone.hasSameRules(((TimeZoneAdapter)other).zone);
84     }
85
86     /**
87      * TimeZone API; calls through to wrapped time zone.
88      */

89     public int getOffset(int era, int year, int month, int day, int dayOfWeek,
90                          int millis) {
91         return zone.getOffset(era, year, month, day, dayOfWeek, millis);
92     }
93
94     /**
95      * TimeZone API; calls through to wrapped time zone.
96      */

97     public int getRawOffset() {
98         return zone.getRawOffset();
99     }
100
101     /**
102      * TimeZone API; calls through to wrapped time zone.
103      */

104     public void setRawOffset(int offsetMillis) {
105         zone.setRawOffset(offsetMillis);
106     }
107
108     /**
109      * TimeZone API; calls through to wrapped time zone.
110      */

111     public boolean useDaylightTime() {
112         return zone.useDaylightTime();
113     }
114
115     /**
116      * TimeZone API; calls through to wrapped time zone.
117      */

118     public boolean inDaylightTime(Date JavaDoc date) {
119         return zone.inDaylightTime(date);
120     }
121
122     /**
123      * Boilerplate API; calls through to wrapped object.
124      */

125     public Object JavaDoc clone() {
126         return new TimeZoneAdapter((TimeZone)zone.clone());
127     }
128
129     /**
130      * Boilerplate API; calls through to wrapped object.
131      */

132     public synchronized int hashCode() {
133         return zone.hashCode();
134     }
135
136     /**
137      * Boilerplate API; calls through to wrapped object.
138      */

139     public boolean equals(Object JavaDoc obj) {
140         if (obj instanceof TimeZoneAdapter) {
141             obj = ((TimeZoneAdapter) obj).zone;
142         }
143         return zone.equals(obj);
144     }
145
146     /**
147      * Returns a string representation of this object.
148      * @return a string representation of this object.
149      */

150     public String JavaDoc toString() {
151         return "TimeZoneAdapter: " + zone.toString();
152     }
153 }
154
Popular Tags