001: /*
002: **********************************************************************
003: * Copyright (c) 2003-2006, International Business Machines
004: * Corporation and others. All Rights Reserved.
005: **********************************************************************
006: * Author: Alan Liu
007: * Created: October 2 2003
008: * Since: ICU 2.8
009: **********************************************************************
010: */
011: package com.ibm.icu.impl;
012:
013: import com.ibm.icu.util.TimeZone;
014: import java.util.Date;
015:
016: /**
017: * <code>TimeZoneAdapter</code> wraps a com.ibm.icu.util.TimeZone
018: * subclass that is NOT a JDKTimeZone, that is, that does not itself
019: * wrap a java.util.TimeZone. It inherits from java.util.TimeZone.
020: * Without this class, we would need to 'port' java.util.Date to
021: * com.ibm.icu.util as well, so that Date could interoperate properly
022: * with the com.ibm.icu.util TimeZone and Calendar classes. With this
023: * class, we can use java.util.Date together with com.ibm.icu.util
024: * classes.
025: *
026: * The complement of this is JDKTimeZone, which makes a
027: * java.util.TimeZone look like a com.ibm.icu.util.TimeZone.
028: *
029: * @see com.ibm.icu.impl.JDKTimeZone
030: * @see com.ibm.icu.util.TimeZone#setDefault
031: * @author Alan Liu
032: * @since ICU 2.8
033: */
034: public class TimeZoneAdapter extends java.util.TimeZone {
035:
036: // Generated by serialver from JDK 1.4.1_01
037: static final long serialVersionUID = -2040072218820018557L;
038:
039: /**
040: * The contained com.ibm.icu.util.TimeZone object. Must not be null.
041: * We delegate all methods to this object.
042: */
043: private TimeZone zone;
044:
045: /**
046: * Given a java.util.TimeZone, wrap it in the appropriate adapter
047: * subclass of com.ibm.icu.util.TimeZone and return the adapter.
048: */
049: public static java.util.TimeZone wrap(com.ibm.icu.util.TimeZone tz) {
050: return new TimeZoneAdapter(tz);
051: }
052:
053: /**
054: * Return the java.util.TimeZone wrapped by this object.
055: */
056: public com.ibm.icu.util.TimeZone unwrap() {
057: return zone;
058: }
059:
060: /**
061: * Constructs an adapter for a com.ibm.icu.util.TimeZone object.
062: *
063: * @internal
064: * @deprecated This API is ICU internal only.
065: */
066: public TimeZoneAdapter(TimeZone zone) {
067: this .zone = zone;
068: super .setID(zone.getID());
069: }
070:
071: /**
072: * TimeZone API; calls through to wrapped time zone.
073: */
074: public void setID(String ID) {
075: super .setID(ID);
076: zone.setID(ID);
077: }
078:
079: /**
080: * TimeZone API; calls through to wrapped time zone.
081: */
082: public boolean hasSameRules(java.util.TimeZone other) {
083: return other instanceof TimeZoneAdapter
084: && zone.hasSameRules(((TimeZoneAdapter) other).zone);
085: }
086:
087: /**
088: * TimeZone API; calls through to wrapped time zone.
089: */
090: public int getOffset(int era, int year, int month, int day,
091: int dayOfWeek, int millis) {
092: return zone.getOffset(era, year, month, day, dayOfWeek, millis);
093: }
094:
095: /**
096: * TimeZone API; calls through to wrapped time zone.
097: */
098: public int getRawOffset() {
099: return zone.getRawOffset();
100: }
101:
102: /**
103: * TimeZone API; calls through to wrapped time zone.
104: */
105: public void setRawOffset(int offsetMillis) {
106: zone.setRawOffset(offsetMillis);
107: }
108:
109: /**
110: * TimeZone API; calls through to wrapped time zone.
111: */
112: public boolean useDaylightTime() {
113: return zone.useDaylightTime();
114: }
115:
116: /**
117: * TimeZone API; calls through to wrapped time zone.
118: */
119: public boolean inDaylightTime(Date date) {
120: return zone.inDaylightTime(date);
121: }
122:
123: /**
124: * Boilerplate API; calls through to wrapped object.
125: */
126: public Object clone() {
127: return new TimeZoneAdapter((TimeZone) zone.clone());
128: }
129:
130: /**
131: * Boilerplate API; calls through to wrapped object.
132: */
133: public synchronized int hashCode() {
134: return zone.hashCode();
135: }
136:
137: /**
138: * Boilerplate API; calls through to wrapped object.
139: */
140: public boolean equals(Object obj) {
141: if (obj instanceof TimeZoneAdapter) {
142: obj = ((TimeZoneAdapter) obj).zone;
143: }
144: return zone.equals(obj);
145: }
146:
147: /**
148: * Returns a string representation of this object.
149: * @return a string representation of this object.
150: */
151: public String toString() {
152: return "TimeZoneAdapter: " + zone.toString();
153: }
154: }
|